Repository navigation
fix: recover fresh local terminal spawns from a deleted saved cwd - #7847
Conversation
After #7750 removed the containment guard, the residual #7239 failure mode is a persisted/inherited startupCwd whose directory no longer exists: every spawn dies with the provider's missing-directory error. Fresh local renderer spawns now opt in (cwdFallback: 'worktree') to recover at the workspace root with a generic in-terminal notice; reattach, SSH, remote-runtime, runtime/API and mobile callers keep exact cwd semantics, and existing directories — including outside the worktree (#7685) — spawn as requested. Co-authored-by: Orca <[email protected]>
923bede to
b7aaffa
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 923bedeb1d64c6ec8d5bbcb2bd95572f91945304 and b7aaffa. 📒 Files selected for processing (12)
🚧 Files skipped from review as they are similar to previous changes (12)
📝 WalkthroughWalkthroughAdds a fallback mechanism for terminal PTY startup working directories: when a persisted 🚥 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 |
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/renderer/src/components/terminal-pane/pty-transport.ts (1)
683-705: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winForward
startupCwdFallbackin thecoldRestorereturn (src/renderer/src/components/terminal-pane/pty-transport.ts:683-695)
pty:spawncan includestartupCwdFallbackon the same response ascoldRestore, but this early return drops it. That preventspty-connection.tsfrom showing the saved-folder-missing notice and leaves the terminal opening at the workspace root without explanation.
🧹 Nitpick comments (1)
src/renderer/src/components/terminal-pane/pty-transport.test.ts (1)
199-214: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winConsider adding a case for
coldRestore+startupCwdFallbacktogether.The current test only covers a plain fresh spawn returning
startupCwdFallback. Given the coldRestore-branch concern raised onpty-transport.ts(Lines 683-705), a test mockingspawnto resolve{ id, coldRestore: {...}, startupCwdFallback: {...} }would pin down whether the field is expected to survive that branch.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 614ab14b-1a29-47cb-9641-e10248ca5eb6
📥 Commits
Reviewing files that changed from the base of the PR and between 19f1ad4 and 923bedeb1d64c6ec8d5bbcb2bd95572f91945304.
📒 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
Clean auto-merge, no conflicts. Brought in from main: - daemon boot hardening: fail builds/CI when terminal daemon can't start; plain-node-entry-guard + verify-packaged-daemon-entry (electron require leaked into daemon-entry chunk, #7844/#7849) - perf(windows): relax whole-process-table scans for terminals with no agent evidence (#7607) — foreground-scan-cadence - fix(agents): route WSL OMP hooks to the Windows listener (#7565/#7641) - fix: recover fresh local terminal spawns from a deleted saved cwd (#7847) - native-chat: upload composer attachments over SSH (#7832) - mobile: keyboard dismiss control; agent-tab launch fix - new GitHub issue draft persistence (#7778) Perf-branch structure preserved (clean auto-merge; no restructured terminal files conflicted). Gates: typecheck 0 errors; terminal-pane + ipc/pty + daemon + pane-manager suites 4497 passed / 14 skipped / 0 failed. Co-authored-by: Orca <[email protected]>
…ablyai#7847) After stablyai#7750 removed the containment guard, the residual stablyai#7239 failure mode is a persisted/inherited startupCwd whose directory no longer exists: every spawn dies with the provider's missing-directory error. Fresh local renderer spawns now opt in (cwdFallback: 'worktree') to recover at the workspace root with a generic in-terminal notice; reattach, SSH, remote-runtime, runtime/API and mobile callers keep exact cwd semantics, and existing directories — including outside the worktree (stablyai#7685) — spawn as requested. Co-authored-by: Orca <[email protected]>
Summary
Replaces #7678 (that PR's head branch got detached on GitHub's side after a branch delete/re-create, so it can no longer track pushes; same branch, reworked fix). Two changes on
mainsince #7678 was opened reshaped the fix:Terminal cwd must be inside the selected worktree.(the exact persistent toast reported in [Bug]: New terminal creation persistently fails with "Terminal cwd must be inside the selected worktree." toast #7239) can no longer be thrown onmain, and out-of-worktree cwds now spawn as requested ([Bug]: Split terminal is not working #7685 split-inheritance semantics).startupCwdwhose directory no longer exists on disk (e.g. FileExplorer "Open in Terminal" on a folder that is later deleted, a restored tab, or splitting from a shell whose cwd was removed). Every spawn then dies with the provider'sWorking directory "…" does not exist.red toast, on every retry, with no way to self-recover from the UI.This PR now fixes that residual path:
cwdFallback: 'worktree'; when the resolved startup cwd is missing and the workspace root exists, main spawns at the workspace root and returnsstartupCwdFallbackmetadata.[Orca opened this terminal at the workspace root because its saved start folder no longer exists.]sessionId), SSH (connectionId), remote-runtime, runtime/API, and mobile callers never engage the fallback: the renderer only sends the flag for fresh local IPC spawns and main independently re-checks.statSyncon\\wsl.localhost9P shares can falsely report ENOENT); the provider's WSL-aware validation stays authoritative.Closes #7239.
Supersedes #7297 (its outside-worktree fallback premise was mooted by #7750) and #7184 (same missing-dir bug, but via an unconditional resolver fallback that would also remap reattach/runtime/API cwds).
Repro evidence (red)
On current
main, in a live dev build (daemon provider), spawning a fresh local terminal whose saved cwd was deleted:→ red
TerminalErrorToastwith "file an issue", every retry, no recovery — the same UX class as #7239. The unit testkeeps a missing cwd unchanged without the fallback flagpins this error shape.Live Electron evidence (green)
Verified in a dev build at this branch (isolated profile, throwaway repo, daemon provider):
pty:spawnwithcwd=<repo>/deleted-folder+cwdFallback:'worktree'→ spawned, response carriedstartupCwdFallback: { kind: 'worktree', cwd: '/private/tmp/orca-cwd-fallback-repo' }, andpty:getCwdconfirmed the live shell at the repo root.startupCwdrendered the notice and an interactive prompt; typingpwdprinted/private/tmp/orca-cwd-fallback-repo. No toast.cwd=/private/tmp(existing, outside worktree) + flag spawned at/private/tmpwith no fallback metadata ([Bug]: Split terminal is not working #7685 preserved).ELI5
Orca sometimes remembers which folder a terminal should start in. If that folder gets deleted, clicking "new terminal" used to fail with a red error — every single time. Now Orca notices the folder is gone, starts the terminal at the workspace root instead, and prints a short note in the terminal saying what happened. Terminals that reconnect to existing sessions, remote/SSH terminals, and API-created terminals are unchanged.
Tradeoffs
statSync, so they keep exact cwd semantics.Reliability proof
Gate:
terminal-session.startup-cwd-missing-dir-recovery(experimental) — invariant: a fresh local renderer spawn may recover from a missing saved cwd only by spawning at the workspace root with a generic notice; existing directories always spawn as requested; reattach/SSH/remote/runtime/mobile callers keep exact cwd semantics.Performance risk inventory: touches
pty:spawnpreflight (adds ≤2statSyncprobes for fresh local spawns only — the provider already stats the same paths invalidateWorkingDirectory), renderer transport option routing, and one bounded terminal write only when fallback occurs (visibility-gated foreground). No polling, fanout, provider listing, render-loop, startup-await, or subprocess work added.Correctness evidence (all at this branch):
pnpm exec vitest run --config config/vitest.config.ts src/shared/terminal-startup-cwd.test.ts— 21 passedpnpm exec vitest run --config config/vitest.config.ts src/main/ipc/pty.test.ts— 225 passedpnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/pty-transport.test.ts— 58 passedpnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/pty-connection.test.ts— 341 passedpnpm run typecheck— passedpnpm run check:reliability-gates— passed (30 gates)pnpm run check:max-lines-ratchet— passedpnpm exec oxlint <changed files>— cleanResidual gaps (recorded in the gate): no live daemon-provider run in CI (covered locally above), WSL/mobile/API provider-contract runs, Linux/Windows live behavior.
Note on the second report in #7239
Shoma-DS's follow-up (in-worktree cwd still rejected on 1.4.121) was hit on the pre-#7750 guard, which no longer exists. The
orca status/stale_bootstrapruntime-connection instability in that comment is a separate issue and is not addressed here.Made with Orca 🐋