Repository navigation
Conversation
📝 WalkthroughWalkthroughThis PR adds a Related PRs: None specified. Suggested labels: terminal, pty, reliability Suggested reviewers: None specified. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 4034f3d1-4b00-489d-96bd-6c76e066a13b
📒 Files selected for processing (12)
config/reliability-gates.jsoncsrc/main/ipc/pty.test.tssrc/main/ipc/pty.tssrc/preload/api-types.tssrc/preload/index.tssrc/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/components/terminal-pane/pty-transport-types.tssrc/renderer/src/components/terminal-pane/pty-transport.test.tssrc/renderer/src/components/terminal-pane/pty-transport.tssrc/shared/terminal-startup-cwd.test.tssrc/shared/terminal-startup-cwd.ts
| "platforms": [ | ||
| "macos", | ||
| "linux", | ||
| "windows" | ||
| ], | ||
| "providers": [ | ||
| "local", | ||
| "daemon", | ||
| "ssh", | ||
| "wsl", | ||
| "remote-runtime", | ||
| "mobile" | ||
| ], |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
mobile is categorized as a provider here but as a platform elsewhere.
This gate lists mobile under providers, while the terminal-runtime.mobile-stream-budget gate (lines 2115-2126) lists mobile under platforms with remote-runtime as the provider. Mobile is a client/caller that reaches terminals via the remote-runtime provider, so any tooling that filters gates by provider vs. platform will mis-aggregate this entry. Align with the existing convention.
🔧 Align mobile with the platform/provider convention
"platforms": [
"macos",
"linux",
- "windows"
+ "windows",
+ "mobile"
],
"providers": [
"local",
"daemon",
"ssh",
"wsl",
- "remote-runtime",
- "mobile"
+ "remote-runtime"
],📝 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.
| "platforms": [ | |
| "macos", | |
| "linux", | |
| "windows" | |
| ], | |
| "providers": [ | |
| "local", | |
| "daemon", | |
| "ssh", | |
| "wsl", | |
| "remote-runtime", | |
| "mobile" | |
| ], | |
| "platforms": [ | |
| "macos", | |
| "linux", | |
| "windows", | |
| "mobile" | |
| ], | |
| "providers": [ | |
| "local", | |
| "daemon", | |
| "ssh", | |
| "wsl", | |
| "remote-runtime" | |
| ], |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: c24ce8f2-2164-4dd3-9409-158afcd3c5b3
📒 Files selected for processing (12)
config/reliability-gates.jsoncsrc/main/ipc/pty.test.tssrc/main/ipc/pty.tssrc/preload/api-types.tssrc/preload/index.tssrc/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/renderer/src/components/terminal-pane/pty-transport-types.tssrc/renderer/src/components/terminal-pane/pty-transport.test.tssrc/renderer/src/components/terminal-pane/pty-transport.tssrc/shared/terminal-startup-cwd.test.tssrc/shared/terminal-startup-cwd.ts
🚧 Files skipped from review as they are similar to previous changes (8)
- src/renderer/src/components/terminal-pane/pty-transport.ts
- src/renderer/src/components/terminal-pane/pty-connection.test.ts
- src/renderer/src/components/terminal-pane/pty-transport.test.ts
- src/shared/terminal-startup-cwd.ts
- src/main/ipc/pty.ts
- config/reliability-gates.jsonc
- src/shared/terminal-startup-cwd.test.ts
- src/main/ipc/pty.test.ts
| if ( | ||
| spawnedPtyId && | ||
| typeof spawnedPtyId === 'object' && | ||
| spawnedPtyId.startupCwdFallback?.kind === 'worktree' | ||
| ) { | ||
| writeTerminalOutput(pane.terminal, STARTUP_CWD_FALLBACK_NOTICE, { | ||
| foreground: true | ||
| }) | ||
| } |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win
Guard the fallback notice write with the visibility check used elsewhere.
Every other one-off foreground write in this file (writeRestoreUnavailableWarning, queueAgentIdleTerminalModeReset) gates foreground: true behind shouldWritePtyOutputForeground(deps.isVisibleRef.current). This new write forces foreground: true unconditionally, even for a hidden/background pane (e.g. a terminal created without focus), bypassing the background throttling path.
💡 Suggested fix
- if (
- spawnedPtyId &&
- typeof spawnedPtyId === 'object' &&
- spawnedPtyId.startupCwdFallback?.kind === 'worktree'
- ) {
- writeTerminalOutput(pane.terminal, STARTUP_CWD_FALLBACK_NOTICE, {
- foreground: true
- })
- }
+ if (
+ spawnedPtyId &&
+ typeof spawnedPtyId === 'object' &&
+ spawnedPtyId.startupCwdFallback?.kind === 'worktree'
+ ) {
+ writeTerminalOutput(pane.terminal, STARTUP_CWD_FALLBACK_NOTICE, {
+ foreground: shouldWritePtyOutputForeground(deps.isVisibleRef.current),
+ beforeWrite: beforeTerminalOutputWrite
+ })
+ }📝 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.
| if ( | |
| spawnedPtyId && | |
| typeof spawnedPtyId === 'object' && | |
| spawnedPtyId.startupCwdFallback?.kind === 'worktree' | |
| ) { | |
| writeTerminalOutput(pane.terminal, STARTUP_CWD_FALLBACK_NOTICE, { | |
| foreground: true | |
| }) | |
| } | |
| if ( | |
| spawnedPtyId && | |
| typeof spawnedPtyId === 'object' && | |
| spawnedPtyId.startupCwdFallback?.kind === 'worktree' | |
| ) { | |
| writeTerminalOutput(pane.terminal, STARTUP_CWD_FALLBACK_NOTICE, { | |
| foreground: shouldWritePtyOutputForeground(deps.isVisibleRef.current), | |
| beforeWrite: beforeTerminalOutputWrite | |
| }) | |
| } |
|
Superseded by #7847. This PR's head branch got detached on GitHub's side (branch delete/re-create), so it stopped tracking pushes. The fix was also reworked on top of current main: #7750 removed the containment guard this PR was originally built around, so #7847 targets the residual #7239 failure mode — a persisted startup cwd whose directory no longer exists. |
Summary
startupCwdis stale or outside the selected worktree by falling back to that worktree root.terminal-session.startup-cwd-containmentreliability gate with shared, main IPC, renderer transport, connection-layer, and notice coverage.Closes #7239.
Refs community PR #7297; I reproduced independently first, then adapted the same local-only fallback idea to the current branch and added issue-shaped non-ASCII path coverage plus the reliability gate.
Repro Evidence
Red before the fix:
pnpm exec vitest run --config config/vitest.config.ts src/shared/terminal-startup-cwd.test.ts -t "falls back"failed withTerminal cwd must be inside the selected worktree.for stale outside cwd fallback cases.pnpm exec vitest run --config config/vitest.config.ts src/main/ipc/pty.test.ts -t "falls back to the worktree root for stale local renderer cwd values"failed with the same error in the actualpty:spawnpath.That reproduces the issue shape: a local renderer-backed new terminal sends
worktreeIdplus a stale outsidecwd; main rejects before provider spawn, which is what produces the persistent terminal error toast.ELI5
Orca remembered a folder to start the next terminal in. In the bad state, that remembered folder was no longer inside the workspace, so the terminal guard stopped every new terminal from opening. Now, for a normal local "new terminal" click, Orca says: "that remembered folder is stale, so start at the workspace root instead," and it prints a short note in that terminal so the recovery is visible. It still refuses unsafe cwd requests from remote/session/API paths.
Tradeoffs
Reliability Proof
Reliability invariant:
terminal-session.startup-cwd-containmentfor #7239. A fresh local renderer terminal spawn may recover from a stale outside cwd only by spawning in the selected worktree root and printing a generic in-terminal notice; remote, SSH, reattach, runtime, mobile, and API callers must not silently weaken cwd containment.Material impact: This turns the persistent "new terminal never opens" failure into a recoverable local UI spawn while preserving the safety guard that prevents shells from starting outside the selected worktree. The recovery is no longer silent because the affected terminal shows a scoped note.
Product change type: mixed runtime hardening + reliability gate/test coverage.
Performance risk inventory: touches terminal creation,
pty:spawnpreflight, startup cwd resolution, renderer transport option routing, and one terminal foreground write after a successful fallback. It does not touch typing, output delivery, focus loops, resize, render scheduling, provider listing, hidden-pane wakeups, git/worktree scans, or subprocess creation.No-regression evidence: The runtime path adds constant-time option checks, uses the existing single cwd resolver during spawn, and performs one bounded terminal write only when fallback actually occurs. No polling, fanout, provider list, renderer loop, startup await, or subprocess work was added.
Correctness evidence:
pnpm exec vitest run --config config/vitest.config.ts src/shared/terminal-startup-cwd.test.tspassed: 19 tests.pnpm exec vitest run --config config/vitest.config.ts src/main/ipc/pty.test.tspassed: 221 tests.pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/pty-transport.test.tspassed: 57 tests.pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/pty-connection.test.tspassed: 335 tests.pnpm run typecheckpassed.pnpm run check:reliability-gatespassed.pnpm run check:max-lines-ratchetpassed.pnpm exec oxlint <changed TS files>passed.git diff --checkpassed.Provider/platform coverage: local macOS covered, including a Japanese/non-ASCII worktree-root test matching #7239. SSH strictness is covered via
connectionId; remote-runtime omission is covered in the connection tests. Daemon shares the same pre-provider main cwd decision but does not have a live daemon spawn run here. WSL/mobile/API and Linux/Windows live behavior are recorded as gate gaps.Residual gaps: no live Electron persisted-session fixture for the exact production state; no live daemon-provider run; no direct WSL/mobile/API provider-contract run.
Promotion status: partial experimental gate. It should not be promoted until CI/soak evidence, live Electron reproduction, and the provider/platform gaps above are addressed.
Rollback or demotion rule: demote/quarantine if the gate flakes without a product bug, or if any remote/session/API path can silently fall back instead of rejecting an outside cwd.
Additional Validation Notes
pnpm run lintwas attempted and failed in unrelated existing code:src/renderer/src/components/right-sidebar/source-control-manual-review-url.ts:164is missing thenullcase for the switch-exhaustiveness lint. I kept that source-control fix out of this terminal PR; targeted oxlint on the changed files passed.