Skip to content

perf(pr-merge): end an uncovered wake on one read - #15535

Merged
kyle-sexton merged 2 commits into
mainfrom
perf/pr-merge-needs-dispatch-precheck
Nov 12, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
perf/pr-merge-needs-dispatch-precheck

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

No related issue: hub GITHUB_TOKEN cut (D132, L550)

Summary

A PR-scoped pr-merge wake (pr-merge: arm #N) that runs while a lane merge has no full dispatch run covering it reaches "needs-dispatch" only after the last-report, carry, lane-records and fresh-check reads (36 or more GITHUB_TOKEN calls, estimated below), and arms nothing. That gap lasts until the next full run of main, which the 30-minute cap delays. This PR adds a one-call pre-check that ends such a wake before those reads. No gate is weakened: the pre-check can only end a wake early, never arm one.

Fix

  • babysit_postmerge.py --uncovered-since MERGED_AT --branch main (newest_dispatch_before, babysit_postmerge.py:2977; _uncovered_since, :3012) reads pr-require-checks.yml workflow_dispatch runs on the branch with per_page=1. It keeps the rows _runs keeps (this repository, that event, that branch) and adds no filter of its own: no conclusion filter and no actor filter, because _stop_uncovered's first pass counts every listed dispatch run. It exits 6 when the newest run was created before MERGED_AT, or when there are no runs at all, because _stop_uncovered (:2961) would stop in that case. It exits 0 when a run is newer and 3 on an unreadable page or a newest row that is not such a run. It returns before the identity, floor, anchor and pin reads (main() :5606-:5635).
  • pr-merge.yml enable-auto-merge, new step "Check whether a full run covers the newest lane merge" (pr-merge.yml:2540), PR-scoped runs only:
    • It takes the newest first-parent commit on the .base checkout whose author is merge.agent-identity (git log --fixed-strings --author, since the login's [bot] is a regex class otherwise), using its commit date (%cI).
    • On exit 6 it sets uncovered=true and prints a notice. The last-report, code-changed, carry read, run-cache start, lane-records and keep-report steps (:2570, :2607, :2657, :2696) now skip on that output.
    • The arm step stays skipped because no report stands, the same as on today's exit 6. The outcome line reads report=none outcome=skipped: the pre-check found a lane merge no dispatch run covers (needs-dispatch): the same tail as today's exit-6 wake, which reads report=fresh.
    • Any other answer runs today's path unchanged: covered, unreadable, a rate limit, a crash, or no lanes App commit on the checkout.
  • Coverage is read again on every wake. Nothing is carried.
  • The job timeout goes from 44 to 45 minutes, because the new step names a 1-minute timeout and workflow.test.mjs requires the job timeout to exceed the sum of the step timeouts.

Why a wrong answer is safe:

  • Today's arm stays. When the pre-check is right that the newest lane merge is uncovered, today's wake cannot arm either. A last-sweep report made before that merge is refused by shared_refusal, which requires the report to judge every merge the check would judge, and the idle settle passes no recompute. A report made after the merge carries needsDispatch, and idle_report_refusal refuses it. The fresh check then stops at exit 6 (pr-merge.yml:2747, --stop-uncovered).
  • The commit date is early, not late. The merge queue stamps the commit date (%cI) when it builds the group, which is at or before mergedAt. "Uncovered" therefore means that no run was created after mergedAt either. The bias is toward "covered", which falls through to today's path and only gives up savings. It is largest when the group spent a long time in CI.
  • Author is a narrower test than enqueuer. A lane merge is one the identity enqueued; this step tests who authored the commit. An owner or Dependabot PR the lane enqueued is not seen, which biases toward covered and is safe. A lanes App PR that a person merged would read as a lane merge, so the pre-check could wrongly say uncovered. That only leaves the arming to the next sweep, at most 30 minutes later.
  • A settled merge is not a false stop. A merge verifies only on a dispatch run created at or after it, so the newest such run is at or after the merge, and the pre-check reads covered.

Verification

Calls per gap wake, before and after. These are estimates until measured on real runs after merge.

  • Before, on the code path traced:
    • last-report.mjs 5, carry-run-cache.mjs read 4, lane-records.mjs read 1. settle --idle-tick refuses on the report alone (idle tick needs-dispatch), with no reads.
    • The fresh check up to its stop:
      • default_floor, lane_floor, _default_is_human (:5606-:5635)
      • _merged_since GraphQL pages (:3092) and the pin prefetch (:3111)
      • _dispatch_runs (:3166), then the exit 6
    • Cost reference, run 43142384398: last-report 5 + carry 4 + lane-records 1 + fresh check 26 (19 core + 7 GraphQL) = 36 calls on the reads the pre-check skips. Those 26 are a floor: that check hit the exhausted core pool (exit 75) before its stop. That wake was not a gap wake for the pre-check: its checkout (8930f4caa) holds a newest lane merge dated 02:11:12Z, before the newest dispatch run (02:23:37Z), so the pre-check reads covered there and runs today's path. The analysis's figure of about 31 core + 15 GraphQL (L550) is in the same range.
    • No exit-6 wake was measured in the logs read this session. Two other wakes checked were covered: 43141333204 passed its stop and was refused unverified-stale, and 43118947929 armed. The pre-check reads covered for both and lets them through.
  • After: 1 core call (the per_page=1 listing), plus a local git log.
  • Saving: at least 35 GITHUB_TOKEN calls per gap wake. The ~58 core/h and ~29 GraphQL/h figures from L550 assume 47 such wakes a day, a rate this PR does not re-measure.

Tests (verbatim counts):

  • python3 -m unittest discover -s plugins/source-control/skills/babysit-prs/scripts/tests -p "test_babysit_postmerge*.py": Ran 578 tests ... OK. The new UncoveredSince class (9 tests) covers:
    • a merge newer than the newest run exits 6 on exactly one read
    • no run at all exits 6
    • a run at or after the merge falls through (0)
    • red, running, cancelled and other-actor runs count as cover
    • an unreadable listing (HTTP 502) falls through (3)
    • a short count, another branch's row or a fork's row falls through (3)
    • nothing else is read and no identity is needed
    • the argument refusals
  • node --test .github/scripts/pr-merge/workflow.test.mjs: tests 117, pass 117, fail 0. New tests:
    • the step's exit 6 output and its call sequence
    • covered, unreadable, rate-limited, crash and no-lane-merge answers run today's path
    • step order, and every skipped read gated on the pre-check
    • the outcome line
  • scripts/check-changelog-fragments.sh --check-required origin/main: passes.

Related

  • Owner decision D132: cuts by measured saving, no gate weakened.
  • Hub analysis L550, re-measured 2026-11-12: pr-merge.yml made 1,190 GITHUB_TOKEN calls over 25 runs in 2 h.
  • --stop-uncovered is the existing stop this pre-check runs ahead of.

session: GitHub Support

🤖 Generated with Claude Code

https://claude.ai/code/session_01VQb9Q1HHi6JACp77x2ZbE7

kyle-sexton and others added 2 commits November 11, 2026 22:40
A PR-scoped pr-merge wake whose newest lane merge no full dispatch run
covers yet ends today at the fresh check's --stop-uncovered exit 6, after
the last-report, carry, lane-records reads and the check's own floor,
anchor, merge, pin and run reads. The wake now reads main's newest full
dispatch run first (babysit_postmerge.py --uncovered-since, one call) and
compares it with the newest first-parent commit the lanes App authored.
When the run is older, the wake ends with the same needs-dispatch outcome
and skips those reads; any other answer runs today's path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VQb9Q1HHi6JACp77x2ZbE7
The pre-check's notice and outcome line now end as today's exit-6 wake
does ("no dispatch run covers ... (needs-dispatch)"), so tooling keyed on
that tail still counts these wakes; report=none tells them apart from a
fresh check's report=fresh. The job header comment names the pre-check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VQb9Q1HHi6JACp77x2ZbE7
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 12, 2026 04:06
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T04:16:33.923324Z a14fbf3 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 a14fbf39daec15ac78f67a84a31e5fc45f8a523f: read 5 of 5 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #15535 (perf(pr-merge): end an uncovered wake on one read)

No security issues found. I read every hunk of all 5 changed files. Two of them are trusted paths and got the extra scrutiny: .github/workflows/pr-merge.yml and plugins/source-control/skills/babysit-prs/scripts/babysit_postmerge.py.

What I checked

  • Merge hold (pr-merge.yml enable-auto-merge). The new precheck step can only set uncovered=true, and that output only adds != 'true' skip conditions to the last-report, code, carry, run-cache, lane-records and keep-report steps. On a PR-scoped run the arm step at pr-merge.yml#L2818 needs steps.keep-report.outputs.stands == 'true': if: steps.lane-token.outputs.token != '' && !(github.event_name == 'workflow_dispatch' && inputs.pr && steps.keep-report.outputs.stands != 'true'). When keep-report is skipped, stands is empty and arming stays skipped, so this fails closed. Every answer other than exit 6 (covered, unreadable, rate limit, crash, no lane merge) leaves the output unset and runs the path that runs today. The step can end a wake early. It cannot arm a pull request or get one past a hold. A wrong "uncovered" only puts off a disarm until the next sweep (at most 30 minutes, by the PR's account), and the merge gate still runs after that.
  • Tokens and permissions. The step uses GH_TOKEN: ${{ github.token }} (the job's contents: read / actions: read scopes). It does not use the lane App token, and the diff changes no permissions: block and no token request.
  • Injection. No pull request or user-supplied text reaches the run: block. inputs.pr appears only in the if:. $identity comes from the trusted .base checkout's docs/conventions/pr-pipeline.yaml, and $at from git log on .base. Both are quoted, and --fixed-strings keeps the [bot] in the login from acting as a regex. In the Python, branch is URL-encoded with quote(..., safe=''), and --uncovered-since is parsed by the existing _since type (an offset is required).
  • Python read logic (newest_dispatch_before). It makes one read-only listing call and writes nothing. Rows go through _run_rows, which keeps this repository's runs for that event, and the function also filters on head_branch. A fork's row or another branch's row raises PostMergeReadError and exits 3, so the wake falls through to today's path. Exit 6 is refused alongside --stop-uncovered and the other modes.

Other notes

  • Owner throughput-phase holds: this diff weakens none of the named friction holds. It adds an early exit that arms nothing.
  • Spend: none added. The change cuts GITHUB_TOKEN calls on a gap wake. The job timeout goes from 44 to 45 minutes on the same runner (ubuntu-24.04), which adds no billing.
  • No plugin manifest changed, and no standing instruction was deleted or narrowed.
  • No embedded directives found in the PR context.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: perf(pr-merge): end an uncovered wake on one read

No findings. I read every hunk of all 5 changed files. Three of them are on trusted paths: pr-merge.yml, babysit_postmerge.py and workflow.test.mjs's workflow gates. I gave those the extra security scrutiny the prompt asks for. A security lane runs here (pr-review-security-hosted.yml), so I left security judgments to it.

What I checked

The new step can only end a wake early. It cannot arm or disarm anything.

  • The pre-check sets uncovered=true only on exit 6.
  • On uncovered=true, keep-report is skipped. Its stands output is then empty, so the arm step's guard !(… && steps.keep-report.outputs.stands != 'true') keeps it skipped (pr-merge.yml#L2818).
  • The head-ref and skip-record reads are gated on stands == 'true'.
  • A PR-scoped run uploads no carry or skip artifacts (!inputs.pr, L2910), so a skipped read cannot leave an empty artifact behind for the next sweep.

Every other answer runs the old path. The step uses continue-on-error, set -uo pipefail without -e, an || exit 0 on yq and on git, and a 1-minute timeout. Because of that, a covered answer, an unreadable listing (3), a rate limit (75), a crash or a timeout all leave the output unset.

The two time stamps compared, %cI and created_at, lean toward "covered".

  • The commit date is at or before mergedAt. So a run created in between reads as covered, and the wake falls through to the old path. That is the safe direction.
  • The pre-check also counts every dispatch run as cover: any actor and any conclusion, cancelled included. This is broader than both _stop_uncovered's first pass (babysit_postmerge.py#L2961-L2974) and the sweep's cover listing, so it too can only make the pre-check say "covered" more often.

A settled lane merge cannot cause a false stop. _judge records a "no dispatch run by the agent identity within 6 h" failure for a lane merge with no dispatch run of its own (L2753-L2760). So a settled lane merge always has a dispatch run at or after it, and the pre-check reads it as covered.

There is one known false-stop case. A lanes App PR that a person merged has the App as commit author, but the fresh check does not judge it (--lane-merges-only). The PR body names this case. Its cost is that arming waits for the next sweep, at most 30 minutes later.

The git lookup has the history it needs.

  • .base is checked out with fetch-depth: 0 (L2418), so git log --first-parent --author can see past HEAD.
  • --fixed-strings also applies to --author, so the [bot] in the login is matched literally.
  • An empty result exits 0.

CLI wiring is correct.

  • --uncovered-since is in the mode group, needs --branch, and is refused together with --stop-uncovered.
  • It returns before the identity, floor and pin reads.
  • fromisoformat accepts git's Z suffix on the Python versions that support it (3.11+).

Job timeout. The step sum goes from 43 to 44 with the new 1-minute step, and the job timeout goes from 44 to 45 to stay above it.

Tests.

  • The new UncoveredSince class covers the call count, the boundary (a run in the same second counts as covered), and the unreadable, foreign and short pages.
  • The workflow tests check the step's gating on every skipped read and on the outcome line.
  • The checks regex's negative lookahead leaves exactly one real --stop-uncovered check.
  • The pass counts in the PR body (578 and 117) are the author's claims. I did not run them, since this lane has no shell.

Other criteria

  • Closing issue: none ("No related issue" in the PR body), so there are no acceptance criteria to check.
  • Plugin manifests: not changed. The changelog fragment's bump: minor fits a new CLI flag.
  • Path-scoped rules (skill-bodies-state-current-rules, cost-claims, ruff-pin): no violation in the changed lines.
  • Paved paths: docs/standards/README.md has no paved-path row, so there is nothing to check.
  • Embedded text: no directive aimed at this lane in the PR context.

API use: each PR-scoped wake makes one more GITHUB_TOKEN listing call when the newest lane merge is covered, and at least 35 fewer calls when it is not (the PR's own estimate). This is rate-limit budget only. No billing is involved, so there is no hold.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 12, 2026
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 12, 2026
Merged via the queue into main with commit 74c4781 Nov 12, 2026
87 checks passed
@kyle-sexton
kyle-sexton deleted the perf/pr-merge-needs-dispatch-precheck branch November 12, 2026 05:05
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-path: owner-agent Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant