Skip to content

backends: a pi duplicate-resume loser's turn temp is sometimes closed twice, failing PI_DUPLICATE_RESUME_LOSER_CLOSED_BEFORE_REFUSAL #3544

Closed

Description

@schlessera

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:

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

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/main

Contract impact

None.

Activity

  1. added this to the 0.45.0 milestone on Nov 3, 2026
  2. added
    type: fixSomething is broken and must behave the way it is documented.
    area: backendsAgentBackend implementations and the seam they share.
    priority: p2Wanted, not scheduled. Pulled in when a milestone has room.
    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.
    priority: p1Scheduled into the current or next milestone.
    and removed
    priority: p2Wanted, not scheduled. Pulled in when a milestone has room.
    on Nov 3, 2026
  3. self-assigned this
    on Nov 3, 2026
  4. schlessera commented on Nov 4, 2026

    @schlessera
    OwnerAuthor

    Claiming (token c3544-d542), branch fix/3544-pi-duplicate-loser-close. Raised to priority: p1: this flake blocks ready-candidate proof for #3517 (epic #1849), and a blocker carries at least the priority of what it blocks.

  5. schlessera commented on Nov 4, 2026

    @schlessera
    OwnerAuthor

    Another hosted occurrence, 2026-11-04. Ready-candidate proof for #3546 (head 46837b60b, base 9805f52fd), run https://github.com/schlessera/brain-kit/actions/runs/41744666881, job unit (4). It failed duplicate-acquisition.test.ts:135 (PI_DUPLICATE_RESUME_LOSER_CLOSED_BEFORE_REFUSAL, expected 1, received 2). #3546 changes only packages/ui-sdk/tests/worker-var-sockets.test.ts and 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.

  6. schlessera commented on Nov 4, 2026

    @schlessera
    OwnerAuthor

    Fixed by #3547, squash-merged as 53b862123 on 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 on PI_DUPLICATE_RESUME_LOSER_CLOSED_BEFORE_REFUSAL.

    Main CI on 53b862123 is still running at the time of writing; red-main incident #3545 remains open pending its own fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.area: backendsAgentBackend implementations and the seam they share.priority: p1Scheduled into the current or next milestone.type: fixSomething is broken and must behave the way it is documented.

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions