Repository navigation
fix(server): settle a turn when its provider session closes - #16181
Adamulek123 wants to merge 2 commits into
Conversation
Closing a session with a live turn left the run unsettled: three of the four adapters emitted nothing at all, and Pi had no code path that emits turn.terminal during teardown. This is the adapter-side closure of the gap named in pingdotgg#15197, where a provider "returns success without emitting turn.terminal". pingdotgg#15298 owns the Stop half; this does not depend on it — RunExecutionService already guards on rootRunFinalized, so a late terminal cannot settle a run twice. OpenCodeAdapterV2's message-cache deletion is deliberately NOT here; it belongs to the reclamation branch and would otherwise collide.
f4843fa to
1e39859
Compare
|
Closing this draft: the adapter teardown terminals do not reach managed run subscribers, so it does not deliver the durable settlement promised in its title and description. The blocking reason. I confirmed this ordering is pre-existing on Two adapter-level defects found in review, kept here for whoever picks this up:
The tests do not prove what the body claims. Every adapter test collects via Overlap is heavier than I originally described. #15307 was closed and replaced by #15776 for stream-end settlement. #15298 was closed as superseded by merged #15442, which handles Stop recovery via Open question for maintainers, since I would rather ask than guess: is an observable terminal-on-session-close contract wanted beyond #15776 and #15442? If yes, the right starting point is a failing managed-session-to-SQLite regression plus an explicit decision about shutdown and restart semantics, not another four-adapter emission patch. Findings preserved in the audit notes and in issue #15197, which remains open. |
|
Closed per the review above. Reopen if a maintainer wants the terminal-on-session-close contract pursued with a managed-session persistence regression. |
Problem
When a provider session is closed while a turn is still live, the run is left unsettled. Closing a session emitted nothing at all from three of the four V2 adapters, and Pi had no code path that emits
turn.terminalduring teardown. The turn stays open in the UI indefinitely, with no terminal status and no way to close it out.This is the adapter-side closure of the gap named in #15197 ("provider returns success without emitting
turn.terminal"). #15298 owns the Stop half; this does not depend on it, becauseRunExecutionServicealready guards onrootRunFinalized, so a late terminal cannot settle a run twice.Change
Each of the four V2 adapters now emits a terminal event when its session closes with a live turn, so the run reaches a durable terminal state instead of hanging:
CursorAdapterV2-- emits for the open turn.OpenCodeAdapterV2-- emits for the open turn.OpenCode2AdapterV2-- emits for the open turn.PiAdapterV2-- adds the teardown emission it previously lacked.Terminal-on-close was deliberately split out of #15767. That PR reduces whole-text emissions while coalescing streamed deltas, and a session-close terminal is a lifecycle decision rather than a coalescing one. #15767 keeps only the part that is the coalescer's: a session that closes mid-response still projects what it buffered, but does not settle.
OpenCodeAdapterV2's message-cache deletion is also not here. It belongs to #15760, and keeping it out avoids a conflict.Scope and approval
Follow-up to the adapter audit of #2829, and a direct implementation of the adapter-side gap in #15197. This is one underlying problem -- "a closed provider session leaves its turn unsettled" -- across the four adapters that share the teardown path.
Verification
Focused adapter tests, run in
apps/server:vp test runoverCursorAdapterV2.test.ts,OpenCodeAdapterV2.test.ts,OpenCode2AdapterV2.test.ts,PiAdapterV2.test.ts-- 193 passed, 0 failed.vp run typecheckinapps/server-- exit 0.vp lint --report-unused-disable-directives apps/server/src/orchestration-v2/Adapters-- exit 0 (existing warnings only, none in changed lines).Each adapter gained coverage asserting that closing a session with a live turn produces exactly one terminal event, and that it does not double-settle.
Not checked: end-to-end behavior against live provider CLIs, and multi-device relay.
Model and harness:
opencode/space-bunny-freein T3 Code (OpenCode harness), on top of the #2829 adapter audit.