Repository navigation
fix(terminal): recover degraded daemon spawn routing - #12277
Conversation
📝 WalkthroughWalkthroughDegraded daemon providers route fresh PTY spawns through a fallback until a current-daemon health probe succeeds. Recovery probes use retry backoff and coalesce concurrent requests. Existing sessions retain their recorded providers. Session discovery is shared across daemon adapters. Runtime and renderer PTY spawn paths await recovery before provider selection. New-session metadata distinguishes new sessions from reattachments. Degraded status reflects active local fallback routing. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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.
🧹 Nitpick comments (1)
src/main/daemon/degraded-daemon-session-routing.ts (1)
4-17: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winRun adapter discovery concurrently to reduce startup latency.
discoverDegradedDaemonSessionsawaitsadapter.listProcesses()one adapter at a time inside the loop at line 10.daemon-init.tsawaits this function (await routedAdapter.discoverDaemonSessions()) before completing daemon initialization, so sequential RPCs add up when there is more than one adapter (current + legacy).Run the per-adapter listing concurrently, for example with
Promise.allSettled, while keeping the existing per-adapter try/catch and warning.♻️ Proposed refactor for concurrent discovery
export async function discoverDegradedDaemonSessions( adapters: readonly DaemonPtyAdapter[], sessionProviders: Map<string, IPtyProvider> ): Promise<void> { - for (const adapter of adapters) { - try { - for (const session of await adapter.listProcesses()) { - sessionProviders.set(session.id, adapter) - } - } catch (error) { - console.warn('[daemon] Failed to discover degraded daemon sessions', error) - } - } + await Promise.allSettled( + adapters.map(async (adapter) => { + try { + for (const session of await adapter.listProcesses()) { + sessionProviders.set(session.id, adapter) + } + } catch (error) { + console.warn('[daemon] Failed to discover degraded daemon sessions', error) + } + }) + ) }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 32f90d63-f6d3-49a7-953c-e44ff9e7c1cf
📒 Files selected for processing (11)
src/main/daemon/daemon-init.test.tssrc/main/daemon/daemon-init.tssrc/main/daemon/degraded-daemon-fresh-spawn-routing.tssrc/main/daemon/degraded-daemon-pty-provider.test.tssrc/main/daemon/degraded-daemon-pty-provider.tssrc/main/daemon/degraded-daemon-session-routing.tssrc/main/ipc/pty-management.test.tssrc/main/ipc/pty-management.tssrc/main/ipc/pty.test.tssrc/main/ipc/pty.tssrc/main/providers/pty-provider-contract.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/daemon/degraded-daemon-fresh-spawn-routing.ts (1)
48-63: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winBound the recovery probe.
checkDaemonHealthhas a finite timeout when it reaches the health socket, butprobeCurrentDaemonSpawnis not required to timeout before callingrecoverFreshSpawnRouting(). If a later implementation uses a custom probe that can hang, concurrent callers awaitthis.recoveryforever. Enforce a finite timeout aroundthis.probeCurrent()and add a regression test for a never-settling probe.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 12ff8bfb-2b7c-4d1b-ab54-d5c7af7e462a
📒 Files selected for processing (7)
src/main/daemon/degraded-daemon-fresh-spawn-routing.tssrc/main/daemon/degraded-daemon-pty-provider.test.tssrc/main/daemon/degraded-daemon-pty-provider.tssrc/main/ipc/pty.test.tssrc/main/ipc/pty.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/main/daemon/degraded-daemon-pty-provider.test.ts
- src/main/daemon/degraded-daemon-pty-provider.ts
- src/main/ipc/pty.test.ts
…degraded-pty-routing # Conflicts: # src/main/ipc/pty.ts # src/main/runtime/orca-runtime.ts
Electron reproduction and control validationValidated in an isolated Orca dev profile attached through CDP to this exact PR branch. Real degraded-state reproduction
Preserved session while degraded: Fresh daemon terminal after automatic recovery: Old-latch reproduction versus daemon controlI then used a temporary uncommitted E2E health override to emulate the pre-fix permanent fallback latch. No override or source change remains in the branch.
Latched fallback artifact: Daemon-backed control: This confirms the reported rendering corruption can be reproduced from the permanently latched fallback ownership state under scheduler pressure, and that returning fresh terminals to the durable daemon preserves authoritative snapshot ordering under the same stress. Remaining boundary: if the daemon is genuinely still unable to spawn PTYs, Orca must continue using the local fallback. Extreme pressure can still expose the fallback snapshot weakness in that legitimately degraded state; this PR fixes the transient-health permanent latch without expanding into a separate fallback-output subsystem rewrite. Cleanup completed: temporary source override removed, helper files restored, isolated terminal sessions and daemon processes stopped, and the worktree is clean. |
Electron QA — PASSValidated current HEAD
The degraded→recovered daemon transition has no production UI toggle, so that transition is covered by the deterministic recovery/provider tests and |
Current-head AI reviewThe requested same-model and same-effort reviewer re-audited the PR after the
Validation at current head:
Final verdict: CLEAN. |
* fix(terminal): recover degraded daemon spawn routing * fix(terminal): preserve fresh-session recovery semantics * fix(terminal): avoid retaining exited recovery sessions





Summary
Root cause
After a transient PTY spawn-health failure, DegradedDaemonPtyProvider permanently routed every later fresh terminal to the local fallback until restart. Those non-persistent PTYs cannot participate in durable terminal parking, allowing hidden renderer panes and memory pressure to accumulate.
The design follows the existing durable-host ownership model: host readiness is revalidated authoritatively, the provider route changes once, and downstream consumers derive from that route. Renderer observation is not used as runtime truth.
Reliability contract
Testing
Coverage includes failed recovery, later recovery, concurrent probe coalescing, retry cooldown, daemon endpoint wiring, management warning state, runtime-controller ordering, renderer-IPC ordering, stable-ID fresh runtime creation, restored-session reattach, stable-pane adoption, Git-guard/snapshot capability routing, hidden-at-spawn timing, pane materialization deduplication, and exit-before-spawn-reply ownership cleanup.
Electron QA
Validated current HEAD d779e9d in the actual Orca dev app through CDP-only Electron automation on macOS.
The degraded-to-recovered transition itself is covered by the deterministic recovery/provider tests because production Electron has no safe UI control for inducing that fault.
AI review report
The latest main branch was merged and conflicts in PTY spawn routing/runtime creation were reconciled without dropping stable-pane adoption or fresh-session recovery semantics.
A same-model, same-effort independent reviewer audited the full post-merge diff for correctness, ownership/reattach behavior, failure ordering, security, SSH/WSL/folder-workspace/cross-platform behavior, and performance. It found one material issue: a recovered daemon PTY that exited before its spawn reply could be reinserted into the session-provider map after the exit callback removed it, retaining stale ownership and memory. Commit d779e9d adds the liveness guard and regression test.
The reviewer reran the full diff after the fix and returned CLEAN with no remaining in-scope correctness, regression, security, cross-platform, SSH/folder-workspace, or performance findings.
Security audit
Notes