fix(scoring): pin upstream constants to the resolved SHA and fail closed on fetch failure - #1192
Merged
Merged
Conversation
…sed on fetch failure
Contributor
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1192 +/- ##
=======================================
Coverage 94.80% 94.80%
=======================================
Files 157 157
Lines 19083 19090 +7
Branches 6909 6912 +3
=======================================
+ Hits 18091 18098 +7
Misses 399 399
Partials 593 593 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
3 tasks
JSONbored
added a commit
that referenced
this pull request
Jun 24, 2026
…g branches (#1193) Pagination cap: getLastCloserLogin now exits after 10 pages (1 000 events) instead of looping indefinitely — prevents GitHub API rate exhaustion on pathologically long issue timelines. Returns the best lastCloser found within the cap; adds a test that validates the cap fires and page 11 is never fetched. Scoring coverage: add tests for the four uncovered branches in the #1192 diff: - fetchUpstreamRefSha catch path (network throw → null → mutable-ref fallback) - non-string SHA response (typeof guard → null → mutable-ref fallback) - empty SHA string (length guard → null → mutable-ref fallback) - prior fallback snapshot on second fail-closed attempt (sourceKind === "fallback" guard → does not freeze the prior fallback, bootstraps fresh defaults instead)
JSONbored
added a commit
that referenced
this pull request
Jun 24, 2026
#1235) #1192 pinned the upstream constants fetch and froze last-good on a non-2xx response, but a 200 with a semantically-garbage body — an HTML interstitial, a Git-LFS pointer, or a truncated file — parsed to ~0 recognized constants and silently reverted every constant to DEFAULT_SCORING_CONSTANTS while keeping sourceKind="raw-github", moving live scoring with no staleness signal. The refresh now applies a sanity floor: a 200 body must parse at least MIN_RECOGNIZED_SCORING_CONSTANTS recognized constants to be trusted. Otherwise it is handled exactly like a failed fetch — freeze the last-good snapshot, or bootstrap to a clearly-labeled "fallback" when there is no verified last-good. Also surfaces a warning when the upstream ref can't be resolved to an immutable SHA (the fetch falls back to the mutable ref), and records the resolved fetch ref in the drift-sync source.
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two correctness gaps in the scoring constants refresh path:
SHA-pin: The fetch was using the mutable branch ref (e.g.
test) directly in the raw-content URL. A force-push or branch-rename between the ref-resolve and the fetch could silently change what constants every repo scores against mid-cycle. Now resolves the ref to an immutable HEAD commit SHA first (GET /repos/{repo}/commits/{ref}), then builds the constants URL from that SHA. The SHA is also recorded in the snapshot payload for audit traceability. Fail-open on the SHA lookup itself — a transient API error falls back to the mutable ref so the refresh is never blocked.Fail-closed: A failed constants fetch previously fell through to
DEFAULT_SCORING_CONSTANTS, silently overwriting the last verified upstream values with hardcoded defaults. That would move live scoring with no one noticing. Now: if a verifiedraw-githubsnapshot exists, freeze it in place and append a warning instead of persisting defaults. Only bootstraps to defaults when there is genuinely no prior snapshot to fall back to.Scope
src/scoring/model.ts— SHA-pin + fail-closed logictest/unit/scoring.test.ts— 3 new tests (SHA recorded, freeze-last-good, bootstrap-to-defaults)Validation
npm run test:ci— all tests passnpm run typecheck— cleanSafety