Skip to content

fix(pr-pipeline): retry transient network errors on lane script reads and safe writes - #10361

Merged
kyle-sexton merged 9 commits into
mainfrom
fix/lane-scripts-retry-9549
Oct 26, 2026
Merged

kyle-sexton merged 9 commits into
mainfrom
fix/lane-scripts-retry-9549

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Closes #9549

Summary

Lane scripts no longer fail an activity on one transient network error (undici fetch failed, ECONNRESET, UND_ERR_SOCKET) or a 5xx on a read or on a write that is safe to send again. Most scripts used to send their non-GET requests once.

No workflow file is touched, so the token broker's workflow-modified refusal does not apply and lane runs on this PR are not skipped. The broker refuses only while a PR changes a caller of request-lane-token or pr-run-activity-write.yml (.github/actions/request-lane-token/README.md). The lane's own patch edited pr-run-activity-write.yml to copy a new pr-unblock/retry-fetch.mjs beside apply-patch's base copy. This PR doesn't need that edit: apply-patch imports its own sibling copy instead, and collect-base-activity already copies the script's whole directory (.github/actions/collect-base-activity/action.yml, "Copy the script's base directory").

Fix

  • Shared client (check-trusted-trigger.mjs retryServerErrors): a POST to /graphql whose document is a query, with no mutation or subscription anywhere in it (isGraphQLRead), now gets the existing GET treatment. That means a 20 s attempt timeout and up to 3 resends with equal jitter, inside the 60 s budget. A mutation is still sent once. The mutation check reads the raw document, so a # inside a string cannot hide a mutation after it. This covers every createGitHub and retryServerErrors user, including budgetedFetch (dispatch.mjs and its siblings); the issue lists resolve-pr, select-trusted-text, resolve-config, write-issue, check-trusted-trigger, admit and gate-check among them.
  • Hand-rolled clients (apply-patch, address-feedback, report-outcome, post-statuses) now go through retry-fetch.mjs.
    • It allows at most 3 attempts, with full-jitter waits of a random share of 4 s, then of 8 s. These are the caps enable-auto-merge.mjs uses (RETRY_CAPS_MS); the owner's rule Q677 is not written down in this repository.
    • Reads and GraphQL queries always get the resend. A write gets it only when its caller passes safeToResend.
    • Each script runs from a copy of its own directory, so the file sits in apply-patch/, pr-unblock/ and work-resolve-issue/. retry-fetch.test.mjs asserts the three copies are byte-identical.
  • Writes marked safe to resend:
    • Git Data blob, tree and commit creates: each answer names the sha that gets used, so a second create only leaves an unreferenced object.
    • Ref updates: they carry the sha they set.
    • Pull request close.
    • Issue label add and remove.
    • Commit statuses: the newest status of a context wins.
  • Writes sent once: comments, issues, createRef, and every mutation.
  • POST /pulls in report-outcome: after a network error, the script reads the open pull request back with the existing bot-filtered lookup, and creates it again only when there is none.
  • dispatch.mjs: sends Connection: close on every request (request and paginate), as enable-auto-merge.mjs already does. The pool then never holds a socket that sat idle through the up to 5 × 10 s waits, and the dispatch POST, which is not resent, opens a new connection.
    • A local probe with Node 24 fetch showed that a request carrying Connection: close still goes out on an already-pooled idle socket. The header closes the socket only after the answer.
    • So sending the header only on the dispatch, or only after a long idle (as the issue's Fix section suggests), would not have kept the dispatch off a stale socket.
  • enable-auto-merge.mjs: comment updated, since the shared client now also resends GraphQL queries.
  • merge-holds.mjs is left as it is. It is not in the issue's done-when list, and it is fetched alone by pr-require-checks.yml, so it cannot import a module.

Verification

Every new resend test fails against the base code. The apply-patch and address-feedback tests were run this pass in a throwaway worktree at origin/main (ba401acab7) with only the two test files changed to this branch's bytes (cmp identical):

  • apply-patch.test.mjs on the base: 133 of 134 pass; the new createGitHubApi sends a read and each repeatable write again after a dropped socket, and createRef once fails, its first GET raising TypeError: fetch failed (UND_ERR_SOCKET) with no resend.
  • address-feedback.test.mjs on the base: 113 of 114 pass; the new createGitHubApi sends reads, GraphQL queries and repeatable writes again after a dropped socket, and an issue or a mutation once fails, its first GET raising TypeError: fetch failed (ECONNRESET) with no resend.
  • The shared-client GraphQL-query tests, report-outcome, post-statuses and dispatch tests also fail against the base (run in the earlier pass, not repeated). The new #-in-a-string mutation case fails (1 of 365) against the earlier isGraphQLRead that stripped comments before its mutation check. retry-fetch.test.mjs has no base to run against.

On this branch:

  • node --test .github/actions/check-trusted-trigger/check-trusted-trigger.test.mjs: 365 pass. The mutation-once test is a negative guard and passes on the base too.
  • node --test .github/scripts/work-resolve-issue/retry-fetch.test.mjs: 8 pass, including copy identity, the 3-attempt limit, cap shares, write-once, and query vs mutation.
  • node --test .github/scripts/apply-patch/apply-patch.test.mjs: 134 pass. A dropped socket on a read, a blob, a tree, a commit and a ref update is followed by success; createRef is sent once.
  • node --test .github/scripts/pr-unblock/address-feedback.test.mjs: 114 pass. The read, the GraphQL query, the close and the ref update each survive a dropped socket; the issue and the mutation are sent once.
  • node --test .github/scripts/work-resolve-issue/report-outcome.test.mjs: 230 pass. After a dropped PR create, the PR is read back: one create when it landed, two when it did not. A dropped compare read is sent again.
  • node --test .github/scripts/work-resolve-issue/post-statuses.test.mjs: 23 pass. A dropped branch read and a dropped status post both survive.
  • node --test .github/scripts/pr-unblock/dispatch.test.mjs: 50 pass. Real fetch against a local server that keeps idle sockets open: the dispatch arrives on a socket no earlier request used. It failed 3 of 3 runs against the base and passed 5 of 5 runs with the fix.
  • Every tracked .github/**/*.test.mjs, after npm ci in .github/actions/resolve-config and .github/standards/runner-policy: 4297 pass, 0 fail.
  • scripts/run-test-file.sh on the shell suites that name a touched file: report-escalation.test.sh, ci-lanes-pr-hold.test.sh, ci-review-lanes.test.sh, read-runner-dispatcher-gate.test.sh (9), write-runner-never-rules.test.sh (76) and write-runner-promote-holds.test.sh (22) all pass.
  • scripts/sync-shared-copies.sh --check: all 526 registered copies match.
  • scripts/check-changelog-fragments.sh --check and --check-required origin/main: pass.
  • editorconfig-checker on the changed files: pass.

Related

  • Issue: #9549. The lane run that stopped on patch-protected-path: run 40055373926.
  • The Connection: close precedent and the 4 s/8 s full-jitter caps: .github/scripts/pr-merge/enable-auto-merge.mjs (withRetry, RETRY_CAPS_MS).
  • Known limit: the three retry-fetch.mjs copies are not in scripts/shared-copies.txt. scripts/sync-shared-copies.sh accepts only copies under plugins/<name>/ and prepends a generated header that would break the byte-identity test, so retry-fetch.test.mjs holds them equal instead.

🤖 Generated with Claude Code

kyle-sexton and others added 9 commits October 25, 2026 16:15
… and safe writes

The shared client (retryServerErrors) times and resends a GraphQL POST
whose document is a query under its GET rules. apply-patch,
address-feedback, report-outcome and post-statuses send reads and writes
that repeat to the same state again after a network error or a 5xx (at
most 3 attempts, full-jitter waits capped at 4 s then 8 s) through
retry-fetch.mjs, one copy per script directory since each runs from a
copy of its own. report-outcome reads an open PR back before it resends
a create that failed on the network. dispatch.mjs sends Connection:
close on every request, so its dispatch after the idle waits never goes
out on a pooled socket GitHub may have dropped.

Closes #9549

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… resending

isGraphQLRead stripped `#` comments before looking for a mutation, so a
`#` inside a string hid any mutation after it on that line and the write
was treated as a resendable read. The mutation check now reads the raw
document; only the leading-token check uses the comment-stripped text.

Refs: #9549

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y-9549

# Conflicts:
#	.github/actions/check-trusted-trigger/check-trusted-trigger.mjs
#	.github/scripts/pr-merge/enable-auto-merge.mjs
…s import

Main's floor (bee2891, owner decision Q-ENFORCE (A)) holds every module
the floor-enforcing scripts import, address-feedback.mjs and
report-outcome.mjs included. This branch makes both import a retry-fetch.mjs
from their own directory, so the merge left two imported modules off the
floor and test_merge_holds_sync's closure check failed. Both copies now sit
on HOLD_PATH_FLOOR, babysit_risk.HIGH_FLOOR, ci-status hold_patterns and the
review lanes' hold-paths, with the floor tests and the README extended.

Refs: #9549

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…every retry-fetch copy

A `#` inside a string could hide a later mutation from the comment-stripped
text, so the lane would resend it. The shared client already reads the raw
document; the three retry-fetch copies now do too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y-9549

# Conflicts:
#	.github/scripts/apply-patch/apply-patch.mjs
#	.github/workflows/pr-require-checks.yml
#	plugins/source-control/skills/babysit-prs/scripts/tests/test_merge_holds_sync.py
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T21:12:54.860682Z 8722780 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 8722780f72eb9a0295d77f6ec70b373a2851618e: 0 finding(s), 0 as inline comments.

No security findings in this pull request.

critical-findings: 0

I read all of .claude-lane/pr.diff (29 files) and the PR context. I did not check the files against the checkout, and I did not read docs/conventions/instruction-exception-register/README.md. No instruction surface (CLAUDE.md, rules, skill or agent body) is touched, so no standing rule was deleted or softened.

Trust controls (all trusted-path files read in full)

  • Merge holds are only widened. merge-holds.mjs (HOLD_PATH_FLOOR), babysit_risk.py (HIGH_FLOOR), the hold_patterns array in pr-require-checks.yml (ci-status), and hold-paths in pr-review-hosted.yml and pr-review-security-hosted.yml each gain the same two entries: pr-unblock/retry-fetch.mjs and work-resolve-issue/retry-fetch.mjs. No entry is removed or narrowed, and the lists match across all five places. The tests move to 40 floor paths to match. Because the two new modules are imported by floored scripts (address-feedback.mjs, report-outcome.mjs), a PR that edits them now needs a person. This closes a gap, so it is not a finding.
  • The trusted-trigger check is not widened. The only change to check-trusted-trigger.mjs is the graphqlQuery regex in the shared client. It decides which requests may be resent after a network error or 5xx. It does not touch the trusted-actor list, fail-closed handling or trigger gating. A GraphQL mutation can't be treated as a read, because:
    • the prefix test requires query or { after comments are stripped;
    • the mutation|subscription test runs on the raw, unstripped document, so a # inside a string hides nothing (this is the case the new test covers);
    • any operationName disables the resend.
  • The kill switch, request-lane-token, resolve-config and the token broker's loaded code are not touched.

New retry-fetch.mjs (identical copies in apply-patch/, pr-unblock/, work-resolve-issue/)

  • A write is resent only when its caller passes safeToResend. The marked writes repeat to the same state: Git Data blob, tree and commit creates, ref updates (which carry the sha they set), PR close, issue label add and remove, and commit statuses. createRef, comments, issue creation and every mutation are sent once.
  • The resent label add is the needs-human hand-back, and it is idempotent, so a duplicate cannot lose the hold. A DELETE resent after it landed gets a 404, which applyHandBack already catches and logs.
  • The POST /pulls fallback in report-outcome.mjs reads the PR back through the same bot-filtered lookup (candidate.user?.login === bot) before creating again. It only adopts a PR the lanes App opened, so it adds no way to adopt a third party's PR.
  • Retry log lines name the error type and cause code, not the message, so the token is not echoed.
  • Attempts are capped at 3 with bounded waits. 4xx responses and non-network errors are rethrown at once.
  • dispatch.mjs adds Connection: close. This is a transport-level change with no trust effect, and the dispatch POST is still not resent.

Manifests: no plugin.json or marketplace.json is changed, so there are no manifest <field> lines.

Non-security note: the PR description says no workflow file is touched, but the diff edits pr-require-checks.yml, pr-review-hosted.yml and pr-review-security-hosted.yml. The edits only add hold paths. The description's reasoning about the broker's workflow-modified refusal may need rechecking, because that refusal applies when a PR changes a caller of request-lane-token. That would at worst make the lane runs on this PR get skipped. It is not a vulnerability.

Spend: the extra retries (up to 3 attempts per call) draw only on existing Actions runtime and API rate budget. There is no billing change, so no hold.

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed 8722780f72eb9a0295d77f6ec70b373a2851618e: 0 finding(s), 0 as inline comments.

Code review: no blocking findings

I read the full diff (.claude-lane/pr.diff) and the PR context. I could not run tests: this lane has no shell. Every test result in the PR description is author-claimed and unverified by me.

Closing issue #9549, criteria

  • Read-only GraphQL POSTs retry through the shared client. Met. check-trusted-trigger.mjs now strips # comments for the prefix check only, and the mutation check still reads the raw document. The new tests cover a 502 followed by a dropped socket, a comment or { shorthand opening the query, and mutations sent once, including the #-in-a-string case.
  • apply-patch, report-outcome, post-statuses and address-feedback retry reads and safe writes, with a test for a failure followed by success. Met. Each has a test: apply-patch.test.mjs, address-feedback.test.mjs, report-outcome.test.mjs and post-statuses.test.mjs.
  • dispatch.mjs's dispatch POST survives a dropped idle socket. Met. Connection: close is on every request, and dispatch.test.mjs uses a real-fetch server to check the dispatch gets a socket no earlier request used.

What I checked

  • retry-fetch.mjs copies. The three copies are byte-identical in the diff. retry-fetch.test.mjs asserts identity from the work-resolve-issue directory.
  • Resend rules. safeToResend is stripped before the request reaches fetch, and the 3-attempt limit (waits of up to 4 s, then 8 s) matches enable-auto-merge.mjs. Retry log lines carry the error name and cause code, never the message, so a token in an undici message cannot leak.
  • Marked-safe writes.
    • The Git Data blob, tree and commit creates are safe because their answers name the sha that gets used.
    • Ref updates carry the sha they set.
    • A PR close, an issue label add and a label remove (a 404 on a repeat is caught and logged) leave the same state.
    • A commit status is newest-wins.
    • Comments, issues, createRef and mutations are still sent once.
  • POST /pulls. After a network error, report-outcome reads the bot's open PR back and creates it again only when none is there. A 5xx answer is not a network error and still fails the step; a rerun finds the PR, as before.
  • Hold floor. The two new retry-fetch.mjs paths are added to HOLD_PATH_FLOOR, HIGH_FLOOR, the pr-require-checks.yml hold_patterns and both hosted review lanes' hold-paths. The tests were updated to match, including the floor-size count (38 to 40). The apply-patch/ copy is not floored, which is consistent because apply-patch.mjs is not floored.
  • Base-copy assumption. I confirmed collect-base-activity runs cp -R on the script's whole directory, so the sibling retry-fetch.mjs travels with a script run from a base copy.
  • Trusted paths. The trusted-path files in this diff (check-trusted-trigger.mjs, merge-holds.mjs, address-feedback.mjs, report-outcome.mjs, babysit_risk.py and pr-require-checks.yml) only gain the retry behavior and the added hold paths. None of them loosens a gate. The change to isGraphQLRead errs toward treating a document as a write.

Description is inaccurate (not a code finding): the PR body says "No workflow file is touched", but the diff edits .github/workflows/pr-require-checks.yml, pr-review-hosted.yml and pr-review-security-hosted.yml. These are hold-path list edits. A grep shows the two review workflows only list the request-lane-token path and none of the three calls request-lane-token or pr-run-activity-write.yml, so the broker's workflow-modified refusal most likely still does not apply. The description's stated rationale should still be corrected so a reader does not rely on it.

Spend: none beyond prepaid or subscription usage. There are no billing, plan or paid-resource changes, so no hold.

Manifest items: no plugin.json or marketplace.json change. The two changelog fragments are bump: patch, which fits a bug fix and a hold-list addition.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 26, 2026
Merged via the queue into main with commit 108da2e Oct 26, 2026
48 checks passed
@kyle-sexton
kyle-sexton deleted the fix/lane-scripts-retry-9549 branch October 26, 2026 22:22
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.

fix(pr-pipeline): retry transient network errors on lane script reads and safe writes

1 participant