Repository navigation
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:
📝 WalkthroughWalkthroughUpdated terminal and session-tab close flows to carry explicit reasons and user-origin metadata. PTY-exit and cleanup echoes can be refused when live runtime PTYs remain, while dead headless tabs are retired and user or legacy closes remain destructive. Added close-reason RPC schemas, runtime adjudication tests, and daemon kill intent handling that refuses automatic kills for live non-shell foreground processes. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
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 |
e57bfc0 to
ac9fa1b
Compare
8fbb81a to
32abe4a
Compare
|
Rework note — the branch was force-pushed with a full reimplementation (old approach: client-side close-intent recording; it left the host unable to adjudicate and, as later analysis showed, could not distinguish a transport-artifact echo from a genuine exit host-side). Key changes vs. the original:
Part of #9414; complements #8888 (attribution) and the lifecycle-state follow-up. |
32abe4a to
857c082
Compare
|
Rebased onto latest
|
PR #8872 Windows/WSL red-green audit: refused-close reconciliation candidateAudit date: 2026-07-19 (America/Vancouver) OutcomePASS. The candidate fixes the acceptance failure observed at No stale, disconnected, expired, ambiguous, or ownership-mismatched action killed a Preserved RED baselineThe two prior reports remain unchanged:
Preservation hashes:
Candidate implementationFiles changed from
Explicit successful closes retain the existing optimistic suppression path. No global Environment and exact builds
Build commands on both Windows and WSL: Live topology:
Primary acceptance flowAuthoritative identifiers:
Exact steps and evidence:
Result: PASS. The lifecycle/stale action was non-destructive, the authoritative Remaining live matrix
Final cleanup at Close counts and source interpretation
Automated verification
Artifacts
Evidence classification and gaps
|
5533a29 to
bb69fac
Compare
|
@OrcaWin The PR is now rebased onto current main at bb69fac775. The prior Windows/WSL PASS belonged to the old head and is no longer valid; could you please rerun the native Windows and WSL checks on this updated head? Local focused tests, root/mobile typechecks, lint/format, max-lines, and the independent spec gate are green. |
|
Related to #9952 (sessions vanishing over remote Orca link). |
… live
The daemon kill request gains an optional intent field ('auto' | 'user').
When intent is 'auto' and the session's foreground process is a live
non-shell process (an agent at work), the daemon refuses the kill and
answers { refused: true } instead. Missing intent keeps the legacy
unconditional kill, and old daemons ignore the extra field, so no
protocol version bump is needed.
KillRequest moves to daemon-kill-request.ts because types.ts sits at its
max-lines cap.
Give the ad-hoc { refused: true } kill reply a KillResponse type so the
lifecycle-state follow-up consumes a declared shape. Sending intent:'auto'
still requires a PROTOCOL_VERSION or handshake-capability bump first —
surviving old daemons silently ignore the guard otherwise.
|
Rebased onto current Scope after restack: main already absorbed the session-tab close-intent / Still unique and kept (3 commits):
ahead=3 behind=0. Kill-request tests green. |
bb69fac to
c85c636
Compare
Closing original close-intent / host-adjudication scope as supersededThe original problem — host cannot distinguish user vs lifecycle closes, and must refuse destructive closes against still-live PTYs — is landed on main via:
Main also early-returns remote Residual unique work (not closed as “done forever”)The current tip of this branch is already narrow (~daemon only):
That residual is not on main. If we still want it before any Closing as PARTIALLY SUPERSEDED (tab-close adjudication done; daemon residual optional follow-up). |
fix(runtime): typed close intent + host-side adjudication for session tab closes
Part of #9414. Reworked from this PR's original client-side approach — see the
rework comment below. The intent field is consumed by the lifecycle-state
follow-up and by #8888 attribution logging.
Problem
session.tabs.closecarried only{worktree, tabId}. The host could not tella user-initiated close from a transport-artifact echo: when a paired client
loses a mirrored PTY stream it fires
closeTerminalTab(reason: 'pty-exit'),the reason was dropped before the RPC, and
closeMobileSessionTabkilled livePTYs unconditionally. A transient transport blip could therefore terminate a
working agent on the host.
Fix
Thread a typed close reason end-to-end and make the host the sole decision
point:
session.tabs.closeparams gain an optionalreason: 'user' | 'pty-exit' | 'cleanup'(CloseTabinsession-tabs-schemas.ts). Reasonless payloads still validate.closeTerminalTabalready hadoptions.reasonlocally but dropped it; it now flows through
closeWebRuntimeSessionTabandweb-runtime-session.tsonto the RPC. Direct user actions (tab close, bulkclose, tab-group close, mirrored editor close, mobile tab close, CLI
handle-addressed close) send
reason: 'user'. Callers whose origin is notclearly a user action stay reasonless — the client never invents an
explicit-close claim.
closeMobileSessionTab, a close whose reason ispresent and not
'user'is treated as an echo, not an authorization. If anyleaf under the addressed terminal parent still resolves a connected PTY
record (
findPtyForMobileTerminalTab(...)?.connected === trueafterrefreshMobileSessionPtyRecords— record presence alone is not liveness:exited PTYs stay addressable as disconnected records in
ptysById), thehost refuses every destructive branch — direct
ptyController.kill, thewhole-parent renderer close relay, and the headless teardown/kill loop — and
returns
{ closed: true, refused: true }. Unless the echo addressed a deadleaf under a live sibling (below), it also republishes the session snapshot
with a bumped
snapshotVersionso the echoing client re-syncs andre-attaches, and marks the response with additive
{ snapshotRepublished: true }.When the PTY is genuinely dead/absent (including a retained
disconnected record), the close proceeds normally so the tab record retires —
this is what keeps headless hosts retiring dead tabs.
whose sibling PTY is live is refused (the only reachable close path for a
single leaf is the whole-parent close, which would kill the live sibling)
but not republished: re-adding the dead leaf on the echoing client would
feed an endless refuse→republish→re-echo cycle. Retiring just the dead leaf
record host-side is left to the follow-up that consumes the intent field.
{ closed: true, refused: true }; only paths that actually republish alsoreturn
snapshotRepublished: true. The renderer then clears only the targettab's alias intents and permits one replay of the exact current
epoch/version. Dead-leaf refusals retain suppression, while older concurrent
frames remain behind the monotonic gate and cannot clear unrelated intents.
Both response fields are additive and skew-safe for older clients.
closeTerminalTabgains ahostCloseReasonoption that tags the wire reason without triggering thelocal
reason === 'pty-exit'pinned-guard bypass. The parked-tab watcher'sautonomous pty-exit close now sends
hostCloseReason: 'pty-exit', sobackgrounded tabs get the same host adjudication as mounted ones while
keeping the parked pinned-tab confirmation flow.
killrequest gains an optionalintentfield.intent: 'auto'is refused (typedKillResponse{ refused: true }) while the session's foreground is a live non-shellprocess; missing intent keeps the legacy unconditional kill. Old daemons
ignore the extra field, so no protocol-version bump is required today
because no caller sends
intent: 'auto'yet. Precondition for thelifecycle-state follow-up: before any caller starts sending
intent: 'auto', bumpPROTOCOL_VERSION(or add a handshake capability) —daemons survive app updates, and without it a caller cannot distinguish
"refused" from "old daemon silently killed". (
KillRequestmoved todaemon-kill-request.tsbecausetypes.tssits at its max-lines cap.)Why the echo is preserved
The client-side echo is deliberately not suppressed. Per the comment in
terminal-tab-actions.ts: "a remote-owned worktree's tabs arehost-authoritative, so the close MUST reach the host or its next snapshot
re-adds the tab (the 'close then snaps back' bug)". Additionally, the host's
own pty-exit handling never retires tab records, so headless hosts rely on the
client echo to retire genuinely dead tabs. Safety comes from the host-side
gate, not from suppression.
Version-skew behavior
reasonstripped by the host's non-strict zod object → legacy closereason: 'user'→ destructive close (explicit intent)pty-exit/cleanup)reasonstripped → legacy close (no worse than today)Same shape for the daemon
intentfield: old daemons ignore it; new daemonsonly change behavior when
intent: 'auto'is explicitly sent.Behavior note: after a live-PTY refusal, the republished marker restores the
mirror immediately even if the same snapshot version arrived before the RPC
response. A dead-leaf refusal intentionally keeps its close intent and does not
open the replay gate, preventing the dead mirror from being re-added.
Tests
session-tabs-schemas.test.ts— close params round-trip with each reason;reasonless payload validates (skew safety); unknown reason rejected.
terminal-tab-actions.test.ts— pty-exit close still reaches the host andnow carries the reason; reasonless close stays reasonless on the wire; local
prune behavior unchanged; bulk closes send
reason: 'user';hostCloseReasonreaches the wire without tagging the local reason andwithout bypassing the pinned confirmation guard.
terminal-parked-tab-watchers.test.ts— the parked autonomous exit closecarries
hostCloseReason: 'pty-exit'.web-runtime-session.test.ts— wire-level params carry the reason and omitit when absent; only a refusal carrying
snapshotRepublishedclears thetarget close intent and opens replay recovery.
orca-runtime.test.ts(close intent adjudication) —(a)
pty-exit/cleanup+ live PTY → no kill, no renderer relay,refused: true,snapshotRepublished: true, and abumped version; (b) pty-exit +
dead headless tab → retires normally, including when the exited PTY still
has a retained disconnected record (the production state after
onPtyExit); (c)user+ live PTY → destructive (whole-parent relay anddirect split-leaf kill branches); (d) missing reason + live PTY → legacy
destructive; (e) runtime-owned headless branch refused while live; (f) dead
split leaf under a live sibling → refused without a republish (no churn
loop).
daemon-server-kill-request.test.ts—intent: 'auto'+ live non-shellforeground → refused, no subprocess kill; shell foreground → proceeds;
missing intent → legacy unconditional kill.
web-session-tabs-sync.test.ts— same-version replay remains available, oldersame-epoch frames stay rejected, and a second pending close intent survives
refusal recovery.
Verification after rebasing onto current
main: focused Vitest runs of 12files / 976 tests and the daemon + remote transport set of 3 files / 93 tests
passed; node/CLI/web and mobile TypeScript checks passed; changed-file oxlint,
type-aware lint, formatting, max-lines ratchet, and
git diff --checkpassed.Independent post-fix gate: Spec compliance PASS / Code quality APPROVED.