Skip to content

Landing a PR reuses an earlier CI run on the same merged code instead of starting another (GST-3634) - #4760

Merged
capy-ai[bot] merged 4 commits into
mainfrom
land-reuses-merged-tree-ci-run
Nov 24, 2026
Merged

capy-ai[bot] merged 4 commits into
mainfrom
land-reuses-merged-tree-ci-run

Conversation

@garrytan

@garrytan garrytan commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

When main has moved, gstack-ship-queue land --pin now reuses an earlier CI run on the same merged code: it lands at once on a green run, waits on one still queued and refuses on a red one, instead of starting a new run on every try.
Why: GitHub's macOS runner queue has been slower than land's 45-minute wait, so lands kept timing out while the run they started finished green unused.
Nothing to do. Rerunning a timed-out land now waits on the run it named.

What changed

A land onto a moved main kept getting refused with QUEUE_NOT_READY. Each try built a new merged commit, dispatched a new Free Tests run and gave up after 45 minutes, and the next try ignored the run that had since passed and joined the same queue again. #4753 was refused twice this way on the same base and the same merged tree.

Before it dispatches, land now lists the workflow's workflow_dispatch runs on gstack-land/<pr> and at the merged commit, and keeps those whose head commit has the merged tree. It matches on the tree, never the commit. Cancelled runs are skipped and the newest remaining run decides. A green run still has to pass lib/run-evidence.ts's verifyRun, and one that no longer proves the tree (its artifact expired, or it is too old) gets a fresh dispatch. A timeout names the run the next land will wait on. For a flaky red run, the fix line says to rerun that run (gh run rerun <id>), because rerunning land alone finds the same red run.

GitHub keeps a run going after its branch is deleted. Run 45249277829's macOS jobs started after the branch was deleted and passed, and the deleted branch's commit can still be fetched by sha. So land still deletes the scratch branch every time.

Blast radius

The one caller is landMergedCi in lib/ship-queue-land-direct.ts. When no earlier run matches, the old push, dispatch and wait path runs unchanged (the existing tests still pass). A read-only probe against GitHub with #4753's real runs, with push and dispatch stubbed out, adopted green run 45249277829 through the real verifyRun and pushed nothing.

Test Coverage

The test was written first: commit aced15f has 6 new cases failing against main's code. They now pass, plus 3 more added during review (16 in test/land-merged-ci.test.ts). The cases cover green, still-running, red, tree rather than commit matching, skipping cancelled runs, an unprovable green run falling through, a run at the merged commit, an adopted run that can't be proved, and timeouts on both a dispatched run and an adopted one. Not covered by tests: landMergedCi's fix-line wording, and the live runsOn API call (exercised by the probe above).

Pre-Landing Review

The specialist pass found 2 test gaps, both fixed (a test fake whose lookup used up scripted polls, and two untested outcomes at lib/land-merged-ci.ts:77). The second-model review (GPT-6.2 Sol) and the native adversarial pass raised three findings recorded as blocking. Each was ruled below the blocking floor and ships as an open note:

  • A, lib/land-merged-ci.ts:77: the choice to dispatch fresh reads the run-list snapshot, not what land saw while polling. If a green run is rerun between listing and polling, a red or timed-out rerun is ignored and land dispatches again (worst case about 90 minutes). It never lands on a red or unproven run. A follow-up PR fixes it.
  • B, lib/land-merged-ci.ts:47: reuse is keyed on the tree, not on base plus pin, and Free Tests' seed ratchet reads the merge base. This only matters if main returns to an identical merged tree. Tree matching is what the issue asked for.
  • C, lib/land-merged-ci.ts:63: a red run on a tree never expires, and gh run rerun stops working after 30 days. This needs a merged tree unchanged for 30 days.
Review notes

Below the blocking floor (advisory, informational, test-gap or wording items); recorded here and not fixed in this PR.

  • INFORMATIONAL lib/land-merged-ci.ts:47 4. lib/land-merged-ci.ts:47 — Land skips cancelled or wrong-tree runs before choosing a candidate, but the post-merge Free Tests consumer chooses the newest scratch-branch run before checking its status or tree (scripts/ci-tree-reuse.ts:80–87). In the new test’s older-green/newer-cancelled case, land passes without dispatching but main rejects the cancelled run and queues the entire suite agai
  • INFORMATIONAL lib/land-merged-ci.ts:77 The worst-case CI wait goes from 45 to 90 minutes, which equals DIRECT_LOCK_TTL_MS (90 minutes, crew/lib/ship-queue-land-lock.ts:37) before merged_checks time is even added. Another machine could then take over an expired lock while this land is still running. It's also a small correctness slip, because a red result for that tree gets dropped. The fix is to have settle mark the one case th
  • INFORMATIONAL lib/land-merged-ci.ts:77 2. INVESTIGATE: a red run now stays red for its tree until someone reruns it by hand. Any conclusion other than success or cancelled refuses with QUEUE_LAND_MERGED_CHECKS, as a red run: timed_out, startup_failure, action_required and stale included (settle, line 63). Every later land on that tree finds the same run, and the only way out is gh run rerun <id>. That isn't always
  • INFORMATIONAL lib/land-merged-ci.ts:77 3. INVESTIGATE: reuse matches on the tree, not the parent commits. Two merged commits can have the same tree and different parents. For example, main moves to B and then a revert C returns it to A's tree. A run on the old merged commit is then accepted for the new one. Anything in the free suite that reads git history (diffs against HEAD^1 or the merge base, checks on changelog fragments or
  • INFORMATIONAL lib/land-merged-ci.ts:106 4. FIXABLE: the branch run listing is capped at 20 runs. runsOn asks for per_page=20 with no paging (lib/land-merged-ci.ts:106). A PR whose gstack-land/<pr> branch has more than 20 newer dispatch runs on other trees won't find an older run on the matching tree, and dispatches a duplicate. That only wastes CI time; it never lands a wrong tree. Severity: Low. Blocks: no.
Exploratory QA

Pass. Probe 001: PR #4753's real runs on the deleted gstack-land/4753 with merged tree 6a3569f1 adopted green run 45249277829, checked by the real verifyRun, with no push or dispatch. Probe 002: the same branch with a tree no run tested adopted nothing and went on to push. Limits: a real dispatch and wait were stubbed out. The timeout and in-progress adoption are covered by unit tests only.

Scope Drift

Scope Check: CLEAN. The 45-minute timeout, the required jobs and the 7 required checks are unchanged.

TODOS

No TODO items completed in this PR.

Documentation

Status: current. The docs already describe the new merged-tree CI reuse, so the audit made no edits.

Scope: the branch land-reuses-merged-tree-ci-run against base a256d153, covering committed and working-tree content. The diff touches docs/ship-policy.md (the land policy row and the land --pin section), docs/troubleshooting.md (QUEUE_NOT_READY and QUEUE_LAND_MERGED_CHECKS), crew/docs/captain.md (the refusal table) and the changelog fragment. Each was checked against lib/land-merged-ci.ts, lib/land-merged-checks.ts and lib/run-evidence.ts.

Documentation health

  • docs/ship-policy.md: current. It covers reuse by tree, the newest run that wasn't cancelled deciding, the 45-minute wait, red runs refusing, and the gh run rerun advice.
  • docs/troubleshooting.md: current. The timeout and red-run fixes match the CLI's fix text.
  • crew/docs/captain.md: current. The rerun guidance for a red run matches.
  • changelog.d/land-reuses-merged-tree-ci-run.md: current. The fragment matches the behavior.

Coverage debt: none found.

Diagram drift: none, because no diagrams cover this path.

Tests
  • bun test test/land-merged-ci.test.ts: 16 pass, 0 fail
  • bun run typecheck and bun run typecheck:test: clean, no new diagnostics
  • Adjacent files (changelog-fragments, ci-tree-reuse, gstack-ship-policy, module-size-ratchet, run-evidence, ship-policy-compat, ship-queue-land-direct, troubleshooting-anchors, land-direct-recovery-isolation): 632 pass, 0 fail
  • Full free suite: CI on this head
Agent notes

Refs GST-3634

Approvals

Approved: yes (record r-03252b3ff4cb). The full approval record stays private.
Plan: exempt: bug fix (R65)
Plan check: exempt bug fix

REVIEW_LOOP: passes=1 blocking_found=4 deferred=0 noted=5 fixed=2 scope=frozen open=4 dispatches=1
Gate edits: none detected (GATE_SCAN tagged=0)
Ruled note: lib/land-merged-ci.ts:77:correctness at 9486779 ruled by GStack Minder (GSTA-36) (relayed from GSTA-36:2026-11-23T22:32:26Z) at 2026-11-23T22:32:26.450Z: A: rerun race at line 77 costs at worst a fresh dispatch; never lands a red or unproven run; fixed in the follow-up PR (approval a-4a5ef64f2371)
Ruled note: lib/land-merged-ci.ts:47:correctness at 9486779 ruled by GStack Minder (GSTA-36) (relayed from GSTA-36:2026-11-23T22:32:26Z) at 2026-11-23T22:32:26.568Z: B: tree key, not base plus pin; needs main to return to an identical merged tree; tree matching is what the brief asked for (approval a-ea1fbbc32895)
Ruled note: lib/land-merged-ci.ts:63:correctness at 9486779 ruled by GStack Minder (GSTA-36) (relayed from GSTA-36:2026-11-23T22:32:26Z) at 2026-11-23T22:32:26.675Z: C: a red run never expires; needs a merged tree unchanged for 30 days (approval a-8653a39469d1)

{
  "schema_version": 1,
  "pr": 4760,
  "head": "fbcafb238adfadff348152be427e6c6c7c22a89c",
  "version": "1.103.0.0",
  "base": "main",
  "gate": {
    "free": {
      "pass": 1779,
      "fail": 0,
      "skip": 0
    }
  },
  "ci_carried": [
    {
      "lane": "free",
      "run": 45281220216,
      "attempt": 1,
      "tree": "2f4c81de6f5c1a3366ce500bf9192da6b3ea1d02"
    }
  ],
  "calls": 32,
  "session_kind": "unattended",
  "run": "/home/user/.capy/work/gsta-831/ship",
  "head_tree": "2f4c81de6f5c1a3366ce500bf9192da6b3ea1d02",
  "product_patch_id": "74f228586f5a2a5df9f14b65fa16d88e7279ce4f",
  "gstack_version": "1.103.0.0",
  "review_depth": {
    "depth": "light",
    "class": "code",
    "runtime_lines": 101,
    "rules": "33831f8248a814fd",
    "base": "a256d1530dad693df5b66ddd3e3a43351cefe3e4",
    "registry": "a256d1530dad693df5b66ddd3e3a43351cefe3e4",
    "gate_scan": {
      "tagged": 0,
      "head": "fbcafb238adfadff348152be427e6c6c7c22a89c"
    },
    "reasons": [
      "runtime=101"
    ],
    "risk": [],
    "mode": "panel"
  },
  "pregate": "requires-remote cleared @2f4c81de6f5c (8 checks, current for fbcafb238adf)",
  "requires_remote": [
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/45281220216/attempts/1",
    "windows-smoke.yml/windows-smoke: https://github.com/garrytan/gstack/actions/runs/45281220000/attempts/1",
    "pregate.json/remote_gate: remote-gate tree=2f4c81de6f5c tests=39279 skipped=89 runs=45281220216/1 profiles=ci-reuse/free-tests heads=fbcafb238adf verified=2026-11-23T23:28:22.589Z"
  ],
  "issues": {
    "fixes": [],
    "refs": [],
    "flakes": []
  },
  "docs": {
    "status": "current",
    "scope": "docs/, crew/docs/, README.md, CLAUDE.md, AGENTS.md"
  },
  "review_loop": {
    "passes": 1,
    "blocking_found": 4,
    "deferred": 0,
    "noted": 5,
    "fixed": 2,
    "scope": "frozen",
    "rounds": 1,
    "dispatches": {
      "specialist": 1
    }
  },
  "ruled_notes": [
    {
      "finding": "lib/land-merged-ci.ts:77:correctness",
      "head": "9486779a50374cb944a36dfca8d9882a2221e49a",
      "by": "GStack Minder (GSTA-36)",
      "reason": "A: rerun race at line 77 costs at worst a fresh dispatch; never lands a red or unproven run; fixed in the follow-up PR",
      "at": "2026-11-23T22:32:26.450Z",
      "approval": "a-4a5ef64f2371",
      "relayed": "GSTA-36:2026-11-23T22:32:26Z"
    },
    {
      "finding": "lib/land-merged-ci.ts:47:correctness",
      "head": "9486779a50374cb944a36dfca8d9882a2221e49a",
      "by": "GStack Minder (GSTA-36)",
      "reason": "B: tree key, not base plus pin; needs main to return to an identical merged tree; tree matching is what the brief asked for",
      "at": "2026-11-23T22:32:26.568Z",
      "approval": "a-ea1fbbc32895",
      "relayed": "GSTA-36:2026-11-23T22:32:26Z"
    },
    {
      "finding": "lib/land-merged-ci.ts:63:correctness",
      "head": "9486779a50374cb944a36dfca8d9882a2221e49a",
      "by": "GStack Minder (GSTA-36)",
      "reason": "C: a red run never expires; needs a merged tree unchanged for 30 days",
      "at": "2026-11-23T22:32:26.675Z",
      "approval": "a-8653a39469d1",
      "relayed": "GSTA-36:2026-11-23T22:32:26Z"
    }
  ],
  "gate_dispositions": []
}
{"head":"9486779a50374cb944a36dfca8d9882a2221e49a","run":"ship-20261123T221818-f35724","status":"started","review_loop":{"passes":1,"blocking_found":0,"deferred":0,"noted":0,"fixed":2,"scope":"frozen","rounds":1,"dispatches":{"specialist":1}}}
{"head":"9486779a50374cb944a36dfca8d9882a2221e49a","run":"ship-20261123T221818-f35724","mark":"stop","tree":"f93f7bfee168df926260aa7b54d7f3aa09c1ad3f","at":"2026-11-23T22:30:56.878Z"}

Open in Capy

garrytan and others added 2 commits November 23, 2026 22:11
…ching another (GST-3634)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…atching another (GST-3634)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@trunk-io

trunk-io Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

garrytan and others added 2 commits November 23, 2026 22:25
Review-Finding: p1/specialist-batched#1 reader=testing
Review-Finding: p1/specialist-batched#2 reader=testing
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai
capy-ai Bot merged commit 1cb381b into main Nov 24, 2026
61 checks passed
capy-ai Bot added a commit that referenced this pull request Nov 24, 2026
- `/ship` now tells you what to change when GitHub refuses a push for email privacy. (#4748)
- The release gate's /cso check accepts the low-confidence hypotheses /cso now reports. (#4753)
- /cso reports every security finding the code supports instead of dropping most of them. (#4739)
- /cso can search the whole repository in one call, and a daily report now lists its low-confidence hypotheses. (#4742)
- A first version's plan and try-it message now open with the owner's own words, and the build is tried the same way he will try it before he is asked. (#4759)
- A first version's public export now keeps out the owner's short quotes and his reasons to leave something out, and a phone first-use check installs a build the cloud phone can actually run. (#4772)
- Three intermittent test failures are fixed. (#4745)
- Free Tests runs its shards on 8-core runners again. (#4749)
- A land that waits on an earlier CI run now decides on what that run actually did. (#4763)
- Landing a PR no longer starts a new CI run when one for the same merged code is already running or has passed. (#4760)
- /ship no longer misses a file-mode change from main on files whose names start with `:`. (#4774)
- make-pdf keeps quotes in alt text, link titles and raw HTML attributes inside the attribute, so a Markdown file can no longer add an `onerror`, `onload` or `javascript:` link that runs in the print browser. (#4761)
- Posting a PR body that lists earlier /ship runs no longer stops for a phone number that isn't there. (#4747)
- A first version's public export now catches a short owner quote whose padding or quote marks are encoded. (#4778)
- A first version's public export now also keeps out a short owner quote written with spaces just inside its quote marks. (#4776)
- Posting a PR body that lists earlier /ship runs no longer stops for a card number that isn't there. (#4751)
- /ship no longer asks for an extra reader when you merge the base branch next to code that was already reviewed. (#4754)
- /ship no longer plans narrow re-checks after a fix. (#4741)
- /ship can't quietly gain new refusals. (#4740)
- `gstack-upgrade` no longer refuses to run after you disable skills. (#4743)
- The free test suite splits its shards from this week's recorded test times. (#4744)
- gstack now writes up a failed or shelved attempt before closing it. (#4735)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
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.

1 participant