Skip to content

fix(platform): attribution gap could exceed 100% on narrow windows - #279

Merged
clickmatos merged 2 commits into
mainfrom
fix/attribution-gap-over-100pct
Oct 8, 2026
Merged

clickmatos merged 2 commits into
mainfrom
fix/attribution-gap-over-100pct

Conversation

@clickmatos

Copy link
Copy Markdown
Contributor

Summary

Reported from the live dashboard: the Attribution Gap card showed 123% ("174 of 142 human commits") with the window filter set to 7 days.

Root cause

The engine omits commit_origin_distribution for a repo with zero AI/bot-classified commits in-window (the has_non_human gate) — a separate condition from attribution_gap's own independent >=3-flagged-commits threshold. An all-human repo can still trip the attribution-gap heuristic (a burst of human commits satisfying the velocity signals) while never emitting commit_origin_distribution at all.

computeAIvsHuman summed flagged_commits from every repo with attribution_gap into the numerator, but only summed dist.HUMAN from repos that also had commit_origin_distribution into the denominator. An all-human repo contributed to the former without ever reaching the latter — not a per-repo invariant violation (flagged_commits <= total_human_commits always holds within one repo's own numbers, confirmed against the engine), but an aggregate effect across repos.

A narrow 7-day window makes this far more likely than 30/90 days: it's common for a repo to have zero AI-attributed commits in a short window while still having a dense burst of human commits (a crunch/sprint) that satisfies the heuristic.

Fix

platform/lib/queries/org-summary.ts, computeAIvsHuman: falls back to attribution_gap.total_human_commits for a repo's human count when commit_origin_distribution is absent, so every repo contributing to the numerator also contributes to the denominator. Clamped flaggedPct to 100 as defense in depth for any gate interaction not yet found.

Added a regression test reproducing the aggregate effect across two all-human repos.

Test plan

  • npx tsc --noEmit — clean
  • npx vitest run — 402 passed (1 new)
  • npm run build — not re-run for this change (pure aggregation logic, no new route/page surface)

🤖 Generated with Claude Code

The engine omits commit_origin_distribution for a repo with zero
AI/bot-classified commits in-window (has_non_human gate) — a separate
condition from attribution_gap's own independent >=3-flagged-commits
threshold, so an all-human repo can still trip the attribution-gap
heuristic. computeAIvsHuman summed flagged_commits from every repo
with attribution_gap into the numerator, but only summed dist.HUMAN
from repos that also had commit_origin_distribution into the
denominator — an all-human repo contributed to the former without
ever reaching the latter.

Surfaced on the dashboard as "174 of 142 human commits" (123%) on a
7-day window, where a short lookback makes an all-human commit burst
that still trips the heuristic far more likely than on 30/90 days.

Falls back to attribution_gap.total_human_commits for a repo's human
count when commit_origin_distribution is absent, so every repo
contributing to the numerator also contributes to the denominator.
Clamps flaggedPct to 100 as defense in depth for any gate interaction
not yet found. Added a regression test reproducing the aggregate
effect across two all-human repos (not a per-repo invariant violation
— flagged_commits <= total_human_commits always holds within one
repo's own numbers).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
clickbus-iris Ready Ready Preview Oct 8, 2026 1:12pm UTC

Request Review

The previous fallback added an all-human repo's total_human_commits to
totalHuman, which also feeds commitShare — so the org Human/AI split
shifted depending on whether the attribution-gap heuristic happened to
fire. Track the gap denominator in its own gapHuman counter instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@clickmatos
clickmatos merged commit dc96604 into main Oct 8, 2026
4 checks passed

This branch was successfully deployed

1 active deployment
Preview — a477e508 Deployed Oct 8, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant