MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / worker

Function worker

web/src/server/free-session/abuse-detection.ts:419–456  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

417 let rateLimited = 0
418
419 const worker = async () => {
420 while (queue.length > 0) {
421 const s = queue.shift()
422 if (!s?.githubId) continue
423 const result = await fetchGithubCreatedAt(s.githubId)
424 if (result === 'rate-limited') {
425 rateLimited++
426 continue
427 }
428 if (result === null) {
429 failures++
430 continue
431 }
432 const ageDays = (now.getTime() - result.getTime()) / 86400_000
433 s.githubAgeDays = ageDays
434 if (ageDays < 7) {
435 s.flags.push(`gh-new<7d:${ageDays.toFixed(1)}d`)
436 s.score += 60
437 } else if (ageDays < 30) {
438 s.flags.push(`gh-new<30d:${ageDays.toFixed(0)}d`)
439 s.score += 30
440 } else if (ageDays < 90) {
441 s.flags.push(`gh-new<90d:${ageDays.toFixed(0)}d`)
442 s.score += 10
443 } else if (ageDays >= 365 * 3) {
444 // Established GitHub accounts are a strong counter-signal: buying
445 // a 3+ year old account is rare at our abuse scale. Subtract enough
446 // to pull a day-1 heavy user (new-acct<1d + very-heavy = 90) back
447 // below the high-tier threshold without fully clearing them —
448 // genuine 24/7 patterns still surface.
449 s.counterSignals.push(`gh-established:${(ageDays / 365).toFixed(1)}y`)
450 s.score -= 40
451 } else if (ageDays >= 365) {
452 s.counterSignals.push(`gh-established:${(ageDays / 365).toFixed(1)}y`)
453 s.score -= 20
454 }
455 }
456 }
457
458 await Promise.all(
459 Array.from({ length: Math.min(GITHUB_API_CONCURRENCY, targets.length) }, () =>

Callers 1

enrichWithGithubAgeFunction · 0.85

Calls 1

fetchGithubCreatedAtFunction · 0.85

Tested by

no test coverage detected