Repository navigation
🐛 fix(automerge): expire 404'd closing-link targets instead of caching them forever - #15139
Conversation
…g them forever A closing-keyword target that returned 404/410 was cached as not-a-PR for the process lifetime. A transient or masked 404, or a number later allocated to a pull request, then slipped past the closing-keyword gate. Missing targets are now trusted for 10 minutes; existing non-PR issues stay cached. Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of No conflicting open PRs or same-file overlaps were found. |
|
hive/awaiting-ci: CI pending — sweep will merge when green. 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
There was a problem hiding this comment.
The production change is correct; the new test is why test (rest 4/4) is red, and it fails deterministically, not flakily.
Finding (test defect, medium): src/pkg/github/automerge/automerge_closing_link_test.go:342-355 — TestClosingKeywordMissingTargetExpires calls numberIsOpenPullRequest for acme/widget#1036 without ever seeding that key in the front. The front only counts reads for keys it owns: automerge_linked_issue_test.go:181-185 does issue, ok := f.issues[key]; if ok { f.reads[key]++ } and otherwise proxies to the backend. So the first two reads produce a backend 404 (which the engine caches correctly via automerge_closing_link.go:164-166) but front.readsOf(target) stays 0, and line 355 fails with reads within TTL = 0, want 1 — exactly what CI job 123138545532 shows on every run.
Fix is one line before the first read:
front.set(target, linkedIssue{status: http.StatusNotFound})The front then serves the 404 itself (automerge_linked_issue_test.go:188-191) and counts it, so the assertions 1 (within TTL) and 2 (after set(..., pr: true) past the TTL) hold as written. http is already imported in that test file via the other cases.
What I verified about the engine side: noteClosingTarget (automerge_closing_link.go:135-151) stores a zero expiry for existing non-PR issues and now+10m for nil, and the cache check at :156-158 treats zero as permanent and a set expiry as valid only while clock().Before(expires). The cache-reset at closingLinkCacheMax and the field type change in automerge_sweep.go:311 are consistent. Looks right to me once the test is fixed.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
The production change is correct; the new test fails deterministically and will keep test (rest 4/4) and coverage red until it is fixed.
Why the test fails (automerge_closing_link_test.go:355: reads within TTL = 0, want 1, three times in the CI log for this head):
linkedIssueFront only counts a read when the key is already in f.issues — automerge_linked_issue_test.go:181-186:
issue, ok := f.issues[key]
if ok {
f.reads[key]++
}Unknown keys fall through to proxy.ServeHTTP. TestClosingKeywordMissingTargetExpires never sets acme/widget#1036 before the first two numberIsOpenPullRequest calls, so the 404 comes from the backend fixture and is never counted. The fix is one line before the first call:
front.set(target, linkedIssue{status: http.StatusNotFound})Then the later front.set(target, linkedIssue{state: "open", pr: true}) flips it to a PR and the want 2 assertion holds. (http is already imported in that file.)
What I verified in the production code:
noteClosingTarget(automerge_closing_link.go:134-150) stores a zerotime.Timefor an existing non-PR issue andclock()+10mfor a nil (404/410) issue, andnumberIsOpenPullRequest(:157-161) treats zero as "forever" and otherwise re-reads onceclock()reaches the expiry. That is exactly the stated behaviour: existing issues cached for the process, missing numbers trusted for 10 minutes.- The 404 path at
:165-168is the only writer of a nil entry, andc.clock()(automerge_held_runs.go:254) is the existing seam the test overrides viac.now, so the test's clock manipulation drives the real code path. - The
closingLinkCacheMaxreset still applies to the retyped map.
Once the test is fixed this looks correct to me.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
linkedIssueFront only counts reads for registered numbers; an unregistered one falls through to the backend uncounted, so readsOf stayed 0. The test now registers acme/widget#1036 as a 404 first. Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
A closing-keyword target that 404'd was cached as not-a-PR for the process lifetime, so a transient 404 or a number later allocated to a PR bypassed the closing-keyword gate. Missing targets now expire after 10 minutes; existing non-PR issues stay cached.
Closes #15120
— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88