Repository navigation
Description
Context
packages/ui-backend-pi/tests/duplicate-acquisition.test.ts ("a concurrent duplicate resume reaches the pool race with two real workers and refuses only the loser after its refused teardown") fails intermittently on PI_DUPLICATE_RESUME_LOSER_CLOSED_BEFORE_REFUSAL (duplicate-acquisition.test.ts:135): expect(loser.closes).toBe(1) receives 2. The losing worker's turn-temp closeAsync is counted twice by the test's wrapper (duplicate-acquisition.test.ts:70).
The assertion was added by #3501 (main 04c192872, the #3488 fix). The loser branch is packages/ui-backend-pi/src/session-pool.ts:88-96, which awaits releaseLosingSession. The worker session has two turn-temp close sites: the memoised closeTurnTemp (packages/ui-backend-pi/src/worker-session.ts:300) and a direct launchedChild.turnTemp?.closeAsync() (packages/ui-backend-pi/src/worker-session.ts:281). Which path makes the second call has not been diagnosed.
Observed on 2026-11-03:
- Hosted: ready-candidate proof for test: land epic #1849 batch 1 — deterministic signals for real-time test waits and full-shard weight refreshes #3517 (head
4a1dac122, base29799ebcd), run https://github.com/schlessera/brain-kit/actions/runs/41721920839, jobunit (2). It was that run's only failing test. test: land epic #1849 batch 1 — deterministic signals for real-time test waits and full-shard weight refreshes #3517 does not changepackages/ui-backend-pi/srcor this test file. - Local, plain main
29799ebcd:bun run test packages/ui-backend-pi/tests/duplicate-acquisition.test.ts, 12 runs: 2 failed on this assertion. - Local, test: land epic #1849 batch 1 — deterministic signals for real-time test waits and full-shard weight refreshes #3517's tree: 12 runs, 5 failed on the same assertion.
So main carries the flake, and it blocks ready-candidate proof for any PR whose affected closure includes the pi backend.
Scope
Find why the losing worker's turn temp is closed twice in some interleavings, and make the close happen exactly once before the busy refusal settles, or correct the assertion if a second close is the intended idempotent behaviour. In that case the test must still prove the first close finished before the refusal.
Out of scope
- The refused-cleanup retry case (
duplicate-acquisition.test.ts:152, which expects 2 closes on purpose). - The new-session duplicate branch (
session-pool.ts:101-117).
Acceptance criteria
- The named test passes in 50 consecutive local runs of
bun run test packages/ui-backend-pi/tests/duplicate-acquisition.test.tson the fix head. - The cause of the second close is named in the PR, with the interleaving that produced it.
- backends: a pi duplicate-resume busy refusal settles before the losing worker's teardown #3488's guarantees still hold: the refusal settles only after the loser's worker exit, turn-temp close and stdio release.
Verification
for i in $(seq 1 50); do bun run test packages/ui-backend-pi/tests/duplicate-acquisition.test.ts || break; done
bun run check:pr --base origin/mainContract impact
None.
Activity
schlessera commentedon Nov 4, 2026
Claiming (token
c3544-d542), branchfix/3544-pi-duplicate-loser-close. Raised topriority: p1: this flake blocks ready-candidate proof for #3517 (epic #1849), and a blocker carries at least the priority of what it blocks.schlessera commentedon Nov 4, 2026
Another hosted occurrence, 2026-11-04. Ready-candidate proof for #3546 (head
46837b60b, base9805f52fd), run https://github.com/schlessera/brain-kit/actions/runs/41744666881, jobunit (4). It failedduplicate-acquisition.test.ts:135(PI_DUPLICATE_RESUME_LOSER_CLOSED_BEFORE_REFUSAL, expected1, received2). #3546 changes onlypackages/ui-sdk/tests/worker-var-sockets.test.tsand its fixture. That makes two of the last few ready proofs this issue has failed on its own (#3517, #3546), and it now blocks the declared fix for red-main incident #3545.fix(ui-backend-pi): close a torn-down worker's turn temp once per tea…
schlessera commentedon Nov 4, 2026
Fixed by #3547, squash-merged as
53b862123on main (ready-candidate proof run 41747712232: success; merged as a declared fix for incident #3545).Cause: the duplicate-resume loser's inactive
abort()awaits its own turn-temp close, but the worker's exit handler had already started a background close. When that background close was refused, its memo reset and the abort's close became a second attempt (closes === 2). Inactive abort and startup failure now claim the close before they kill the worker, so an exit-driven close no longer competes with an awaited one. Before: 5/30 failing on main; after: 50/50 passing; mutation (abort's claim removed): 7/30 failing onPI_DUPLICATE_RESUME_LOSER_CLOSED_BEFORE_REFUSAL.Main CI on
53b862123is still running at the time of writing; red-main incident #3545 remains open pending its own fix.