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

The engine picks the same issue every tick, is refused because a twin holds it, and starts nothing else #12379

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

An issue whose twin holds the same work is now held under its own `twin` reason, so the tick no longer counts it as startable and spends its pick on it. The held-card tests, `test/twin-runs.test.ts`, the relieves-map test and `tsc` pass. `scripts/gate.ts` printed nothing, which I read as green. `scripts/fast.ts` named 2177 of 3112 test files, so I ran the held and twin tests by hand and not the wh…

shipped production is serving it deploy 9cda780

opened this

An issue whose twin holds the same work is now held under its own twin reason, so the tick no longer counts it as startable and spends its pick on it. The held-card tests, test/twin-runs.test.ts, the relieves-map test and tsc pass. scripts/gate.ts printed nothing, which I read as green. scripts/fast.ts named 2177 of 3112 test files, so I ran the held and twin tests by hand and not the whole suite.

What changed

  • New hold: twin is added to HOLDS in src/crew/held.ts. It uses the same twinOf check the dispatcher applies, so the two cannot disagree. Variant-group issues share a title on purpose and are exempt. It sits after red_fix and before hot_file.
  • Tick line: the issue appears in held= as twin=N and drops out of startable. The picker only sees startable issues, so it moves on to the free one in the same tick. The refused-pick loop in the issue's description can't happen.
  • Map and issue page: the map API and MCP map give the reason as "waits for #N, which holds the same work". I did not check what the issue's own page shows, and there is no separate test for it.
  • Logging: the "build run refused: a twin holds the work" line in src/crew/dispatch.ts is logged at most once per issue per hour. The note on the issue's thread was already posted only once.
  • Tests: a new case in test/twin-runs.test.ts has one twin-held issue and one free one. The free one stays startable, the twin-held one lands under twin, and its reason names the twin.

Changed fixtures: test/boards-held.test.ts and test/held-relieves-map.test.ts gave several issues the same title. Those issues are now twins by definition, so I gave them distinct titles. The tests' intent is unchanged.

Not done: the dispatcher's own refusal is kept as a backstop for a person assigning a twin by hand.

To try it, open a twin of an issue that has a run going, then check held= on the next tick line or /map.

🤖 Generated with Claude Code

Closes #12376

4 earlier comments · 1 event
commented

An issue whose twin holds the same work is now held under its own twin reason, so the tick no longer counts it as startable and spends its pick on it. The held-card tests, test/twin-runs.test.ts, the relieves-map test and tsc pass. scripts/gate.ts printed nothing, which I read as green. scripts/fast.ts named 2177 of 3112 test files, so I ran the held and twin tests by hand and not the whole suite.

What changed

  • New hold: twin is added to HOLDS in src/crew/held.ts. It uses the same twinOf check the dispatcher applies, so the two cannot disagree. Variant-group issues share a title on purpose and are exempt. It sits after red_fix and before hot_file.
  • Tick line: the issue appears in held= as twin=N and drops out of startable. The picker only sees startable issues, so it moves on to the free one in the same tick. The refused-pick loop in the issue's description can't happen.
  • Map and issue page: the map API and MCP map give the reason as "waits for #N, which holds the same work". I did not check what the issue's own page shows, and there is no separate test for it.
  • Logging: the "build run refused: a twin holds the work" line in src/crew/dispatch.ts is logged at most once per issue per hour. The note on the issue's thread was already posted only once.
  • Tests: a new case in test/twin-runs.test.ts has one twin-held issue and one free one. The free one stays startable, the twin-held one lands under twin, and its reason names the twin.

Changed fixtures: test/boards-held.test.ts and test/held-relieves-map.test.ts gave several issues the same title. Those issues are now twins by definition, so I gave them distinct titles. The tests' intent is unchanged.

Not done: the dispatcher's own refusal is kept as a backstop for a person assigning a twin by hand.

To try it, open a twin of an issue that has a run going, then check held= on the next tick line or /map.

🤖 Generated with Claude Code

commented

An issue that a same-title twin already holds is now held as twin and never picked, so the engine stops choosing it every tick. The twin refusal also logs once an hour per issue instead of once a tick.

The failing check came from tests that had not caught up with that rule. Two of the three failures are fixed and pass locally, along with bun x tsc --noEmit. The third (the test/boundary-tenancy-cell.test.ts link test) I could not check here.

  • test/boards-held.test.ts: an earlier edit to the seeding helper left a ?5 placeholder with only four values bound, which is the SQLite error in the log. Every seeded issue was also titled 't', so they all counted as twins of each other. The helper now binds a distinct title per issue.
  • test/crew-direction-autonomy.test.ts: the reader's fork pull had the same title as the issue it closes, which the twin rule counts as holding the work. I gave the pull its own title ("Rounder corners, mine") so the test still checks that a reader's pull does not stand in for the issue it names. A fork pull that reuses the issue's title will now hold that issue as twin.
  • test/held-relieves-map.test.ts: I reverted my earlier edit to this file; it passes unchanged.
  • boundary-tenancy-cell.test.ts (the third failure): the 15 tests that need cells or unix sockets are skipped in this sandbox, and nothing in my change touches them, so I did not touch this one. The forge's check runs it on this push.

I did not run the whole suite; the forge's check does that on this push.

Changes requested — before the latest push

The twin hold is the right fix and shares twinOf with the dispatcher. Changes needed in one round:

  1. The once-an-hour log throttle has no test. Revert it and nothing fails. Add one that calls queueAgentRun twice for a twin-held issue and expects one log line, then advances the clock and expects another. Or drop the throttle: the hold now stops the per-tick pick, so the line should only fire for a hand assignment.
  2. heldBy now calls twinOf for every candidate issue on every tick and every map render. twin.ts says its queries once cost 10 s on the main thread. Show a timing with a few hundred open issues in a repo, or restrict the check to issues the tick could actually pick.
  3. twinLogged is module-level state with a wholesale clear at 1000 entries. Keep it bounded per entry (drop expired keys) or hold it with the dispatch state, not as a hidden global.
  4. The pull's own text says the issue page's reason was not checked. Verify the issue page and the TUI map show the twin reason, and add a test for it. The preview must show a twin-held issue under held=twin.
  5. Tests: add a case where a variant-group issue sharing a title is not held as twin. The exemption has no test.
commented

All five review items are addressed and pushed. bun scripts/gate.ts, bun x tsc --noEmit and test/twin-runs, mcp-flow-why, boards-held and held-relieves-map pass (42 tests). I did not run the full suite or check the preview.

What changed

  • Throttle test (1). Two queueAgentRun calls on a twin-held issue log one line; after the clock moves 1 h + 1 ms the next call logs a second. I kept the throttle because sweepAssigned re-offers a refused issue every sweep, since it never gets a run.
  • No hidden global (3). The throttle state is now a WeakMap<App, Map> in src/crew/dispatch.ts. Expired keys are dropped on each write, so there is no wholesale clear at 1000 entries.
  • Cost of the check (2). twinOf ran about 0.8 ms per issue, around 330 ms for 418 open issues. heldBy now makes one query for the titles that more than one issue or pull in the repo bears (sharedTitles in src/crew/twin.ts) and calls twinOf only for issues with such a title. heldNow over those 418 open issues, none of the 400 I added sharing a title, now takes about 44 ms. A test pins this: it logs both timings and fails if heldNow goes over 250 ms.
  • Reason on the issue page (4). The issue page does not render a hold at all. The "why is it not moving" answer behind it, whyIssue, only knew hot_file. I added a twin cause, so it now says "Another issue holds the same work: waits for #N…". A test shows an issue whose twin has a run going answering cause: "twin" and naming that issue.
  • TUI map and plan (4). These already read the generic hold detail, so a twin-held issue shows "waits for #N, which holds the same work" there. The existing held.by.twin / mapHolds test covers that path; I added no TUI-specific test.
  • Variant exemption (5). A variant-group issue sharing a title with a running issue is not held as twin, even though twinOf alone would match it. A test covers it.

I did not check that the preview shows a twin-held issue under held=twin. I only read the preview URL's role from your request; the tests above exercise the same code path.

commented

The gate failure is fixed and pushed. I rewrapped the two over-long comments in src/crew/dispatch.ts (the twinLogged map comment and the twinLogDue comment) to fit within 100 columns. No code changed.

After committing, bun scripts/gate.ts and bun x tsc --noEmit both pass. I did not re-run the tests, since only comments changed. The forge's check will run on this push. The gate only checks lines the pull adds, so it said nothing until the fix was committed, even though older lines in the file are longer.

commented

I fixed the two timing failures in test/twin-runs.test.ts and pushed. The third failure was not mine, and I did nothing about it.

  • What failed: the "twin hold stays cheap with hundreds of open issues" test asserted wall-clock bounds (under 2 ms per issue, under 250 ms for the pass). The check bans clock bounds in tests, so two rules flagged line 217.
  • The change: it now counts SQL statements with once and expectWork instead of timing. With 418 open issues, the twin lookup (twinOf) runs 1244 statements and the whole heldNow pass 1630. I capped twinOf at 3 statements per issue and the pass at 5 per issue.
  • How I checked: bun test test/twin-runs.test.ts passes (12 tests). bun scripts/gate.ts and bun x tsc --noEmit are clean.
  • Not mine: the third failure, "a link the forge left where its home goes is never mounted", is in test/boundary-tenancy-cell.test.ts. The check log says that file is also red on main at f057c8a, so it was not counted against this pull. I haven't touched it.

The statement caps are loose on purpose. They will catch the twin scan running per issue instead of once per repeated title, but not a small rise in cost.

Approved

Earlier asks, all met in the diff: (1) the hourly log throttle has a test that fails without it (one line, then a second after 1h+1ms); (2) heldBy now does one sharedTitles scan and calls twinOf only for repeated titles, and the test pins statement counts rather than clock time; (3) the throttle state is a WeakMap keyed by App with expired keys dropped, with no global and no wholesale clear; (4) whyIssue has a twin cause that names the holding issue, tested through MCP flow; (5) variant-group issues are exempt, tested. The pull does what the issue asked: a twin-held issue leaves startable, so the tick moves to the free one. Tests moved to distinct titles are justified. Non-blocking: the statement caps (3 per twinOf, 5 per issue for the pass) are loose, as the builder said, so tighten them to the measured 1244 and 1630 plus headroom. Non-blocking: no TUI-specific test for the twin detail, though it reads the generic hold detail. Next: close duplicate issues so twin holds clear; surface the hold on the issue page itself. I did not re-check the preview this round.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs