Skip to content

fix(terminal): keep literal backslashes in POSIX terminal startup cwd - #52558

Merged
nwparker merged 1 commit into
stablyai:mainfrom
SeungWoonSong:fix/terminal-preserve-posix-backslash-cwd
Nov 29, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
SeungWoonSong:fix/terminal-preserve-posix-backslash-cwd

Conversation

@SeungWoonSong

@SeungWoonSong SeungWoonSong commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

On Linux and macOS, a folder name can contain a backslash, for example reports\2026. When you opened a terminal in such a folder, Orca treated the backslash as a Windows path separator, couldn't find the folder, and opened the terminal in the workspace root. The terminal now opens in the folder you picked.

What Changed

Before: asking for a startup cwd of reports\2026 (relative, or the absolute path sent by the file explorer) in a POSIX workspace was rewritten to reports/2026. The missing-directory check then failed and the shell started in the workspace root. A workspace root with a backslash in it, such as /work\archive/repo, was also reported as being outside itself.

After: the shell starts in <workspace>/reports\2026.

Mechanism:

  • resolveTerminalStartupCwd picks the path flavor from isWindowsAbsolutePathLike(workspaceRoot) or isWindowsAbsolutePathLike(cwd). A backslash in a relative name no longer switches to Windows flavor. It passes that flavor to resolveRuntimePath.
  • resolveRuntimePath takes an optional pathFlavor argument. Its default is the old inference, so other callers don't change. Under POSIX flavor it, along with normalizeRuntimePathDots, no longer turns \ into /, and a leading \ is no longer treated as a drive-root path.
  • Windows drive, UNC and WSL UNC paths resolve exactly as before.

Why

The bug started in terminal startup: it guessed Windows path rules from any backslash in the requested name. On POSIX a backslash is a normal filename character, so path rules have to come from absolute path syntax (a drive letter or a UNC prefix), not from a backslash inside a name. Changing the default for every resolveRuntimePath caller would have changed check annotations, bot home files and browser document locations too. An explicit flavor keeps this fix limited to terminal startup.

Linked Issue

Fixes #52557

Visual Proof

There is no UI change. The visible effect is which directory the shell starts in. Below is the output of a real filesystem probe: real directories under a temp workspace (<ws>), the production startup resolver with its real missing-directory check, then /bin/pwd run in the returned directory.

Before (main)

req=reports\2026            -> <ws>   pwd=<ws>               (fallback from <ws>/reports/2026)
req=<ws>/reports\2026       -> <ws>   pwd=<ws>               (fallback from <ws>/reports/2026)
req=a\b/c                   -> <ws>   pwd=<ws>               (fallback from <ws>/a/b/c)
req=dup\x                   -> <ws>/dup/x   pwd=<ws>/dup/x   (wrong sibling directory)
startup(/work\archive/repo, .) = /work/archive/repo   outside=true

After (this PR)

req=reports\2026            -> <ws>/reports\2026   pwd=<ws>/reports\2026
req=<ws>/reports\2026       -> <ws>/reports\2026   pwd=<ws>/reports\2026
req=a\b/c                   -> <ws>/a\b/c          pwd=<ws>/a\b/c
req=dup\x                   -> <ws>/dup\x          pwd=<ws>/dup\x
startup(/work\archive/repo, .) = /work\archive/repo   outside=false

A missing folder (missing\dir) still falls back to the workspace root. Across 17 sampled path pairs (Windows drive, UNC, WSL UNC, /c/..., ~, .. at /), the two-argument resolveRuntimePath returns the same result on main and on this branch.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

  • I reproduced the bug on macOS with real directories named reports\2026, a\b/c and dup\x (probe above). With this change the shell starts in the requested folder. The contributor also reproduced it on Linux with /bin/pwd.

  • I added terminal-startup-cwd.test.ts, which covers a relative backslash name, .. from a root with a backslash in it, and the workspace-root inside check. All three fail on main.

  • I ran the targeted vitest for src/shared/shell/launch/ and cross-platform-path.test.ts. The existing Windows drive and UNC coverage passes.

  • These pass on the touched files: oxlint (anti-slop and code-quality native plugins), ast-grep, oxfmt, and the changed-code quality gate.

  • Windows, WSL and SSH were checked by reviewing the source and sampling path pairs. Explicit Windows paths keep their old interpretation.

Performance

None. This only runs once each time a terminal starts. It does the same filesystem probes as before, and choosing the flavor is two string checks. Microbenchmark, old vs new, in ns per resolveTerminalStartupCwd call: sub/dir 314 vs 296, <root>/reports\2026 342 vs 239, C:\r + ..\y\z 378 vs 379. An adversarial 2.6 KB input took 46.3 µs before and 20.5 µs after. No new I/O, subprocesses or polling.

Risk

Level: Low. In a POSIX workspace, a relative startup cwd that uses Windows separators (sub\dir) now keeps the backslash as part of the name. If no such folder exists, it falls back to the workspace root as before. Workspaces whose root looks like a Windows path, and requests with a drive letter or UNC prefix, use the Windows rules as before. Other resolveRuntimePath callers keep the default inference. There are no storage, protocol or remote-compat changes, and a plain revert backs it out.

Review

Reviewed in the bug-bash pass. A maintainer follow-up simplified how the flavor is picked and tightened the tests.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Original fix by @SeungWoonSong in #52558. Their authorship is kept on the squashed commit.

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance. The path flavor comes from the workspace path syntax, not the client OS, so SSH workspaces on POSIX hosts are fixed the same way.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Terminal startup now preserves literal backslashes in POSIX folder names.

  • Terminal startup keeps backslashes in POSIX folder names.

Reviews (2) · Last reviewed commit: "fix(terminal): preserve backslashes in P..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Path resolution now accepts a path flavor and preserves literal backslashes in POSIX paths. Terminal startup selects Windows handling when either the workspace path or requested cwd is Windows-absolute-like; otherwise, it selects POSIX handling. Tests cover POSIX paths containing backslashes and a relative ../reports cwd.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to cd00d

This change makes Open in Terminal start in Linux folders whose names contain a literal backslash, instead of falling back to the workspace root. Windows and UNC path handling is unchanged. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed [#52557] Requirement: Open in Terminal from a Linux folder whose name contains a literal backslash must start the shell in that folder. At the reviewed head, resolveTerminalStartupCwd (src/shared/shel…
Out of Scope Changes check Passed The changes touch src/shared/file-access/cross-platform-path.ts (optional pathFlavor parameter on resolveRuntimePath, with POSIX-aware separator handling in normalization), src/shared/shell/launch/ter…
Title check Passed The title names the main change: terminal startup cwd on POSIX keeps literal backslashes in folder names. It matches the changeset in terminal-startup-cwd.ts and cross-platform-path.ts, and it follows…
Description check Passed The description follows the repository template. It has ELI5, What Changed, Why, Linked Issue (Fixes #52557), Visual Proof (a before/after probe output, with no UI change explained), Testing with chec…
Full details: Linked Issues check

Explanation

[#52557] Requirement: Open in Terminal from a Linux folder whose name contains a literal backslash must start the shell in that folder. At the reviewed head, resolveTerminalStartupCwd (src/shared/shell/launch/terminal-startup-cwd.ts) selects pathFlavor 'windows' only when the worktree path or the trimmed requested cwd is Windows-absolute-like (isWindowsAbsolutePathLike). Otherwise it selects 'posix' and passes that flavor to resolveRuntimePath. For a POSIX workspace, a relative request such as 'reports\2026' resolves to '<workspace>/reports\2026', and an absolute request such as '<workspace>/reports\2026' keeps the backslash. The missing-directory fallback is unchanged. Windows drive, UNC, and WSL UNC inputs still select the windows flavor. The author reports that both POSIX regression tests fail on main and pass with the fix, and reports a Linux run with a real directory and /bin/pwd. I did not read the test file, so the test evidence is author-reported. The coding requirement is met by the code path shown.

Full details: Out of Scope Changes check

Explanation

The changes touch src/shared/file-access/cross-platform-path.ts (optional pathFlavor parameter on resolveRuntimePath, with POSIX-aware separator handling in normalization), src/shared/shell/launch/terminal-startup-cwd.ts (flavor selection), and their tests. The resolver parameter is the mechanism that #52557 requires, and the terminal startup test changes cover the new behavior. No change is unconnected to #52557. The default flavor of resolveRuntimePath still selects windows when either input contains a backslash, so two-argument callers keep their prior behavior for those inputs. The author's claim of matching main across 576 sampled path pairs is not verified here. The whole-PR diff and the merge-base blob could not be read in this review, so the base-to-head comparison relies on the head file and the supplied summary. The disclosed risk for Windows-style relative separators with a POSIX base is a stated behavior change tied to this fix, not an unrelated change.

Full details: Title check

Explanation

The title names the main change: terminal startup cwd on POSIX keeps literal backslashes in folder names. It matches the changeset in terminal-startup-cwd.ts and cross-platform-path.ts, and it follows the conventional fix(scope) form. Its length (69 characters) is acceptable.

Full details: Description check

Explanation

The description follows the repository template. It has ELI5, What Changed, Why, Linked Issue (Fixes #52557), Visual Proof (a before/after probe output, with no UI change explained), Testing with checkboxes, Performance (None, because ... with measurements), Risk with level Low and a revert path, Agent skill boundary, Notes, and Checklist. The Review section is brief. The AI Disclosure section is left empty, which the template allows for internal contributors but which is unclear for an outside contributor. The Linked Issue and Testing sections are complete. The description is thorough and mostly complete.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b38f5714-3812-417a-96d2-8ce4bd4cb49c
Commits

Reviewing files that changed from the base of the PR and between 51e3ff9 and cd00d2b.

Files selected for processing: 2

  • src/shared/shell/launch/terminal-startup-cwd.test.ts
  • src/shared/shell/launch/terminal-startup-cwd.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Terminal startup inferred Windows path flavor from any backslash in the
requested cwd, so a valid Linux folder such as `reports\2026` was
rewritten to `reports/2026`, failed the existence check, and fell back to
the workspace root. Startup now picks Windows flavor only for
Windows-absolute roots or requests, and the shared resolver keeps
backslashes literal under POSIX flavor.

Fixes stablyai#52557

Co-authored-by: Neil <[email protected]>
@nwparker
nwparker force-pushed the fix/terminal-preserve-posix-backslash-cwd branch from 51e3ff9 to cd00d2b Compare November 29, 2026 16:42
@nwparker nwparker changed the title fix(terminal): preserve backslashes in POSIX startup cwd fix(terminal): keep literal backslashes in POSIX terminal startup cwd Nov 29, 2026
@nwparker
nwparker merged commit 0f17c88 into stablyai:main Nov 29, 2026
58 of 59 checks passed
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]: Open in Terminal falls back to the workspace root for Linux folder names with a backslash

2 participants