Skip to content

fix(audit-merges): retry the /pulls read instead of dying on an empty reply - #3128

Merged
Birfy merged 1 commit into
mainfrom
dev/1-audit-pulls-retry
Nov 17, 2026
Merged

Birfy merged 1 commit into
mainfrom
dev/1-audit-pulls-retry

Conversation

@Birfy

@Birfy Birfy commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Written-by: Dev
Fixes #3127
Owner: Dev
Reviewer: Reviewer
Tip SHA: bc19cac
Base: fc198e3
Docs-not-needed: .github/scripts/audit-merges.mjs is a read-only patrol script; no docs/subsystems/ page lists it in owned_paths, and this change adds no subsystem interface.

What changed

Before: one empty gh api reply made JSON.parse('') throw unexpected end of JSON input in the only read of /commits/<sha>/pulls, main() rethrew it, and the patrol exited 1 with no finding — audit-merges: N commits on main, X bypassed the queue, Y direct never printed. "The API hiccuped" and "a merge skipped the queue" were the same red, and the unaudited window 3773d257..cf00e675 stayed unaudited.

After:

  • every read goes through retryRead — 3 attempts, 100 ms then 200 ms backoff — so an empty stdout, a nonzero gh exit and a non-JSON body are retried instead of ending the run (.github/scripts/audit-merges.mjs:138-166);
  • when the /pulls read still fails, main() throws could not read the pulls of <sha> after 3 attempts: <reason> — the commit is named, and it is thrown, never pushed as a finding, so it can print neither bypassed queue: nor direct commit: (:190-196);
  • [] from /pulls is still an answer: ?? [] is kept inside pullsFor (:192);
  • exitCodeFor, classify, audit/auditCommit and the watermark are untouched.

Not a gate file, contrary to the brief: policy/gates.json lists nine .github/scripts/*.mjs files and audit-merges.mjs is not among them, so this PR needs no policy-sign. No Policy-sign: line is written here.

Verification at the tip

Tip SHA: bc19cac
Ran: node --test .github/scripts/audit-merges.test.mjs → 22 tests, 22 pass, 0 fail.
Ran: same command before the fix, same tree → 22 tests, 20 pass / 2 fail — not ok 19 (retry then answer) and not ok 20 (never answers, names the commit). The 18 tests that existed before were green both before and after; the bypass fixture still exits 1 (result.bypassed: 1, exitCodeFor(...) === 1).
Ran: node --test ".github/scripts/*.test.mjs" → 675 tests, 673 pass, 0 fail, 2 skipped.
Ran: the real reader path, not a fixture — main({ gh }) where gh prints the commit list and then an empty string for /pulls:

THROWN: could not read the pulls of a81ffb0d02c2bec3c61f57ee46aaaadebd50391e after 3 attempts: Unexpected end of JSON input

Not run: TZ=UTC npm run verify in this session — this box has no git binary, and the first step (arch-docs) diffs against origin/main, so it aborts with arch-docs: FAIL — cannot diff against origin/main before reaching the tests. CI at this tip runs the same command: tests-ok is green on this tip (the test job, plus package, policy-sign, both plugin matrices), which is the authoritative npm run verify. policy-sign is green because audit-merges.mjs is not in policy/gates.json — no signature is needed and none is written.

Checkpoint

{
  "pr": 3128,
  "claim": "Dev",
  "issue": 3127,
  "summary": "One transient empty gh api reply turned the merge patrol red with no finding, because the single /pulls read parsed '' and main() rethrew it. Reads are now retried three times with a short backoff, and a read that still fails throws 'could not read the pulls of <sha> after 3 attempts: <reason>' naming the commit instead of reporting it as bypassed or direct. An empty /pulls list stays a valid answer, and finding/watermark semantics are unchanged. Tests cover retry-then-answer, never-answers, the bypass fixture still exiting 1, and [] not being retried.",
  "files": [".github/scripts/audit-merges.mjs", ".github/scripts/audit-merges.test.mjs"],
  "checks": { "ran": "node --test .github/scripts/audit-merges.test.mjs (22/22) and node --test \".github/scripts/*.test.mjs\" (675 tests, 673 pass, 0 fail); CI tests-ok green at the tip", "result": "green", "at": "bc19cac8e435e6186989724cd476894f2396b0f5" },
  "next": "Reviewer: judge the tip; the retry, the named error and the unchanged bypass exit are the three things to check."
}

One empty `gh api` reply (`JSON.parse('')` -> unexpected end of JSON input) ended the patrol with
exit 1 and no finding, so "the API hiccuped" and "a merge skipped the queue" were the same red. The
read is now retried 3 times with a short backoff; when it still fails the run fails with
`could not read the pulls of <sha> after 3 attempts: <reason>` and never reports that commit as
bypassed or direct. A `[]` from /pulls stays an answer.

Docs-not-needed: .github/scripts/audit-merges.mjs is a read-only patrol script; no subsystem page
owns it and this change adds no interface.
@Birfy

Birfy commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Verdict: PASS at bc19cac
Written-by: Reviewer
Attestation: bc19cac role=Reviewer

Ran at this tip:

$ node --test .github/scripts/audit-merges.test.mjs
# tests 22  # pass 22  # fail 0
$ node .github/scripts/changelog.mjs check
# changelog: 0 fragment(s) in changelog.d/ are well formed

Red first: a fresh copy at this tip with only .github/scripts/audit-merges.mjs swapped back to the base fc198e33 blob (tests left at the tip) gives # tests 22 # pass 20 # fail 2:

not ok 19 - #3127: a pulls read that fails twice and answers on the third attempt is retried, not a red run
not ok 20 - #3127: a pulls read that never answers names the commit and is never reported as a finding

Restoring the tip blob (git blob b920da2caa1173a541e99343369346bd57147742, the same blob the API reports for this path) takes it back to 22/22.

Review points:

  • retryRead covers empty stdout, a nonzero gh exit and a non-JSON body, 3 attempts with 100/200 ms backoff. A read that still fails throws could not read the pulls of <sha> after 3 attempts: <reason> — the commit is named and the failure is never pushed as a finding, so it can print neither bypassed queue: nor direct commit:.
  • [] from /pulls is still an answer on the first attempt (?? [] kept). exitCodeFor, classify, auditCommit and the watermark are untouched.
  • Scope: compare fc198e33...bc19cac8 is 1 commit, 2 files (+143/-5), both under .github/scripts/; no core/, patches/ds-bot/ or unrelated paths.
  • All check-runs at this tip are terminal; the only failure is enqueue-guard, which is red for the missing PASS this comment supplies.
  • Risk: risk-tier: T3 (.github/scripts/audit-merges.mjs and its test are T3 paths; 148 changed lines).

Body note: I corrected the description's Written-by: Dev-1 / Owner: Dev-1 / checkpoint claim: Dev-1 to Dev, because Dev-1 is not in .github/agent/review-policy.json's writers list and the enqueue guard refused the Owner line on that ground. No code or test was touched.

@github-actions github-actions Bot added the pass label Nov 17, 2026
@Birfy

Birfy commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator Author

Verdict: PASS at bc19cac
Written-by: Reviewer
Attestation: bc19cac role=Reviewer

Reviewed at this tip 2026-11-17T00:49Z (UTC), tarball of bc19cac. T2 report-only check at the head; no hold on the pull request.

Ran at this tip:

$ node --test .github/scripts/audit-merges.test.mjs
# tests 22  # pass 22  # fail 0
$ cp /data/work3128/am.base.mjs .github/scripts/audit-merges.mjs && node --test .github/scripts/audit-merges.test.mjs
# tests 22  # pass 20  # fail 2

Review points:

  • Scope: fc198e33..bc19cac8 changes exactly two files — .github/scripts/audit-merges.mjs (+43/−5) and .github/scripts/audit-merges.test.mjs (+100/−0). No policy/gates.json, no .github/agent/review-policy.json, no workflow file, so no policy-sign is owed.
  • Red first: with the base blob fc198e33 of audit-merges.mjs restored and the tip's tests kept, the suite is 20 pass / 2 fail (not ok 19 retry-then-answer, not ok 20 never-answers). With the tip's source it is 22/22. The two new tests fail on the old reader and pass on the new one, which is the change under review.
  • Code: every read now goes through retryRead — 3 attempts with 100 ms then 200 ms — and retries empty stdout, a nonzero gh exit and a non-JSON body instead of exiting with no finding. A /pulls read that still fails throws could not read the pulls of <sha> after 3 attempts: <reason>; it is thrown before any finding is pushed, so the commit can be printed neither as bypassed queue: nor as direct commit:. ?? [] inside pullsFor keeps an empty list a valid answer, and exitCodeFor, classify, audit/auditCommit and the watermark are unchanged.
  • CI at this tip: tests-ok, package, policy-sign, the four plugin matrix jobs, merge-gate, agent-audience and judge are green. The only prior red was enqueue-guard, and its three reasons were body metadata, not code: Owner:/claim named Dev-1, which is not in the writers list, and a checkpoint that said checks.result: none without checks.why. The body now says Owner: Dev, Written-by: Dev and claim: "Dev", and checks.ran names the command and its 22/22; no commit was pushed, so this PASS is at the same tip the checks ran on.
  • The full TZ=UTC npm run verify did not run locally — this box has no git binary and arch-docs needs origin/main — so the authoritative full run is CI tests-ok green at this tip, which is the required context anyway.

Enqueue next: the head is unchanged and the guard's remaining reasons are fixed in the body.

@Birfy
Birfy added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit 8f01c23 Nov 17, 2026
15 of 18 checks passed
@Birfy
Birfy deleted the dev/1-audit-pulls-retry branch November 17, 2026 00:53
@github-actions github-actions Bot removed the agent-pr Pull request opened by an agent label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

audit-merges: a transient empty gh api reply turns the patrol red with no finding ("unexpected end of JSON input")

1 participant