Repository navigation
fix(native-chat): settle structured chat turns stranded by a restart - #19122
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (7)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe changes add deterministic settlement retry state for evicted agent sessions and support the Merge Risk: ⚪ Minimal · up to This change restores chats whose provider process died during streaming by settling the interrupted turn at restart, returning the chat to an editable, sendable state. The supplied coverage indicates no remaining concrete merge-blocking risk. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description gives a detailed, relevant explanation of the bug, root cause, fix, safety conditions, tests, and scope. However, it omits most required template sections, including the linked issue, visual proof or an explicit N/A statement, structured testing details, AI disclosure, review, boundary confirmation, notes, and checklist. Resolution Complete the required template sections. Add the issue reference after ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 43525c09-2857-4747-89b9-72e21d8f8df3
📒 Files selected for processing (16)
src/main/native-chat/agent-session-wire/structured-agent-session-host.tssrc/main/native-chat/agent-session-wire/structured-agent-session-readable-restorer.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-readable-restorer.tssrc/main/native-chat/agent-session-wire/structured-agent-session-restart-restore.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-restart-restore.tssrc/main/native-chat/agent-session-wire/structured-agent-session-reveal.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-reveal.tssrc/main/native-chat/agent-session-wire/structured-agent-session-turns.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-turns.tssrc/main/native-chat/agent-session-wire/structured-agent-session-unexpected-exit.tssrc/main/native-chat/agent-session-wire/structured-agent-session-wedged-profile-migration.test.tssrc/main/runtime/agent-session-eviction-settlement-latch.test.tssrc/main/runtime/agent-session-lease-transitions.tssrc/main/runtime/agent-session-restart-handoff-adjudication.tssrc/main/runtime/agent-session-restart-lease-transitions.tssrc/shared/agent-session-lease-adjudication.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
There was a problem hiding this comment.
Important
One correctness concern in the performCancel change: { cancelled: false } is not uniformly "already finished", so tombstoning the running lifecycle row on that signal can clear a turn that is still executing. Details inline.
Reviewed changes
The PR adds a durable "settlement latch" (settlementRetryRequired + settlementRetryId) to every proven-death eviction, adjudicates that latch to a new settlement-pending disposition (instead of recovering, which made the lease permanently un-openable), and triggers the existing provider-agnostic settlement at boot and on attach rather than only on an observed provider exit. It also changes performCancel to tombstone a dangling running-turn row instead of appending an unbounded status note per Stop click.
- Eviction latch —
evictAgentSessionOwnerand theevictedrestart disposition now setsettlementRetryRequired/settlementRetryId(a stablerestart-eviction:<sessionId>:<nextFence>id) on proven death (exit-observed/pid-absent/identity-mismatch), whileindeterminateprobes still route torecoveringand are never settled. settlement-pendingdisposition — replaces the oldrecoveringverdict for a surviving latch, keeping the handoff stage null so the lease stays openable through the hold path.- Boot-time settle —
createStructuredAgentSessionHostRestorenow wiresretrySettlementinto the readable restorer, sorestoreOneStructuredAgentSessionReadsettles latched journals betweenonReadableandrestoreHandoff. - Stop settles —
performCanceltombstones the running turn-lifecycle row (reusing the newrunningTurnLifecycleTombstoneMutations) when the adapter reports{ cancelled: false }. - Tests — 43 new/updated assertions, including a wedged-profile migration test across both providers, an idempotency check, and latch coverage for both eviction sites.
ℹ️ Nitpicks
- The
settlement-pendingbranch added toadjudicateRestartedAgentSessionHandoff(agent-session-restart-handoff-adjudication.ts) appears unreachable: that function only runs forpreparing/new-owner-provingleases, and both paths clearsettlementRetryRequiredat reservation time, soadjudicateAgentSessionRestartcannot returnsettlement-pendingthere. It's harmless and consistent with the sibling handler, but it's dead code with no test coverage — consider dropping it or noting the intent. - The boot/attach settle surfaces raw host-probe text as a user-visible chat line:
retryPendingStructuredAgentSessionSettlementfeedsdeathEvidence?.detailintounexpectedExitFallbackMutations, which always appendsProvider exited: <detail>. For the new restart-eviction trigger that'srecorded pid absent on host/mismatched process-start-time, and it's emitted even when no turn was actually running (an idle chat killed bykill -9). The wording is more appropriate for an internal log than a chat transcript.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
The new commit reverts the performCancel stop-tombstone sub-feature in response to the prior correctness concern; the boot/attach settlement repair is untouched.
- Reverted
performCanceltombstone —{ cancelled: false }no longer infers "already finished" or clears the running lifecycle row;performCancelreturns to base behavior (appendStatus(ctx, input.clientOperationId, note)). Provider completion and proven-death eviction remain the only authorities that settle a running turn. - Re-inlined the running-turn tombstone —
runningTurnLifecycleTombstoneMutationswas removed and its logic folded back intounexpectedExitFallbackMutations, which still tombstones running status rows during the boot/attach settle. - Adjusted tests — dropped the "settles an already-finished turn" case and restored the "leaves the running lifecycle row intact" assertion for the confirmed-cancel path.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
The two new commits add regression coverage that locks in the reverted cancellation behavior.
- Added unconfirmed-cancel coverage —
keeps the running lifecycle when cancellation cannot be confirmedseeds arunninglifecycle row, drivesperformCancelthrough an adapter returning{ cancelled: false }, and asserts the row survives untouched while only the status note is appended. The exact-array assertion would fail if the prior tombstone behavior were reintroduced.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Electron red/green QA (structured native chat recovery)Scope: desktop Electron CDP only ( Commits
Scenario: New tab → Codex structured chat → send a long counting turn while streaming ( Red (baseline after kill + relaunch)
Green (same profile on
|
…ed-chat-restore-settle-2
…ed-chat-restore-settle-2
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
The new commit narrows the settlement latch so only proven-death evictions trigger the boot-time settle, keeping intentional chat closes out of it.
- Gated settlement latch on eviction reason —
evictAgentSessionOwnernow takes a requiredjournalSettlement: 'required' | 'not-required'flag; the intentional-close path (closeRetainedTuiOwner) passes'not-required', while the proven-death paths (recoverDeadTuiOwnerForHandoff,evictProvenDeadOwner) pass'required'. - Regression test for intentional close — new
structured-agent-session-handoff-owner-close.test.tsasserts an intentional TUI close leavessettlementRetryRequired/settlementRetryIdunset, and the existing latch test pins'required'for the proven-death evictions.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
The new commit ee4e45a is a pure Merge remote-tracking branch 'origin/main' — no PR-authored code changes. All 37 files it carries are main's orthogonal work (branch-rename hook, reliability-gate contracts, the status-feed onSessionStatusChanged feature). The only PR-authored files it touches are structured-agent-session-host.ts / structured-agent-session-host-types.ts, and the PR's settlement wiring (the createStructuredAgentSessionHostRestore(deps, this.sessions, () => this.now(), …) signature) survives intact with no conflict-resolution logic. The settlement latch and journalSettlement gating reviewed at 7d6bb74 are unchanged.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…ed-chat-restore-settle-2
…ed-chat-restore-settle-2
Review status for PR 19122Status: ready from this review pass. I reviewed the actual PR diff through pushed head What changed during the review loop:
Readiness checklist:
Same-model review loop: the same-model/same-thinking loop found and drove the two handoff/settlement fixes above, then returned QA and verification:
Deferred item, intentionally not fixed here: repeated Stop clicks still append one status row per click while the lifecycle stays running, because each click has a fresh Branch update note: the branch was repeatedly refreshed from main and exact-head CI stayed green after each final update. During the last exact-head matrix, main landed five additional unrelated commits, so the PR currently reports 5 behind while remaining mergeable/clean; the validated head includes main through |
…ed-chat-restore-settle-2
…ed-chat-restore-settle-2
There was a problem hiding this comment.
Important
This delta regresses the observed-exit settlement path: the settle no longer clears handoffStage, so a session whose surface-release settlement previously failed can never re-attach. See the inline comment and the failing test.
Reviewed changes
- Settle before reacquire on the dead-TUI handoff path —
handoffStructuredSessionToNativenow calls the newretryPendingSettlementdep wheneverrecord.lease.settlementRetryRequiredis set, so a strandedturnLifecycle{running}row is tombstoned before a native owner is reserved. - Extracted
retryLoadedStructuredAgentSessionSettlement— the shared settle logic now takes a loaded session (journal/fence/acquisitionGeneration) instead of the full host deps, so the boot/attach settle and the handoff settle reuse one path;retryUnexpectedExitSettlementandunexpectedExitFallbackMutationswere narrowed to the fields they actually use. - New regression test —
structured-agent-session-proven-dead-retry.test.tsdrives apid-absentdead-TUI handoff retry and asserts the running turn is settled and the latch cleared without re-closing the dead owner.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Preserved the handoff stage in the settle —
retryLoadedStructuredAgentSessionSettlementnow keepsold-owner-stopped(and itshandoffOperationId) when a dead-TUI handoff retry settles, while clearing recovery stages (recovering) back tonull, which fixes the observed-exit re-attach regression from the previous round. - Re-targeted the observed-exit regression test —
structured-agent-session-wedged-profile-migration.test.tsnow driveshost.attachdirectly (rather than the boot sweep plus hold) so it exercises the exact attach path that regressed.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…ed-chat-restore-settle-2
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
The new commit d20b4a5eb is a pure Merge remote-tracking branch 'origin/main' — no PR-authored code changed. The delta against the prior pullfrog review carries only main's orthogonal work and leaves the PR's 28 settlement files untouched, with no conflict-resolution logic.
- Merge of
origin/main— brings in browser-client host attach adoption, pane-manager / terminal-webgl hidden-retention, and thepaired-cmd-j/floating-workspacee2e specs (10 files), all orthogonal to the settlement latch and boot/attach + handoff settle paths.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…ed-chat-restore-settle-2
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
The new commit 27e6338 is a pure Merge remote-tracking branch 'origin/main' — no PR-authored code changed. It carries a single main-side commit, 1e301ab ("test: cover native Wayland Hangul in isolated CI (#19174)"), whose seven files (the terminal-ime-e2e workflow, run-terminal-ibus-hangul-e2e.mjs, focus-nested-wayland-terminal.sh, a reliability-gate entry, pr-e2e-source-routing.mjs, terminal-ime-e2e-workflow.test.mjs, and a Hangul e2e spec) are all CI/test infrastructure orthogonal to the settlement work.
- Merge of
origin/main— brings only Wayland Hangul terminal-IME e2e CI from main; none of the 28 PR settlement files are touched and there is no conflict-resolution logic, so the settlement latch,journalSettlementgating, boot/attach settle, and dead-TUI handoff settle paths remain exactly as previously reviewed.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…tablyai#19122) * fix: settle structured chat turns after restart * fix: preserve unconfirmed turn cancellation state * test: preserve unconfirmed turn lifecycle * test: narrow unconfirmed cancellation coverage * fix: keep intentional TUI closes out of recovery * test: keep branch rename journal mock current * fix: settle dead TUI handoffs before reacquire * fix: preserve handoff stage after retry settlement --------- Co-authored-by: Merge Sim <sim@local>



The bug
Kill Orca while a structured chat turn is streaming and the chat is permanently unusable. It comes back with a spinner, a Stop button, and no send button — you cannot type in it again. The only escape is closing the tab and losing the conversation.
Measured on
main, for both Codex and Claude:turnLifecycle{running}turnLifecycle{running}kill -9This also breaks Resume from Agent Session History: the tab comes back, but the chat it returns is wedged.
Root cause
Settlement runs on the way out, and the shutdown path is explicitly abandonable. A turn interrupted by a kill leaves a
turnLifecycle{state:'running'}row that nothing closes, and the projection reads it as "still working" forever.Verified: a later graceful shutdown appends zero rows, because exit settlement only settles turns a live session knows about. So no exit-path work can ever repair an already-stranded row — the repair has to happen on the way in.
The fix — trigger the settle that already exists
The repair itself is already implemented and provider-agnostic (
unexpectedExitFallbackMutations/retryPendingStructuredAgentSessionSettlement). It only ran on an observed provider exit, which by definition never happens when Orca itself is killed. This adds the missing trigger:settlementRetryRequiredand a stablesettlementRetryId(restart-eviction:<sessionId>:<fence>). Latching only the boolean would have been a silent no-op: the retry short-circuits unless both are present.settlement-pendingdisposition — a settlement latch previously adjudicated torecovering, which sets a handoff stage that makes the session permanently un-openable through the hold path. This keeps the stage null. It also repairs that pre-existing trap for the observed-exit latch.Safety
Settles only on proven death evidence (
exit-observed/pid-absent/identity-mismatch). Anindeterminateprobe routes to recovering and is never settled — loss of contact is not proof of death, which keeps this correct for remote and SSH-hosted sessions.Tests
Focused validation after review covers 12 affected and neighboring test files, including the wedged-profile migration for both providers, eviction-latch safety, idempotent settlement, observed-exit retry, recovery, and surface-lifetime coverage.
pnpm tc:node,oxlint, and the changed-code quality gate are clean.Scope
Deliberately excluded: the liveness gate on status projection, the interrupted-state UI copy, and the quit/update deadline ordering — each is its own PR.