Repository navigation
fix(daemon): keep agent-completion detection alive on pre-v27 daemons - #10478
Merged
Merged
Conversation
DaemonPtyAdapter.inspectProcess() threw terminal_liveness_unavailable when the connected daemon predated protocol v27. The intended provider-level fallback only fires when a provider lacks inspectProcess, so for the daemon adapter the throw propagated: agent-completion-coordinator swallowed it into consecutiveInspectionErrors and retried forever, killing process-exit completions and pending-title validation. Daemons intentionally survive app updates, so updating in place with agent terminals open routes those PTYs to a legacy adapter and permanently disables agent-finished notifications until the terminal is recreated. Compose the inspection client-side from getForegroundProcess, which v26 fully supports. No new wire traffic and no new daemon capability.
Contributor
📝 WalkthroughWalkthrough
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 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 |
…llback The legacy composition had no coverage for a null foreground, which is the one daemon response shape whose semantics diverge from v27: there inspectProcess goes through getAliveSession() and throws for a vanished session, while getForegroundProcess is deliberately null-not-throw. It is also the only shape that reaches a user-visible completion, so reading it as idle is a deliberate choice that should not change silently.
enrick-dev
pushed a commit
to enrick-dev/orca
that referenced
this pull request
Oct 15, 2026
…stablyai#10478) * fix(daemon): keep agent-completion detection alive on pre-v27 daemons DaemonPtyAdapter.inspectProcess() threw terminal_liveness_unavailable when the connected daemon predated protocol v27. The intended provider-level fallback only fires when a provider lacks inspectProcess, so for the daemon adapter the throw propagated: agent-completion-coordinator swallowed it into consecutiveInspectionErrors and retried forever, killing process-exit completions and pending-title validation. Daemons intentionally survive app updates, so updating in place with agent terminals open routes those PTYs to a legacy adapter and permanently disables agent-finished notifications until the terminal is recreated. Compose the inspection client-side from getForegroundProcess, which v26 fully supports. No new wire traffic and no new daemon capability. * test(daemon): pin null-foreground semantics on the pre-v27 inspect fallback The legacy composition had no coverage for a null foreground, which is the one daemon response shape whose semantics diverge from v27: there inspectProcess goes through getAliveSession() and throws for a vanished session, while getForegroundProcess is deliberately null-not-throw. It is also the only shape that reaches a user-visible completion, so reading it as idle is a deliberate choice that should not change silently.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Agent-finished notifications and title-driven agent status stayed permanently dead for any user who updated in place to 1.4.156 while agent terminals were open. Daemons deliberately survive app updates (
PREVIOUS_DAEMON_PROTOCOL_VERSIONSspans v1–v27), so those PTYs keep routing through a pre-v27 adapter — andDaemonPtyAdapter.inspectProcess()threw instead of answering:src/main/daemon/daemon-pty-adapter.ts:830-832— threwterminal_liveness_unavailablewhenprotocolVersion < COMPLETION_PROCESS_INSPECTION_PROTOCOL_VERSION(27).src/main/providers/pty-process-inspection.ts:19-25— the intended fallback only fires when a provider lacksinspectProcess.DaemonPtyAdapteralways defines it (andDaemonPtyRouter:192/DegradedDaemonPtyProvider:156both delegate to it), so the fallback was unreachable and the throw propagated.src/renderer/src/components/terminal-pane/agent-completion-coordinator.ts:560-563— swallows it intoconsecutiveInspectionErrors;:635-639caps backoff at ~10s, so it retried forever and never recovered.Consequences for affected users: process-exit completions never dispatched (
:509-518), and pending-title validation took the!inspectionSucceeded -> dropPendingTitle()path (:579-581). Both stayed broken until the terminal was recreated. The same code is reached by theterminal.inspectProcessRPC (src/main/ipc/pty.ts:3806) and thepty:inspectProcessIPC handler (:5393), so paired/mobile viewers lost it too.Fix: when
protocolVersion < 27, compose the inspection client-side instead of throwing.hasChildProcesseswas already derived client-side fromgetForegroundProcess— which v26 fully supports — so the predicate is now shared viahasChildProcessesFromForegroundand the two paths cannot drift. No new wire traffic, no new daemon capability, no behavior change for v27+.One deliberate deviation from the obvious composition: it issues the
getForegroundProcessRPC directly rather than callingthis.getForegroundProcess(). That wrapper swallows RPC errors intonull(:852-862), andhasChildProcessesis exactly the guard the coordinator uses at:493to suppress spurious completions. Composing through the swallowing wrapper would make a dropped daemon socket read as "idle foreground" and, after two samples, dispatch a false agent-finished completion — the mirror of the bug being fixed. Requesting directly preserves v27's semantics: transport failure rejects (client.ts:196-207throws on bothNot connectedand timeout) and the coordinator's error backoff handles it. A regression test pins this.Screenshots
No visual change.
Testing
pnpm lint— clean (full&&chain throughverify:localization-coverage).pnpm typecheck— clean (all three tsconfig projects).pnpm test— ran the affected suites, not the full repo suite (CI covers that):daemon-pty-adapter114 passed;daemon-pty-router+degraded-daemon-pty-provider+daemon-protocol-version+pty-process-inspection+terminal-host79 passed;agent-completion-coordinator69 passed.pnpm build— not run locally; no build-surface change (no new deps, no config or native-module change).The new tests were verified to genuinely fail without the source change by reverting only
daemon-pty-adapter.tstoorigin/mainand re-running: 4 of the 5 fail withError: terminal_liveness_unavailable(andexpected 'socket_closed' … got 'terminal_liveness_unavailable'). The 5th asserts v27+ still delegates to the daemon RPC — it passes either way by design, guarding the version boundary against a future widening of the gate.New tests cover: composition returns a real inspection on v26; an idle shell reports
hasChildProcesses: false; a null foreground reads as idle (added in review — this is the one response shape whose semantics diverge from v27, and the only one that reaches a user-visible completion, so the deliberate choice is now pinned); a failing daemon call rejects rather than reading as idle; and v27+ still delegates toinspectProcess.AI Review Report
Reviewed by three independent subagents (correctness/coverage, tests/perf, adversarial) plus direct verification. All three returned CONFIRM land-ready; the one actionable finding (the null-foreground test gap) is fixed in this PR. Risks checked and outcomes:
inspectProcess. Both entry points (ipc/pty.ts:3806runtime RPC,:5393IPC handler) go throughinspectPtyProviderProcess(getProviderForPty(...)), andDaemonPtyRouter.adapterForInspection(:357-366) resolves to the session-owning adapter — which is exactly the legacy adapter in the bug scenario.DegradedDaemonPtyProvider:156delegates likewise. A third route also exists and is likewise fixed:runtime/rpc/methods/terminal.ts:1165-1170→orca-runtime.ts:15821-15833callsptyController.inspectProcessdirectly. That one is worth calling out because:15828checks the method's existence, not its success, so pre-v27 it invoked the adapter, ate the throw, and never reached its own composition at:15831-15832— meaning the mobile/relay/webterminal.inspectProcesspath was equally dead and is unwedged by this change. No route still reaches the throw.adapterForInspection(:357-366) has no fallback tothis.current, unlikeadapterFor(:353-355); it throwsterminal_gone. So there is no "wrong adapter answers null → false completion" case.terminal_liveness_unavailable. The other producers (orca-runtime.tsliveness/sleep flows,remote-worktree-sleep.ts:55,web-preload-api.ts:2944) come fromrefreshPtyWorktreeRecordsFromController, an unrelated path; that code is not orphaned.hasChildProcessescorrectness — matches the v27 daemon-side derivation exactly:terminal-host.ts:150-159computesforegroundProcess !== null && !isShellProcess(foregroundProcess), identical to the shared client-side predicate.getForegroundProcessfrom the samesession.getForegroundProcess()call that v27'sinspectProcessuses (daemon-server.ts:916-921→terminal-host.ts→session.ts:454→pty-subprocess.ts:998, a synchronous read of node-pty's.processplus a TTL-cached agent foreground; the heavyps/PowerShell-CIM scan is scheduled out-of-band and throttled to ≤1/s per session, so there is no/procwalk or subprocess spawn on the request path). Per-call daemon cost is therefore identical to v27.hasChildProcesses()is not called on the same tick asinspectProcess(), so this is not 2 RPCs where there was 1. Absolute rates per terminal: ~80 RPC/min worst case in the active tier (750ms), 30 idle, 20 hidden, 4 no-evidence — under an app-wide ceiling ofMAX_INSPECTION_STARTS_PER_SECOND = 8/MAX_CONCURRENT_INSPECTIONS = 4(agent-process-inspection-queue.ts:8-9) = 480 RPC/min regardless of terminal count. Net effect is that affected terminals resume the intended cadence instead of sitting in a 10s error-backoff loop making ~6 futile attempts/min and detecting nothing — that is the feature working, not fix overhead, and it costs no more than a healthy v27 daemon.isShellProcess(src/shared/shell-process-detection.ts), already normalizes Windows.exebasenames, and it is the same helper the v27 daemon path uses, so both paths behave identically on all three platforms. SSH hosts reach inspection throughssh-pty-provider.ts:284/ the relay, not this adapter, so they are unaffected. Folder workspaces and git worktrees are equally unaffected — nothing here touches workspace shape.Security Audit
No new attack surface. No input handling, command execution, path handling, auth, secrets, or dependency changes. The one added call reuses an existing daemon RPC (
getForegroundProcess) with the same{ sessionId }payload the sibling method already sends over the same authenticated socket; no new IPC or RPC method is exposed and no handler signature changes. The change makes an error path less silent, which is the safer direction: a transport failure still rejects rather than being coerced into a benign-looking "idle" result. No follow-up needed.Notes
DaemonServerrejects a v26 handshake withProtocol version mismatch. The actual update-in-place scenario (live v26 daemon + 1.4.156 app) was not reproduced end-to-end, and the paired/mobile route viapty.ts:3806is reasoned from the call graph rather than exercised on a device.inspectProcessusesgetAliveSession(), which throws for a session the daemon no longer has;getForegroundProcessis intentionally null-not-throw (terminal-host.ts:141-148). So on the legacy path a vanished session reads as{ foregroundProcess: null, hasChildProcesses: false }where v27 would reject. This was examined closely because it is the only shape that can reach a user-visible notification, and it was judged not a reachable false completion: three independent guards would all have to fail at once — thehasPty/activeSessionIdspre-check throwingterminal_gone(pty-process-inspection.ts:16-18,daemon-pty-adapter.ts:595-597), the runtime route's stale-handle rejection (orca-runtime.ts:9667-9672), and the coordinator's requirement of two consecutive idle samples with a matching agent identity (:499-508). The only window is between the daemon dropping the session and the exit event retiring the pane, and that event arrives on the same connection that just answered, so by sample Fix Ctrl+Backspace not deleting word in terminal #2options.isLive()is false and polling has stopped (:531,:645). Hardening it further would also buy nothing actionable: thehasChildProcessesguard at:493is already a no-op for every daemon-backed PTY including v27, becauseterminal-host.ts:157derives it from the same foreground string and so can never betruewhen the foreground is null or a shell — only relay/local providers do a real child check (relay/pty-handler.ts:1404). Spending a second RPC on a 750ms poll to recover a distinction the coordinator cannot act on, inside a window the exit event already closes, is a bad trade. A regression test now pins the chosen semantics.getForegroundProcessRPC only landed atPROTOCOL_VERSION = 11(commit519a120828) whilePREVIOUS_DAEMON_PROTOCOL_VERSIONSreaches back to v1, so a v1–v10 daemon rejects withUnknown request type(daemon-server.ts:1029→ok: false→client.ts:421-425). That is behaviorally identical to the pre-fix throw, so it is a strict non-regression, and such daemons predate this fallback's target window anyway.7ab601487c— "fix(remote): don't classify a stale/gone remote handle as agent completion (fix(remote): don't classify a stale/gone remote handle as agent completion #9263)". Composing through the swallowing wrapper would undo that very fix on the legacy route. And because legacy adapters are built with norespawnclosure against a protocol-specific socket path (daemon-init.ts:1063-1071), a dead legacy daemon stays dead — so the wrapper would mark every pane on it agent-finished, not just one.