Repository navigation
Conversation
📝 WalkthroughWalkthroughThe change raises mobile and runtime protocol compatibility versions to 4. It adds exact terminal layout-leaf and workspace-session retirement, generation-aware PTY handles, stale-close validation, ownership-aware PTY cleanup, persistence rollback, and runtime-owned PTY exit retirement. Close options now propagate through main-process IPC, preload, renderer handlers, and web-runtime terminal actions. Mobile snapshots include unified terminal color and pin state, while tests cover protocol compatibility, terminal ownership, stale bindings, renderer validation, and retirement flows. 🚥 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/shared/workspace-session-terminal-leaf-retirement.ts (1)
22-31: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocument why pin protection is bypassed here.
Passing
allowPinnedRetirement: trueunconditionally overrides the pin guard so a pinned tab is fully closed when its last leaf's PTY exits. This is a deliberate exception to pin protection but isn't explained inline, which makes it easy for a future edit to either "fix" this as a bug or extend the bypass to unsafe call sites.As per coding guidelines, "When code is driven by a design document or non-obvious constraint, add a brief one- or two-line comment explaining why the behavior is necessary."
📝 Suggested comment
if (!retirement.layout) { + // Why: the retired leaf was the tab's last pane, so there is nothing left + // to display — close it even if pinned, since pin protection exists to + // preserve visible content, not a dead PTY's empty shell. const closed = closeTerminalTabInWorkspaceSession(session, worktreeId, args.parentTabId, { allowPinnedRetirement: true })Source: Coding guidelines
src/shared/workspace-session-terminal-leaf-retirement.test.ts (1)
69-95: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for the last-leaf/tab-close branch.
Both tests exercise the "leaf survives" and "stale reject" paths, but neither covers retiring the tab's last leaf, which routes through
closeTerminalTabInWorkspaceSession(..., { allowPinnedRetirement: true })and fully removes the tab. This is the branch that intentionally overrides pin protection — worth a dedicated test (including a pinned-tab case) given how central that bypass is to this PR's safety goals.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 9ba28c23-3776-4331-a9c9-ed80d65c7f80
📥 Commits
Reviewing files that changed from the base of the PR and between 49149a0 and d57cf6d988c710f1fecce226f19d03704caeba0e.
📒 Files selected for processing (28)
mobile/src/transport/protocol-compat.test.tsmobile/src/transport/protocol-version.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/main/window/attach-main-window-services.tssrc/main/window/terminal-tab-close-request-relay.test.tssrc/main/window/terminal-tab-close-request-relay.tssrc/preload/api-types.tssrc/preload/index.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.tssrc/renderer/src/components/terminal/terminal-tab-actions.test.tssrc/renderer/src/components/terminal/terminal-tab-actions.tssrc/renderer/src/hooks/useIpcEvents.test.tssrc/renderer/src/hooks/useIpcEvents.tssrc/renderer/src/runtime/sync-runtime-graph.test.tssrc/renderer/src/runtime/sync-runtime-graph.tssrc/renderer/src/runtime/web-runtime-session.test.tssrc/renderer/src/runtime/web-runtime-session.tssrc/renderer/src/store/slices/terminal-tab-retirement.tssrc/shared/protocol-compat.test.tssrc/shared/protocol-version.tssrc/shared/terminal-layout-leaf-retirement.test.tssrc/shared/terminal-layout-leaf-retirement.tssrc/shared/terminal-tab-close.tssrc/shared/workspace-session-terminal-leaf-retirement.test.tssrc/shared/workspace-session-terminal-leaf-retirement.tssrc/shared/workspace-session-terminal-tab-close.ts
Co-authored-by: Orca <help@stably.ai>
d57cf6d to
b39dff7
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: b1dad8f4-9aac-4310-ad3d-3e35e8cd9b1b
📥 Commits
Reviewing files that changed from the base of the PR and between d57cf6d988c710f1fecce226f19d03704caeba0e and b39dff7.
📒 Files selected for processing (22)
mobile/app/h/[hostId]/session/[worktreeId].tsxmobile/src/transport/protocol-compat.test.tsmobile/src/transport/protocol-version.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/main/runtime/rpc/methods/session-tabs-schemas.tssrc/main/runtime/rpc/methods/session-tabs.test.tssrc/main/runtime/rpc/methods/session-tabs.tssrc/main/window/attach-main-window-services.tssrc/main/window/terminal-tab-close-request-relay.test.tssrc/main/window/terminal-tab-close-request-relay.tssrc/preload/api-types.tssrc/preload/index.tssrc/renderer/src/components/automations/automation-target-availability.test.tssrc/renderer/src/components/sidebar/sidebar-host-options.test.tssrc/renderer/src/components/tab-group/useTabGroupWorkspaceModel.focus.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.tssrc/renderer/src/components/terminal/terminal-tab-actions.test.tssrc/renderer/src/components/terminal/terminal-tab-actions.tssrc/renderer/src/hooks/useIpcEvents.test.tssrc/renderer/src/hooks/useIpcEvents.ts
🚧 Files skipped from review as they are similar to previous changes (13)
- src/preload/index.ts
- src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.ts
- src/preload/api-types.ts
- mobile/src/transport/protocol-version.ts
- src/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.ts
- src/main/window/terminal-tab-close-request-relay.ts
- src/main/window/attach-main-window-services.ts
- mobile/src/transport/protocol-compat.test.ts
- src/renderer/src/components/terminal/terminal-tab-actions.ts
- src/renderer/src/hooks/useIpcEvents.ts
- src/renderer/src/hooks/useIpcEvents.test.ts
- src/renderer/src/components/terminal/terminal-tab-actions.test.ts
- src/main/runtime/orca-runtime.ts
| it('rejects ambiguous legacy closes before they reach the runtime', async () => { | ||
| const runtime = { | ||
| getRuntimeId: () => 'test-runtime', | ||
| closeMobileSessionTab: vi.fn() | ||
| } as unknown as OrcaRuntimeService | ||
| const dispatcher = new RpcDispatcher({ runtime, methods: SESSION_TAB_METHODS }) | ||
|
|
||
| const legacyResponse = await dispatcher.dispatch( | ||
| makeRequest('session.tabs.close', { | ||
| worktree: 'id:wt-1', | ||
| tabId: 'tab-1' | ||
| }) | ||
| ) | ||
| const explicitResponse = await dispatcher.dispatch( | ||
| makeRequest('session.tabs.close', { | ||
| worktree: 'id:wt-1', | ||
| tabId: 'tab-1', | ||
| intent: 'user' | ||
| }) | ||
| ) | ||
|
|
||
| expect(legacyResponse.ok).toBe(false) | ||
| expect(explicitResponse.ok).toBe(true) | ||
| expect(runtime.closeMobileSessionTab).toHaveBeenCalledTimes(1) | ||
| expect(runtime.closeMobileSessionTab).toHaveBeenCalledWith('id:wt-1', 'tab-1') | ||
| }) |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
Test rejection of non-user intent values.
The test covers missing intent and intent: 'user', but not values such as 'mirror'. Add that case and assert the runtime is not called; otherwise a regression to a generic string schema could still pass while allowing ambiguous destructive requests.
| runtimeProtocolVersion: RUNTIME_PROTOCOL_VERSION, | ||
| minCompatibleRuntimeClientVersion: MIN_COMPATIBLE_RUNTIME_CLIENT_VERSION |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Preserve explicit version-skew coverage in this compatibility fixture.
Replacing the previous 3/3 values with the current 4/4 constants turns this case into same-version compatibility. Keep a named legacy-compatible fixture (and add a separate current-version case if needed), otherwise future protocol regressions can pass without testing backward compatibility.
Suggested adjustment
- runtimeProtocolVersion: RUNTIME_PROTOCOL_VERSION,
- minCompatibleRuntimeClientVersion: MIN_COMPATIBLE_RUNTIME_CLIENT_VERSION
+ runtimeProtocolVersion: LEGACY_COMPATIBLE_RUNTIME_PROTOCOL_VERSION,
+ minCompatibleRuntimeClientVersion: LEGACY_COMPATIBLE_RUNTIME_CLIENT_VERSION📝 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.
| runtimeProtocolVersion: RUNTIME_PROTOCOL_VERSION, | |
| minCompatibleRuntimeClientVersion: MIN_COMPATIBLE_RUNTIME_CLIENT_VERSION | |
| runtimeProtocolVersion: LEGACY_COMPATIBLE_RUNTIME_PROTOCOL_VERSION, | |
| minCompatibleRuntimeClientVersion: LEGACY_COMPATIBLE_RUNTIME_CLIENT_VERSION |
|
Related to #9952 (sessions vanishing over remote Orca link). |
|
Closing this as superseded by the host-authoritative terminal lifecycle work that has since landed on main in #9687, #9804, and #9994. The current PR head ( We reproduced the original destructive flow on pre-fix main with a real encrypted paired client and real serve-runtime PTY. On exact Any remaining generation-bound hardening for explicit user closes should be a small follow-up PR on current main, with an old-host fallback only for |
Summary
Make the remote host the sole owner of destructive terminal lifecycle decisions.
A paired renderer is now a mirror: disconnecting, unmounting, switching servers, or observing a stale PTY exit cannot kill the host PTY. An intentional ready-tab close carries an exact generation-bound terminal handle, and main revalidates the PTY/worktree/tab/leaf/generation immediately before committing the durable retirement and tearing down the provider.
This is a fresh replacement design for the lifecycle problem discussed in #8872. It does not modify that contributor branch.
ELI5 user flow
Design
Verification
Deterministic checks on the final rebased commit:
git diff --checkpassed.Real paired Electron +
orca servevalidation through the encrypted runtime transport:terminal_handle_stale;terminal_tab_pinnedand preserved both process trees;After rebasing onto the latest adjacent SSH-ownership change, the exact final artifacts were rebuilt and a publication smoke repeated protocol pairing, live PTY disconnect survival, ready-state reconnect, pinned rejection, and guarded explicit close.
Regression considerations
Made with Orca 🐋