Skip to content

Recompute merge-base on every PR file fetch - #5

Merged
anderdc merged 1 commit into
mainfrom
test
Apr 28, 2026
Merged

Recompute merge-base on every PR file fetch#5
anderdc merged 1 commit into
mainfrom
test

Conversation

@anderdc

@anderdc anderdc commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Drop the !pr.mergeBaseSha short-circuit in fetchAndStorePrFiles so the merge-base SHA is recomputed on every PR_FILES job, not just the first one.
  • Fixes inflated token-scoring on PRs whose head advanced via synchronize while the base branch also moved forward — the stored merge-base went stale, pinning base_content to an old ancestor and attributing churn from unrelated PRs to the wrong author.

Root cause

fetchAndStorePrFiles only computed the merge-base when pr.mergeBaseSha was unset, so a PR that was opened, sat for days while the base branch advanced, then got pushed to / merged would keep the original (now-stale) merge-base. pr_file_contents.base_content was then fetched from that stale SHA and tree-diff scoring saw enormous synthetic diffs.

Concrete example: entrius/gittensor-ui#586. Author's actual change: 1 file, +3/-3 (6 lines). Mirror stored:

  • base_sha = f5f9fba9 (correct)
  • head_sha = 599ebed0 (correct)
  • merge_base_sha = a005f577 ← stale; the real current merge-base is f5f9fba9

The 41-commit / 65-file gap between a005f577 and f5f9fba9 got rolled into this PR's score (TOKENS SCORED 638, LEAF 624 for a 6-line edit).

Cost

One extra GET /repos/:owner/:repo/compare/:base...:head per PR_FILES job. At typical PR-event volume that is well under the 5000/hr GitHub installation rate limit.

Backfill required

Existing rows still have stale merge_base_sha and inflated base_content. After this merges, run a backfill (or admin re-enqueue) to recompute. With this fix in place, every PR_FILES re-run will refresh the merge-base unconditionally.

Test plan

  • Deploy to test environment
  • Trigger backfill on a whitelisted repo
  • Verify merge_base_sha for PR #586 (and other previously-mis-scored PRs) updates to current value
  • Confirm base_content.byte_size for #586 drops from ~17.9 KB to ~14.1 KB
  • Confirm scored token count for #586 collapses to a value proportional to +3/-3
  • Spot-check a still-open PR after a synchronize to confirm merge-base refreshes

The merge-base SHA was computed once on the first PR_FILES job and
short-circuited on every subsequent run. When a PR's head advanced via
synchronize while the base branch also moved forward, the stored value
went stale and the saved base_content got pinned to an old ancestor —
inflating tree-diff scoring with churn from unrelated PRs that landed
on the base branch in the meantime.

Drop the !pr.mergeBaseSha guard so we recompute on every fetch. Adds
one compare API call per PR_FILES job; rate-limit cost is negligible.
@anderdc
anderdc merged commit 0d5bd83 into main Apr 28, 2026
2 checks passed
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