Skip to content

fix(terminal): allow terminals to spawn outside the worktree (#7685) - #7750

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/7685-remove-terminal-cwd-worktree-gate
Jul 7, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/7685-remove-terminal-cwd-worktree-gate

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #7685 — right-click → Split Terminal created a dead pane with the banner "Terminal cwd must be inside the selected worktree." whenever the source shell had navigated outside the worktree root (e.g. after cd ..).

Root cause

A terminal startup-cwd containment guard (resolveTerminalStartupCwd) throws whenever a requested/inherited cwd resolves outside the worktree root. That guard was added incidentally alongside the file-explorer "Open in Terminal" feature (#7029) and sits on the shared pty.spawn path — so it also rejects split-pane cwd inheritance (a feature since April). After cd .., splitting inherits the out-of-worktree cwd, the guard throws, and the new pane dies.

The guard provided no real containment: a shell spawned at the worktree root can cd anywhere immediately, so restricting only the startup cwd blocked a legitimate feature without adding a security boundary. Terminals should be allowed to open/split outside the worktree.

Fix

  • resolveTerminalStartupCwd now resolves the requested cwd (relative paths still anchor to the worktree root; .. normalized) and returns it without throwing.
  • Removed the now-unused symlink canonicalizePath plumbing and deleted the dead terminal-cwd-realpath module that only existed to soften the gate.
  • Renamed the two caller wrappers now that nothing is "guarded".
  • SSH/remote behavior is unchanged beyond throw→resolve (realpath was already disabled for remote connections).

Supersedes the clamp approach in #7728 (which forced the split back to the worktree root — the opposite of the desired behavior).

Testing

  • Rewrote terminal-startup-cwd.test.ts + orca-runtime-terminal-cwd.test.ts to assert out-of-worktree cwds now resolve/spawn (they fail if the throw is reintroduced). Touched suites: 235 passing. Typecheck + lint clean.
  • Verified in a dev build: spawning a PTY into a worktree with an out-of-worktree cwd now succeeds (previously rejected), and the shell's own pwd confirms it started at the out-of-worktree directory.

Made with Orca 🐋

The startup-cwd guard threw 'Terminal cwd must be inside the selected
worktree' whenever a requested/inherited cwd resolved outside the worktree
root. That gate landed incidentally with the file-explorer 'open in
terminal' feature and collided with split-pane cwd inheritance: after
'cd ..', splitting a terminal inherited the out-of-worktree cwd and the
guard killed the new pane with an error banner.

The gate provided no real containment (a shell spawned at the worktree root
can cd anywhere immediately), so remove it and spawn at the resolved cwd.
Delete the now-dead local realpath canonicalizer that only existed to
soften the gate.

Co-authored-by: Orca <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 322f0878-4e92-4385-91c7-1221a4007dd5

📥 Commits

Reviewing files that changed from the base of the PR and between 46dcfd3 and 94c4e95.

📒 Files selected for processing (7)
  • src/main/ipc/pty.ts
  • src/main/pty/terminal-cwd-realpath.test.ts
  • src/main/pty/terminal-cwd-realpath.ts
  • src/main/runtime/orca-runtime-terminal-cwd.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/shared/terminal-startup-cwd.test.ts
  • src/shared/terminal-startup-cwd.ts
💤 Files with no reviewable changes (2)
  • src/main/pty/terminal-cwd-realpath.test.ts
  • src/main/pty/terminal-cwd-realpath.ts

📝 Walkthrough

Walkthrough

Changes

Terminal startup working-directory resolution was changed to no longer enforce that a requested cwd stays inside the selected worktree and no longer performs symlink canonicalization. The shared resolver functions dropped their canonicalizePath/TerminalStartupCwdOptions parameters. The localTerminalCwdCanonicalizer/canonicalizeLocalTerminalPath module and its test were deleted. Runtime and PTY IPC code paths were updated to call new simplified resolver helpers (resolveWorkspaceTerminalStartupCwd, resolvePtySpawnStartupCwd) instead of the previous guarded resolvers. Tests were updated to expect out-of-worktree cwds to resolve and spawn successfully rather than throwing.

Sequence Diagram(s)

See hidden artifact diagrams above.

Related PRs: None specified.

Suggested labels: terminal, refactor, breaking-change

Suggested reviewers: None specified.

🐰 A canonicalizer hopped away today,
No more fences kept the cwd at bay,
Trim and resolve, wherever it may roam,
Outside the worktree, still it finds a home.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: allowing terminals to spawn outside the worktree.
Description check ✅ Passed The description is substantive and covers summary, root cause, fix, and testing, but it omits template sections for screenshots, AI review report, security audit, and notes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@brennanb2025
brennanb2025 merged commit d8df9c8 into main Jul 7, 2026
2 checks passed
nwparker added a commit that referenced this pull request Jul 8, 2026
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]>
nwparker added a commit that referenced this pull request Jul 8, 2026
)

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]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Split terminal is not working

1 participant