Repository navigation
Description
Context
Observed while auditing the other synchronous disposal sites for #2880 on main 541b8d98328a760290ac6dd4a7f065af76153408.
createSessionPool.acquire opens a resumed pi worker before checking whether another acquisition has registered the same session. In that race it calls synchronous disposeSession(opened.session) and immediately returns the existing entry or throws BackendBusyError (packages/ui-backend-pi/src/session-pool.ts:85-94). The duplicate new-session identity branch has the same shape (packages/ui-backend-pi/src/session-pool.ts:104-116), though production-generated new identities are unique. The helper only invokes dispose() (packages/ui-backend-pi/src/session-pool.ts:158-164 on that main); production disposal ends stdin and requests a kill without awaiting exit (packages/ui-backend-pi/src/worker-session.ts:766 on that main).
The #2863 lifecycle ruling now requires lifecycle completion to await worker stdio release within its existing bound. #2880 covers accepted cancellation before prompt; the concurrent duplicate-acquisition branch is a separate non-cancellation owner and remains unchanged there.
This is a source observation, not a runtime reproduction. The spike establishes whether a concurrent real resumed acquisition can reach this branch through supported consumers, and specifies the losing worker’s awaited owner under the existing lifecycle ruling if it can.
Out of scope
- The cancellation paths fixed in backends: a pi turn cancelled before its prompt reports done before its worker exits #2880.
- Changing public synchronous disposal, worker protocols, or release/cleanup bounds.
Scope
Reproduce and scope duplicate acquired-worker teardown ownership, preserving the running session and busy-turn behavior.
Acceptance criteria
- Produce a controlled concurrent-acquisition runtime receipt with distinct owned workers through supported callers, or a source-bound explanation of why the branch is unreachable for production worker-backed sessions.
- Identify the losing worker’s actual acquisition/return/refusal, exit, turn-temp and bounded stdio-release boundaries without terminating or changing the winning session.
- If a repair is needed, deliver a separately implementable handoff under the existing ui-sdk: agent turns and streaming maintenance settle without awaiting worker stdio release #2863 lifecycle ruling, with a named failing-first/mutation plan and unchanged public disposal/busy/result contracts. A justified negative reachability result is valid completion of this spike; no implementation is required by this issue.
Verification
Use keyless real workers, assert that only the losing worker is terminated, and preserve the winning session's normal result. Compare completion against worker exit, awaited turn-temp cleanup, and bounded stdio release.
Contract impact
Expected to be none; confirm during scoping. Keep existing cancellation/result and busy-refusal shapes.
Bounded investigation deliverable
Deliver a source-bound reachability/lifecycle report, not an assumed production repair. Trace the supported createPiBackend/startTurn callers into createSessionPool.acquire on current main; accepted cancellation now awaits teardown under merged #2880/#2929, while duplicate losing-worker disposal remains synchronous. Use two distinct owned workers and controlled acquisition gates to determine whether a concurrent real resumed acquisition reaches the losing branch before it returns/refuses. Record winner and loser identities, entry ownership, exit, turn-temp completion and bounded stdio release. A fake session returning a duplicate ID alone does not prove production reachability.
If reachable, specify the narrow awaited losing-worker owner required by the existing #2863 lifecycle ruling, preserving the winner and busy/refusal/result shapes, and file a separately complete implementation handoff with a failing-first/mutation plan. If unreachable through supported worker-backed callers, a documented negative result with exact source/call-path evidence is a valid outcome. Do not change public synchronous disposal or implement a general session-pool redesign in this spike.
Current pointers: duplicate resumed/new branches (packages/ui-backend-pi/src/session-pool.ts:86-118), disposeSession (same file:169-175), and the supported turn’s awaited acquisition (createPiTurnRunner, packages/ui-backend-pi/src/turn-runner.ts:39-79). Verify the final current anchors before using the historical line numbers above.
2026-10-25 triage at main dcd3b336dbade5e29e8a131eeeb5a0d9cffe60ff: Scoped the actual reachability/ownership investigation with inputs, bounded real-worker controls and a valid documented negative outcome. The #2863 lifecycle policy is already settled; this spike gathers the missing production-path evidence before a separate repair. p2 records wanted unscheduled work; no runtime reproduction or fix is invented.
Activity
schlessera commentedon Oct 25, 2026
2026-10-25 triage at main
dcd3b336dbade5e29e8a131eeeb5a0d9cffe60ff: Scoped the actual reachability/ownership investigation with inputs, bounded real-worker controls and a valid documented negative outcome. The #2863 lifecycle policy is already settled; this spike gathers the missing production-path evidence before a separate repair. p2 records wanted unscheduled work; no runtime reproduction or fix is invented.schlessera commentedon Nov 3, 2026
Claiming for the reachability spike (claim token
wi-2918-bde6), branchspike/2918-duplicate-pi-worker-teardownfrom mainadf371ffa. Collision scan of the cited sources: closure-level overlap only with open PRs #3056, #3059, #3069, #3116, #3293, #3336, #3342 (shared test closures, no direct path edits).schlessera commentedon Nov 3, 2026
Spike outcome (draft #3492, head
cb117866): reachable through the publiccreatePiBackend().startTurnwith two concurrent resumes of one non-resident session, each owning a real worker. ui-server's coordinator cannot reach it. The new-session branch is unreachable in production. At the loser'sBackendBusyError, its worker had not exited, its turn temp was not closed and its stdio release was not awaited. The winner was untouched and returned its normalsuccess. The report isdocs/investigations/duplicate-pi-worker-acquisition.md, and the awaited-teardown repair is handed off as #3488 with a failing-first and mutation plan. Contract impact: none. #3492 is still a draft and is not yet confirmed or merged.docs(backends): report duplicate pi worker acquisition reachability (#…