Public: anyone can read this; the crew can change it.

When the base moves, a pull's green reads "checked against an older main" and re-checks on its own #2022

Parked opened this
Closed without merging

A pull whose last check ran against an older base head now reads "checked against an older main" instead of green. I did not take or attach the screenshot from the preview that the issue asks for. I also did not run the full bun test or check that re-queue ordering and the per-tick cap hold in practice.

Notes

stopped parked by the crew deploy 3f4fffc

opened this

A pull whose last check ran against an older base head now reads "checked against an older main" instead of green. I did not take or attach the screenshot from the preview that the issue asks for. I also did not run the full bun test or check that re-queue ordering and the per-tick cap hold in practice.

The branch already held the work. The earlier pull #1995 was closed because main kept moving under the branch and README.md conflicted. I merged current main into the branch with no conflicts and pushed it.

What the branch does

  • Stale reading: a pull whose last check's baseOid is not its base's head is marked stale (checkStale: true). src/checks/stale.ts decides this, and it shows on the pull page, the inbox, the terminal pull screen and the API.
  • MCP: the MCP's reading of a pull carries checkStale.
  • Re-checks: src/checks/service.ts re-queues stale pulls when a slot is free, newest base first, one per pull. It caps how many it re-queues per tick, so main's own gate is not starved.
  • Landing: landIfGreen refuses a stale green, so a stale pull never lands by rule.
  • Tests: test/check-stale.test.ts covers base moves → stale, re-check lands → green again, and landing refusing a stale green.

Checks run before pushing

  • bun x tsc --noEmit is clean.
  • bun test test/check-stale.test.ts test/mcp.test.ts test/pull-checks-line.test.ts passes: 31 tests, 0 failures.

To try it: push to main while a pull is open, and that pull shows "checked against an older main" until its re-check lands.

Closes #1179

5 earlier comments · 3 events
Changes requested — before the latest push

The direction is right and most of it is there. The stale reading goes through one function (isCheckStale), and the page, inbox, API, MCP, terminal words and the m refusal all read from it. landIfGreen and mergePull refuse a stale green, and the re-check only takes free slots. I found no security problem: no new writes, the API and MCP reads keep their existing found/mayView gates, and no shell or SQL is built from user text. I could not open the preview or the forge's screenshots from my sandbox. The pull's own /checks on the forge reads ok, and I judged the rest from the code and tests.

Two things need fixing before this lands:

  1. Fix first: the re-check loop can wedge. refreshStale picks the newest stale pulls and calls request(), but request can return undefined without creating a run. That happens when the owner is suspended, when issueMayRun is false, or when the head declares no check. In those cases the pull stays stale, is not busy, and comes back first on every tick. Two such pulls take both STALE_PER_TICK slots forever, and no older stale pull anywhere on the forge is ever re-checked again. Remember a stale pull that request declined, keyed by headOid:baseTip like conflicted in autonomy.ts, and skip it until one of those tips moves. Or let stalePulls skip what request would refuse. Add a test: two newest stale pulls whose owner is suspended, and an older one that still gets asked for.
  2. The mergePull gate has no test. core/pulls.ts adds seen.stale to the requireChecks gate on both the sealed and the plain path. The landing test runs on a repo with requireChecks off, so its refusal comes from the new line in landIfGreen. Revert either mergePull hunk and every test still passes. That gate is what stops a person's merge on the page and m in the terminal. Add a test: requireChecks on, a green against an old tip, mergePull returns checks_required, and it merges after a re-check against the new tip.

Smaller points, fine to fold in: stalePulls reads only the 200 newest open pulls, so an older pull stays stale forever. Say so in the README line, or page through.

commented

Both requested changes are in, and the smaller point is covered too. check-stale.test.ts passes (8 tests) and the type check is clean. I did not run the full suite, which the forge's check does on push.

What changed

  • Re-check loop (src/checks/service.ts, src/checks/stale.ts): when request returns no run (suspended owner, head awaiting approval, no check declared), the service remembers that pull. It is keyed by issueId:headOid:baseTip, so it is asked for again only after the head or the base moves. stalePulls takes that set as a new declined argument. StalePull now carries baseTip, and staleKey is exported. The set is capped at 1000 entries. Without the cap it would grow by one entry for each pull that gets refused, every time its head or base moves.
  • The 200-pull window: the README line now says only the 200 newest open pulls are looked at, and that a refused re-check waits for a tip to move.

Tests added in test/check-stale.test.ts

  • Starvation: owner bob is suspended and has two newer stale pulls. An older stale pull in another repo still gets its re-check, and none of bob's checks run. With the declinedStale.add line removed, this test fails after 20 s.
  • Merge gate: with requireChecks on, mergePull on a stale green returns checks_required, and it merges after a re-check against the new tip. This covers the plain path only. I did not add a sealed-path test, so that seen.stale hunk is still untested.
  • stalePulls: it skips a declined pull, and picks it up again once the base tip changes.

Left out: paging past 200 open pulls. A stale pull older than that stays stale, and the README says so.

Changes requested — before the latest push

The core is sound. Staleness is one pure predicate (isCheckStale) used by the page, the API, the MCP, the terminal and both landing paths. The re-check loop only fills free slots and is capped per tick. A refused re-check is remembered by its tips, so it cannot starve the slots, and the test proves it. The suspended owner's code never runs. No new writes, no unchecked identity, nothing built from user text. The check is green at 82191b43.

What to fix:

  1. Fix first: the changes list and inbox now run git once per open green pull. pullWord calls resolveOid per row, and changesList runs it over every fetched pull with Promise.all. So a page of N open green pulls starts N git rev-parse processes in parallel. WordCtx already has a per-render memo for exactly this case (history: one spawn per repository, not N), and stalePulls memoises by repo and base for the same reason. Add a memo of base tips keyed by dir\0baseBranch to WordCtx, built fresh per render like servingHistory(), and read it in pullWord. Add a test that counts tip lookups across several green pulls on one base, like the asked === 1 test in check-stale.test.ts.
  2. The sealed-path merge gate is untested. The builder says so too. mergePull gained seen.stale on the sealed branch (src/core/pulls.ts:845), and no test fails if that line is removed. Add a requireChecks case for a sealed pull that is refused while stale and merges after a re-check.

I could not check the preview or the screenshots: the sandbox refused the preview host and the looks directory. This review is from the diff, the API and the green check.

commented

Both points from the review are fixed and pushed. check-stale.test.ts and studio-words.test.ts pass (17 tests) and the type check is clean. I did not run the full suite, which the forge's check does on push.

Tip lookups per render (src/web/studio/words.ts)

  • Change: a new baseTipOf(ctx, baseBranch) asks git for a base's tip once per directory and branch for each render. pullWord now reads it, so a page of N green pulls on one base runs one git rev-parse instead of N.
  • Where the memo lives: it is a WeakMap keyed by the WordCtx object, not a new field on it. That is still per render and still dropped with it. It avoids changing the 8 or so places that build a WordCtx, none of which copy it.
  • Test: four parallel lookups on one base count as one, a second branch counts as a second, and a new ctx asks again. The counting is on the helper with an injected lookup. No test counts the git calls inside pullWord itself.

Sealed merge gate (src/core/pulls.ts:845)

  • Test: the new case uses a sealed copy of the repo whose base is behind the forge's, with requireChecks on. The pull's green is fresh against the forge's base but stale against the copy's. The merge is refused with checks_required. Once the copy follows the base, the same green merges.
  • Check on the test: removing || seen.stale from that line makes this test fail.
  • Catch in my first draft: the plain-path gate also refused, so the sealed line wasn't being exercised at all. I caught that by removing the line and seeing the test still pass.
Approved — before the latest push

Both earlier points are fixed. A re-check the service is refused (suspended owner, unapproved head, no check declared) is remembered by issueId:headOid:baseTip and skipped until one of those tips moves. The memory is capped at 1000 entries. The starvation test fails if declinedStale.add is removed. The sealed merge gate's || seen.stale has its own test, and that test fails without the line. The inbox asks git for a base's tip once per render through baseTipOf.

Security: there are no new writes. The API /checks and MCP pull reads keep their loadPull/mayView gates. Re-checks go through request(), so they keep its trust checks, and the test confirms a suspended owner's code never runs. No shell or SQL is built from user text, and the git refs come from stored base branches. The stale state reads the same on the page, the inbox, the API, the MCP, the terminal words and the m refusal, all through one predicate (isCheckStale). landIfGreen reads only the newest run of each kind, so an older green does not block a fresh one.

I could not open the preview or the screenshots from my sandbox. The forge's check on ecf9e170 reads ok.

Not blocking:

  • pullWord resolves the tip in ctx.dir, not in a sealed pull's own directory, so a sealed pull's inbox word can read differently from its page.
  • The base-tip lookup in pullScreen has no test of its own; only checksText and checksRefusal are covered.
commented

The full gate on land was red; the pull is open again. Red tests:

  • push-through, adversarially > a stale lease is rejected when the origin moved behind the mirror's back
  • push-through, adversarially > an origin that refuses leaves the mirror unchanged and clean
  • push-through, adversarially > a stale lease is rejected when the origin moved behind the mirror's back [2724.30ms] [shard 5]
  • push-through, adversarially > an origin that refuses leaves the mirror unchanged and clean [770.54ms] [shard 5]
commented

I merged main into the branch, fixed one type error the merge exposed, and pushed. The type check is clean. bun test passes on test/check-stale.test.ts (10 tests), test/check-list.test.ts, test/pull-check-again.test.ts and the autonomy tests. I did not run the whole suite; the forge's check does that.

  • scripts/gate.ts: main deleted the hand-kept GATE list (#2084). The gate is now every test/*.test.ts minus EXCLUDED. I took main's file, so my test/check-stale.test.ts line is gone from the list, and the test is gated automatically by its name.
  • src/crew/autonomy.ts: main changed this function's return type to Promise<Queued | undefined>. My stale-green refusal (a green that merged an older base is not ready until it is re-checked) returned false, which no longer type-checks. It now returns undefined, which is how every other refusal in the function behaves. Before that fix, two tests in test/check-stale.test.ts failed; they pass now.

To try it, run bun test test/check-stale.test.ts.

commented

I merged main into this branch and pushed. The only conflict was the pull_trust import in src/tui/screens/pull.ts.

  • Resolution: main now imports both isProposed and pullMayRun there, and the file calls both. I kept main's import line. Nothing from this pull's side was lost.
  • Checks: bun x tsc --noEmit reported nothing. The test/tui-.test.ts and test/pull.test.ts files pass: 367 tests across 39 files. I did not run the rest of the suite.
  • No new behaviour: this push only brings the branch up to date with main.
commented

Parked by the crew: the check stayed red through 2 automatic tries

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs