Repository navigation
fix(terminal): make remote workspace sleep converge - #9874
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe changes add worktree-scoped terminal sleep with serialized PTY teardown, liveness verification, structured results, and replayable client sleep events. Renderer PTY handling now buffers output, defers exits, preserves bindings across reversible stops, and rolls back failed shutdowns. Remote runtimes support modern sleep RPCs with legacy stop-and-convergence fallback. Tests expand coverage for runtime coordination, remote subscriptions, renderer lifecycle handling, and end-to-end sleep/wake convergence. Native dependency rebuilding now targets only modules whose probes fail. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/shared/runtime-types.ts (1)
487-503: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocument the outcome-dependent type invariant.
The
neverfields prevent consumers from treating verified and failed teardown outcomes as interchangeable; add a conciseWhycomment above this union.Proposed clarification
} & ( + // Why: callers may only receive liveness evidence on failed verification; + // verified results must not be mistaken for a failure carrying stale evidence. | {As per coding guidelines, “For non-obvious TypeScript code, add a concise comment explaining why the constraint exists.”
Source: Coding guidelines
src/preload/index.ts (1)
1048-1049: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAlign the internal
listenerparam type with the widened callback contract.The
callbacktype now includespreserveRendererBinding?: boolean, but the intermediatelistener'sdatais still typed{ id: string; code: number }. It works at runtime (the IPC object carries the field and is forwarded verbatim), but the annotation understates the payload and can mislead future readers.♻️ Proposed annotation alignment
- const listener = (_event: Electron.IpcRendererEvent, data: { id: string; code: number }) => - callback(data) + const listener = ( + _event: Electron.IpcRendererEvent, + data: { id: string; code: number; preserveRendererBinding?: boolean } + ) => callback(data)src/renderer/src/components/terminal-pane/pty-shutdown-host-generation.ts (1)
24-79: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDocument that
shouldApplyHostSleepPhaserecords the accepted phase.The name reads as a pure predicate, but on return
trueit also mutateshostSleepPhaseByPtyId(Lines 71-76). It's invoked from inside a.filter()inpty-shutdown-exit-deferral.ts, so a reader could reasonably assume it's side-effect free. A one-line comment on the function explaining that it records/advances the accepted generation-phase barrier would prevent misuse.As per coding guidelines: "For non-obvious TypeScript code, add a concise comment explaining why the constraint exists, not how the code works."
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8bb59737-20d7-47ca-a493-6fe41d88d297
📒 Files selected for processing (37)
config/scripts/rebuild-native-deps.mjsconfig/scripts/rebuild-native-deps.test.mjssrc/main/ipc/pty.test.tssrc/main/ipc/pty.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/main/runtime/remote-runtime-request-connection.integration.test.tssrc/main/runtime/rpc/methods/client-events.tssrc/main/runtime/rpc/methods/terminal.tssrc/preload/api-types.tssrc/preload/index.tssrc/renderer/src/components/sidebar/sleep-worktree-flow.test.tssrc/renderer/src/components/sidebar/sleep-worktree-flow.tssrc/renderer/src/components/terminal-pane/TerminalPane.tsxsrc/renderer/src/components/terminal-pane/pty-connection-types.tssrc/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/components/terminal-pane/pty-dispatcher.tssrc/renderer/src/components/terminal-pane/pty-shutdown-data-suspension.test.tssrc/renderer/src/components/terminal-pane/pty-shutdown-data-suspension.tssrc/renderer/src/components/terminal-pane/pty-shutdown-exit-deferral.test.tssrc/renderer/src/components/terminal-pane/pty-shutdown-exit-deferral.tssrc/renderer/src/components/terminal-pane/pty-shutdown-host-generation.tssrc/renderer/src/components/terminal-pane/pty-transport.test.tssrc/renderer/src/components/terminal-pane/pty-transport.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.tssrc/renderer/src/components/terminal-pane/terminal-parked-watcher-registry.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.tssrc/renderer/src/hooks/useIpcEvents.tssrc/renderer/src/runtime/remote-worktree-sleep.tssrc/renderer/src/runtime/runtime-client-events.test.tssrc/renderer/src/runtime/runtime-client-events.tssrc/renderer/src/store/slices/store-cascades.test.tssrc/renderer/src/store/slices/terminals.tssrc/shared/runtime-client-events.tssrc/shared/runtime-types.tstests/e2e/terminal-sleep-wake-restore.spec.ts
| await waitFor(() => reconnectedEvents.some((event) => event.type === 'ready')) | ||
| expect( | ||
| reconnectedEvents | ||
| .filter((event) => event.type === 'worktreeTerminalSleepState') | ||
| .map((event) => event.phase) | ||
| ).toEqual(['committed']) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert that the committed snapshot precedes ready.
The current assertion passes if ready is emitted before the snapshot. Compare their indices so this test protects the listener-first ordering contract.
Proposed assertion
await waitFor(() => reconnectedEvents.some((event) => event.type === 'ready'))
+ expect(
+ reconnectedEvents.findIndex(
+ (event) =>
+ event.type === 'worktreeTerminalSleepState' && event.phase === 'committed'
+ )
+ ).toBeLessThan(reconnectedEvents.findIndex((event) => event.type === 'ready'))
expect(
reconnectedEvents📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| await waitFor(() => reconnectedEvents.some((event) => event.type === 'ready')) | |
| expect( | |
| reconnectedEvents | |
| .filter((event) => event.type === 'worktreeTerminalSleepState') | |
| .map((event) => event.phase) | |
| ).toEqual(['committed']) | |
| await waitFor(() => reconnectedEvents.some((event) => event.type === 'ready')) | |
| expect( | |
| reconnectedEvents.findIndex( | |
| (event) => | |
| event.type === 'worktreeTerminalSleepState' && event.phase === 'committed' | |
| ) | |
| ).toBeLessThan(reconnectedEvents.findIndex((event) => event.type === 'ready')) | |
| expect( | |
| reconnectedEvents | |
| .filter((event) => event.type === 'worktreeTerminalSleepState') | |
| .map((event) => event.phase) | |
| ).toEqual(['committed']) |
Summary
Remote workspace sleep is now host-authoritative and converges on the first successful action for existing and future workspaces. The owner runtime freshly discovers live PTYs, fences concurrent spawns, waits for physical teardown, verifies liveness afterward, and only then lets clients commit sleeping state. Failures roll back/surface through the existing sleep flow, while proven-dead siblings remain reversibly committed for idempotent retry.
Root cause: daemon liveness and renderer/persisted projections could diverge. The old flow depended on client-hydrated PTY IDs, cleared renderer IDs before remote confirmation, swallowed compatibility errors, and used graph-derived fire-and-forget stops.
worktree.pscould then count stale leaves/tabs even after freshterminal.listwas empty.This supersedes #9665 while retaining its correct principle that persisted identifiers are wake hints, not liveness. #9665 fixes the stale status projection; this PR additionally establishes the long-term host discover → stop/wait → verify contract, per-PTY partial outcomes, multi-client dispositions and reconnect snapshots.
No visual change.
Testing
pnpm lint— full repository lint not run; touched-fileoxlintpassedpnpm typecheck— node and web passed after rebasing onto latestmainpnpm test— focused contract run: 1,930 passed, 12 skipped; one unrelated existing Windows/tmppath fixture failed (preserves existing badgeColor on runtime createRepo dedupe)pnpm build— the Windows Electron E2E built main, preload, and renderer successfully; standalone command not runFocused coverage includes: no hydrated client PTY IDs, transient graph/RPC failure, physical stop failure, stale renderer leaves/persisted tabs, partial sibling failure, first-attempt convergence, idempotent retry, legacy runtime fallback, mutation timeout, two clients, late/reconnecting client snapshots, missed dispositions, stale generations, and more than 512 active guards.
Windows Electron E2E (
terminal-sleep-wake-restore.spec.ts) passed after one sleep action with:terminal.list.totalCount = 0worktree.ps.liveTerminalCount = 0worktree.ps.hasAttachedPty = falseEncrypted WebSocket integration proves one
terminal.sleepreaches the host, two clients observe orderedstarted/committedstate, and a client subscribing after commit receives the authoritative snapshot followed bywoken.Repository setup passed. This PR also repairs Windows native dependency setup so the required setup path does not silently skip the correct platform package.
AI Review Report
Ran seven iterative adversarial review rounds using the installed internal PR-review skill until no valid Critical, Important, or Minor findings remained. Reviews explicitly challenged physical teardown verification, partial failures, mutation fencing, old-runtime deadlines, handle identity, passive-client output suspension, reconnect hydration, missed outcomes, generation ordering, bounded expiry, large workspaces, and macOS/Linux/Windows/SSH/WSL behavior.
Findings led to per-PTY outcomes, passive transport suspension, autonomous rollback expiry, listener-first sleep snapshots, stale-generation tombstones, missed-commit wake reconciliation, and removal of correctness-breaking count eviction. Final verdict: approved with no findings.
Cross-platform review confirmed no platform-specific sleep policy was introduced: authority stays with the selected runtime, path identity uses existing runtime normalization, and the contract is transport/provider-neutral for local, SSH, WSL, macOS, Linux, and Windows hosts.
Security Audit
The new RPC reuses existing paired-runtime authorization and worktree selector resolution. No new shell command construction, secrets, dependencies, provider-specific API, or renderer-trusted liveness input was added. Host mutation fencing and wall-clock deadlines prevent abandoned requests from later killing terminals; subscription snapshots are read-only runtime state scoped to the authenticated connection.
Notes
method_not_found, using repeated fresh discovery/stop under one bounded deadline; real remote errors are surfaced.