Skip to content

fix(pr-pipeline): retry a failed intake hand-off in the demotion alert - #13120

Merged
kyle-sexton merged 10 commits into
mainfrom
fix/13022-demotion-alert-retry-handoff
Nov 4, 2026
Merged

kyle-sexton merged 10 commits into
mainfrom
fix/13022-demotion-alert-retry-handoff

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Closes #13022

Summary

When the post-merge demotion alert could not hand a fix or quarantine issue to intake triage, it labeled that issue needs-human, and nothing retried the hand-off. A failed hand-off is none of the owner's stop reasons. Now the run records it in a hidden marker comment, stays red, and each later alert run retries it.

Fix

  • .github/scripts/post-merge-demotion-alert/handoff.bash (new): the lock-then-dispatch hand-off, fix-issue filing, marker writes, and retry_undelivered. The retry reads only github-actions[bot]'s open issues and that identity's comments, and validates each value it reads before using it.
  • .github/workflows/post-merge-demotion-alert.yml: a retry step before filing, with continue-on-error; a failure in it fails the job at the end of the filing step. A failed hand-off adds no needs-human. A fix issue's marker goes on it and on its record, a quarantine issue's on the issue. The record's note says the hand-off failed and will be retried, or that no marker could be written when every write for that item failed.
  • Canary, revert and fix_over records keep their label, as a reviewed exception stated at the label site. Their relabel moves with fix(pr-pipeline): align every needs-human path with the owner stop rule #10517, per the decision on fix(pr-pipeline): retry a failed intake hand-off in the demotion alert instead of labeling needs-human #13022.
  • docs/contracts/loop-lane/ (18.0.0, major: §2 escalation contract), docs/conventions/pr-pipeline/README.md, a patch fragment.

Choices beyond the issue's text:

  • The duplicate guard is stricter than asked: any open fix issue for the check stops filing, at any SHA, matching the workflow's one-issue-per-check rule.
  • A check marker that finds its fix issue open also sends it, because a failed send and a successful one leave the issue looking the same. An already delivered issue can therefore get a second dispatch.
  • A marker naming an issue the run does not list as an open fix or quarantine issue stays in place, so the issue is delivered if it reopens or is listed later. It costs one comment read per run while its record is open.
  • A check marker clears after a reopen or a mute with no send. The reopen matches the workflow's rule that a reopened issue is not sent to intake again, and a mute means the check is closed as not planned or duplicate.
  • label-unblocked.test.mjs pins the fix marker and recurrence note to the workflow text, so both strings also sit in handoff.bash. That test is unchanged.

Verification

  • scripts/post-merge-demotion-alert.test.sh: 319 passed, 0 failed, on the worker's merged tree, by the verifier at 1aaa645564, and at 3e4f2eb89c after a merge of main that touched none of these files. It runs the real helper and the workflow's extracted step bodies. It adds a test-scope: path for the helper.
  • actionlint on the workflow and shellcheck on the helper and the test are clean.
  • workflow.test.mjs passed 14 of 14 at 1c86a7ff3c. The other node suites and pytest (81 quarantine, 900 postmerge and merge policy) passed on the first commit and were not re-run after the later rounds.
  • Three fresh-context verifier passes. The first two failed: a lost hand-off when marker writes fail, a docs overclaim, then a marker deleted for an unlisted issue. All are fixed and tested. The third passed every criterion but one, which failed on its wording: it required a send before any marker clear, and did not exempt the reopen and mute paths above.
  • PUT /issues/12341/lock on an already locked issue returned 204, so re-locking on a retry is safe.
  • Not run: the real GitHub API path. The tests use a gh stub. No test runs the retry and filing steps together in one job.

Known limits, left as they are:

  • Overlapping alert runs at different SHAs can both retry one check marker and file two fix issues, or dispatch one issue twice. The concurrency group is per signal, event and SHA. The filing path already had this race across SHAs; every canary run now acts on markers too.
  • If the send and every marker write fail together (an exhausted API pool makes this likely), nothing retries that item; the red run and the record's note show it. A quarantine issue has one marker, and the judge lists only new quarantine issues.
  • A fix issue whose only marker is on its record is stranded if that record closes first, because the retry reads open issues.
  • A failed read in the retry warns and leaves the job green; the next run retries.
  • A reopen whose comment posted but whose state change failed posts the note again on retry. An invalid marker is never cleared and is read each run.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 10 commits November 4, 2026 00:38
A fix or quarantine issue the post-merge demotion alert could not hand to
intake triage took needs-human, and nothing retried it. It now gets a hidden
marker comment, on the issue and on its record, and a new step before filing
re-sends what a marker names on every alert run, keeping lock before dispatch,
then deletes the marker. A check whose fix issue could not be filed or reopened
gets the marker on its record; the retry files or reopens it unless a fix issue
for that check is already open. Only github-actions[bot]'s own comments on its
own open issues count. The job still exits 1 on a failed hand-off.

Canary, revert and fix_over labels stay, as a reviewed exception stated in the
workflow.

Refs: #13022

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A retry that filed a fix issue it could not send or mark deleted the check
marker anyway, so the issue was never sent. mark_undelivered now returns 1 on
a failed write, and the check marker clears only once the issue is delivered
or a replacement marker exists. A check marker that finds its fix issue open
now sends it, unless this run already did. The docs say where each marker
goes: a fix issue's on it and its record, a quarantine issue's on the issue.

Refs: #13022

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The retry deleted a marker naming an issue its listing did not show as an open
fix or quarantine issue, which could lose a hand-off: the issue's first line
may have been edited, it may reopen, or the listing may be older than the
marker. The marker now stays and a later run delivers the issue. The record's
note also says when no marker could be written for an item, since no run
retries that one.

Refs: #13022

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 4, 2026 06:43
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 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-11-04T06:56:05.204910Z 3e4f2eb Draft marked ready
ℹ️ 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

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 3e4f2eb89c04a9ec68aee3a9da7ec3a6c3152ee1: read 7 of 7 changed file(s); 0 finding(s), 0 as inline comments.

Security review: no security issues found

I read every hunk of all 7 changed files. The only one under a trusted path is .github/workflows/post-merge-demotion-alert.yml, and I read its whole change and what it gates.

What I checked:

  • Who can trigger the new retry. retry_undelivered in .github/scripts/post-merge-demotion-alert/handoff.bash only reads open issues whose .user.login is github-actions[bot] and whose first line is a known alert marker. It only reads marker comments from that same account, and only when the marker is the whole first line (handoff.bash#L156-L183).
    • An issue marker re-sends only the issue it names. Only a record's marker may name another issue, and even then the target must appear in the listing as an open alert fix or quarantine issue (sendable).
    • Nobody outside can create a marker: not in an issue body, not in another account's comment, not from the lanes App. The tests cover each of these cases.
  • Injection. Check names read back from markers are re-validated against fix_charset (fix_name_ok). That charset has no backtick, $, quote, backslash or newline. Values go to gh as -f fields and to awk -v, so nothing is evaluated by a shell.
    • Comment ids and issue numbers must be positive integers.
    • The record's SHA and signal must match a strict regex.
    • The - Failing run: link must match an Actions run URL shape before it reaches a new issue body (handoff.bash#L234-L245). That line is read only from a github-actions[bot] issue body, which outsiders cannot edit.
  • Untrusted text reaching a credentialed lane. send_to_intake still locks the issue before dispatching, and a failed lock sends nothing.
    • One window is new: when the lock fails, the issue now stays unlocked until a later run retries it.
    • That window gives nothing away. Intake triage passes the model only comments from listed trusted authors and bots (intake-triage.yml#L141-L156, and the prompt at L392). An outsider's comment posted in that window never reaches the model.
  • Token and code provenance. The new retry step uses the same GH_TOKEN: ${{ github.token }} as the filing step, and the job's permissions: do not change. The helper is sourced from .base/, the main checkout the step already uses for its scripts, never from the code under test.
  • Owner threat model. The needs-human label on a failed intake hand-off is removed. This is a person-approval friction hold, not a security control, so it is not a finding. The canary, revert and fix_over labels stay.
  • Instruction surface. The changed docs (the loop-lane README and CHANGELOG, the pr-pipeline README) only describe the new escalation behavior. They remove no protected-class guardrail.

Spend: every alert run, canary runs included, now makes a few extra GitHub API calls (one issue listing, plus comment reads on alert issues that have comments). This uses rate-limit quota only and bills nothing.

No embedded instructions were found in the pull request context.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

claude-review reviewed 3e4f2eb89c04a9ec68aee3a9da7ec3a6c3152ee1: read 7 of 7 changed file(s); 0 finding(s), 0 as inline comments.

Code review: PR #13120, retry a failed intake hand-off in the demotion alert

Result: no blocking or advisory findings. I read every hunk of all 7 changed files. I also read the parts of post-merge-demotion-alert.yml at head that the new code depends on: the job if:, the .base checkout, read_records/own_records, every trap … EXIT in the filing step, the quarantine judge block, and the fix-issue loop.

Checked against closing issue #13022 and its decision comment

  1. No needs-human on a failed hand-off; the failure is recorded visibly; the next run retries it: met.
    • The quarantine path (send_to_intake → mark_undelivered … issue=$q, then handoff_failed=1) no longer adds needs-human.
    • The fix-issue path does the same. It also writes the record note ("The hand-off failed; the next alert run retries it…") and keeps exit 1.
    • The retry step (retry_undelivered) runs before filing on every alert run.
    • It reads only github-actions[bot]'s open issues, and only that account's comments whose whole first line is the marker. That matches answer 1's identity rule.
  2. needs-human kept only for reviewed stop reasons: met, as the decision comment scoped it.
    • The canary, revert and fix_over labels stay as a reviewed exception. The workflow comment states this, with TODO(#10517) (L1181-L1194).
  3. A test shows no needs-human and a retry on the next run: met.
    • scripts/post-merge-demotion-alert.test.sh takes the marker the first run actually posted and feeds it to the extracted retry step. It checks lock-before-dispatch order, marker clearing and the absence of /labels calls.
    • Negative cases cover: markers written by another author or the lanes App, a marker in an issue body, a marker that names a different issue, closed issues, and a check name outside the charset.
  • Answer 5 (no duplicate fix issue on retry): met, and stricter than asked. fix_work takes any open fix issue for the check, at any SHA, and files no second one. A test covers it.

Wiring checked

  • With continue-on-error: true on the retry step, steps.retry.outcome reads failure when it fails. The filing step turns that into exit 1 through its EXIT trap.
  • That trap is set before every early exit 0, and the temp-file trap at L527 keeps the check. The only other trap replacement (revert filing, L970) exits 1 anyway.
  • api-budget.bash and newer-green.bash set no EXIT trap, so the new trap overrides nothing.
  • report-red-main uses !cancelled(), so a red alert job caused only by a retry failure does not skip the report.
  • In the retry, own_records has 4 columns; in the filing step it has 7. fix_work reads only columns 1–4 and matches on $4, so both shapes work.
  • In the retry, own_records is local, so the appends inside fix_work stay within that call.
  • Quarantine issues are filed by the judge under github.token, with the marker as their first body line (babysit_postmerge.py _quarantine_body). So the retry's creator=github-actions[bot] listing does find them.

Not verified by me

The test count (319 passed), actionlint and shellcheck results, and the 204 response on re-locking an issue all come from the author. I could not run them: this lane has no shell. The PR also says no test runs the retry and filing steps together in one job, and that the real GitHub API path is untested.

Known limits

The PR body lists these and I accept them as stated: races between overlapping runs at different SHAs, a second dispatch of an issue already delivered, a fix issue stranded when only its record carried the marker and that record closed, and a failed read that warns but stays green.

Spend (not a finding, not a charge)

Every alert run, including each canary push run, now makes one paginated listing of open github-actions[bot] issues. It also reads the comments of each open fix, quarantine or record issue that has any comments. This uses the job's GITHUB_TOKEN API rate budget only.

Other checks

  • Path-scoped rules: cost-claims.md matches the changed docs/**/*.md files. None of the changed text makes a cost claim.
  • No plugin manifest changed.
  • No paved-path concerns.
  • No embedded instructions were found in the PR context.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 4, 2026
Merged via the queue into main with commit d31b0c6 Nov 4, 2026
89 checks passed
@kyle-sexton
kyle-sexton deleted the fix/13022-demotion-alert-retry-handoff branch November 4, 2026 06:56
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 a failed intake hand-off in the demotion alert instead of labeling needs-human

1 participant