Skip to content

fix(pr-pipeline): clear needs-session when a same-head fix-ci retry lands - #11476

Merged
kyle-sexton merged 4 commits into
mainfrom
fix/issue-11087-clear-needs-session
Oct 31, 2026
Merged

kyle-sexton merged 4 commits into
mainfrom
fix/issue-11087-clear-needs-session

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Closes #11087

Summary

A rung-0 flaky ci-fix-escalated stop adds needs-session. When the same-head retry lands, report-escalation.sh clear posts success, but nothing removed the label, so a Dependabot PR lost dependency review until a session took it off. This implements the 2026-10-31 decision on #11087 (option 3): the clear-escalations sweep removes the label, with no comment, once the stop's failing status has cleared.

That decision assumed no workflow edit. The sweep runs in the merge job, whose token could not read commit statuses, and the lanes App token holds no statuses permission, so every read would fail closed and the label would never come off. This PR adds the read-only grant, the only workflow change.

Fix

  • .github/workflows/pr-merge.yml: the merge job gains statuses: read, never write, the same read enable-auto-merge already declares for these statuses. The CHECKS_TOKEN and sweep comments now say so.
  • clear-escalations.mjs: the label comes off only when the lanes App added it last, and every stop routed to it since then has a success from github-actions[bot], newer than the stop, on that stop's head. A person's label, a still-failing stop, an unparsable stop or a failed status read keeps it.
  • Reads are bounded: at most SESSION_CHECKS_PER_RUN (5) PRs a run, kept or cleared, from the rotating offset. The lane's commit capped clears only, so a kept label would have been re-read every run with no limit.
  • The stop's failing status posts from report-stop-status, a job separate from the comment. A success older than the stop belongs to an earlier stop and no longer clears the label.

Verification

  • node --test .github/scripts/pr-merge/clear-escalations.test.mjs: 118 pass, 0 fail. Includes the rung-0 retry (label gone), the cause still present (label kept), a pre-stop success (kept) and the read cap.
  • node --test .github/scripts/pr-merge/clear-escalations-stale-hold.test.mjs: 17 pass, 0 fail.
  • node --test .github/scripts/pr-merge/workflow.test.mjs: 94 pass, 0 fail. No test pins the merge job's permissions, so none changed.

GitHub API delta per scheduled sweep (R34; the step runs only on the schedule, four times an hour):

Lanes App token Job GITHUB_TOKEN
Today (0 PRs carry needs-session) 1 list read 0
Typical, per PR read (at most 5) 1 timeline read 1 status read per routed stop
Writes at most 5 label deletes 0

So +1 read a run (+4 an hour) today, and in the worst typical case 1 + 5 + 5 reads on the lanes token, including deletes, plus 5 on the job token. A longer timeline or status list adds pages, bounded by paginate (50 pages) and readStatuses (10).

Left out: the live sweep, which runs only on main's schedule after merge. Local verify is off for this repository (pre_ready in docs/conventions/source-control.yaml); CI runs the affected suites.

Related

🤖 Generated with Claude Code

melodic-automation-lanes Bot and others added 4 commits October 31, 2026 03:11
Lane-Activity: work-resolve-issue/resolve-issue
(cherry picked from commit 4c7b250)
…session reads

The merge job gains statuses: read: the clear-escalations sweep reads a
lane stop's pr-unblock status with the job token, which the lanes App
cannot. Reads are capped at SESSION_CHECKS_PER_RUN, kept labels included,
and a success older than the stop no longer clears the label, since
report-stop-status posts the stop's failure in a separate job.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review October 31, 2026 07:57
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 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-31T07:59:42.121710Z 2da680f 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

Copy link
Copy Markdown
Contributor

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

I found no security issues in this change, so there is no hold.

critical-findings: 0

What I read: the full diff, the PR context and the surrounding clear-escalations.mjs code that the new sessionVerdict and clearSessionLabels functions use. I did not read docs/contracts/instruction-exception-register/README.md, because no instruction-surface rule is removed. The docs edits only add a sentence. No plugin manifest changed, so there are no manifest <field> lines.

Trust controls touched

  • .github/workflows/pr-merge.yml: the merge job gains statuses: read (line 830 of the head file). The grant is read-only. It goes on the job's own GITHUB_TOKEN, not the lanes App token, so the lane token's scope does not grow. No write scope is added and no secret is exposed. The if: condition and token wiring on the sweep step are unchanged, and the step still runs only after the kill switch passes. This does not widen what any token may do.
  • clear-escalations.mjs, hold path: the sweep can now remove needs-session. That label gates review-dependency and apply-dependency-patch through labels-absent, and the PR docs say no merge gate reads it. So removing it lifts no merge hold. The label comes off only if all of these hold:
    • The lanes App added the label last. isApp(labeled?.actor, bot) is checked on the timeline.
    • Every lanes-App-authored lane-stopped comment since then parses. Its Reason, Head and activity must agree through escalationActivity(reason) === activity. An unparsable stop keeps the label.
    • For each stop routed to the label, the newest github-actions[bot] status for that stop's context is success and newer than the stop comment's created_at/updated_at. A failed status read keeps the label.
  • Who can write the inputs:
    • A person cannot forge a stop comment: isApp filters on the lanes App.
    • The head SHA comes from that App-authored comment, not from PR text.
    • The success status must come from github-actions[bot]. Only a workflow in this repository holding statuses: write can post one. That is the same actor class that posts the real clear status.
    • Dependabot and fork PR tokens are read-only, so an outside author cannot post one.
  • Worst outcome: if a repository workflow posted a spurious success on that context, a dependency PR would regain automatic dependency review sooner. It would not be merged or armed. The merge gate and its holds are untouched.

Resource use: the sweep makes at most five PR reads a run, plus one status read per routed stop. This spends only API rate budget on existing tokens. It is not a billing change, so there is no cost hold.

Owner-threat-model note: no named friction hold (path, trust-path, person-approval, bot-author, pin) is weakened.

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed 2da680fb7938dd43c8159af4804c9c8d01399abf: 0 finding(s), 0 as inline comments.

No findings. I read the diff, the PR context, clear-escalations.mjs (main and its imports), report-escalation.sh, readStatuses and rotated, and the other test files that call clear-escalations. I ran no tests. The pass counts in the PR body are the author's claims, and I did not confirm them.

Closing issue #11087 criteria (the issue and its decision comment read as met):

  • "A stop whose failing status clears also removes the needs-session label its route added, in the clear-escalations sweep, without adding a person." sessionVerdict and clearSessionLabels do this and post no comment.
  • "A test covers a rung-0 flaky ci-fix-escalated stop whose same-head retry passes: the label is gone afterwards." The first new test in clear-escalations.test.mjs asserts the DELETE and that nothing else is written.
  • "A needs-session stop whose cause is still present keeps the label." One test covers four cases: failure, error, no status, and a success from a non-bot creator. Further tests cover a success older than the stop, a label added by a person, a stop that predates the label, a non-routed reason, an unread status and the per-run read cap. A test in the stale-hold file got the extra list route it needed.

Checked against the scripts:

  • Timing: report-escalation.sh adds the label before the stop comment, and edits the comment in place on a repeat stop. Taking the later of the comment's created and updated times as the stop time, and requiring a success status newer than that, holds up. A success from an earlier stop does not clear the label.
  • Where a stop's head moved on, the label stays. The code comment documents this.
  • A stop comment with an unparsable reason or head keeps the label, which fails safe. Hold-route stops use a different marker, so they never reach this path.
  • The merge job gains statuses: read and no write grant. The comments on CHECKS_TOKEN and the sweep match the change.
  • Rotated reads: rotated falls back to offset 0 when GITHUB_RUN_NUMBER is not a number, and the 5-PR cap counts kept labels as well as cleared ones.
  • Changelog fragment: bump: patch fits a bug fix, and the two docs updates (docs/contracts/loop-lane/README.md, docs/conventions/pr-pipeline/README.md) match the new behaviour.

Cost: more reads on prepaid API and Actions usage (a list read every sweep, and up to five timeline reads plus status reads per run when PRs carry needs-session). This is no billing change, so there is no hold.

@kyle-sexton
kyle-sexton enabled auto-merge October 31, 2026 08:38
@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 31, 2026
Merged via the queue into main with commit 705b9f7 Oct 31, 2026
98 checks passed
@kyle-sexton
kyle-sexton deleted the fix/issue-11087-clear-needs-session branch October 31, 2026 08:47
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): clear needs-session when a same-head fix-ci retry lands

1 participant