Skip to content

fix(startup): restore Windows PATH before shell changes - #13792

Merged
Jinwoo-H merged 1 commit into
mainfrom
OrcaWin/sta-3889-windows-path-restore
Aug 11, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
OrcaWin/sta-3889-windows-path-restore

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • restore the complete prehydration Windows PATH before a configured-shell change or forced profile probe
  • keep newly installed registry PATH entries that are appended after hydration, while discarding prior shell-owned ordering and entries
  • add a physical-Windows regression oracle that checks the exact PATH array and real cmd.exe resolution across PowerShell/Git Bash-style A→B transitions

Linear: STA-3889
Supersedes the PATH cleanup behavior introduced by #13418.

Root cause

mergePathSegments promoted every shell segment, including inherited entries, but cleanup tracked only segments absent from the premerge PATH. Shell A could therefore reorder inherited directories without owning that reorder. Shell B then inherited A's reordered process PATH and resolved an overlapping executable from A.

The fix records the full baseline and exact applied PATH for one hydration application. Restore reestablishes the baseline before the next probe/merge and carries forward only case-insensitively new entries. That exception matches the existing Windows preflight behavior, which appends newly installed registry PATH entries to the live process.

Reproduction and oracle

The byte-identical oracle test blob (2bbf094fb9b00540ce70bb32ea677c33882e97dd) was exercised against:

  • target 56b6d84 / latest main 3713dd7376: same hydration source blobs; red with [B-profile, A, B], and real cmd.exe selected shell A
  • candidate: 6/6 green with [B-profile, B, A], and real cmd.exe selected shell B
  • candidate with only the production fix reverted: 5/6 red, including exact ordering, executable selection, cmd/WSL restoration, external append, and forced-refresh cases
  • restored candidate: 6/6 green again

The suite also covers concurrent generation fencing, PATH/Path casing, case-insensitive duplicates, drive roots, UNC shares, cmd, WSL, and external registry-style additions. Existing focused tests cover PowerShell and Git Bash probe behavior.

Testing

  • pnpm run typecheck
  • 13 affected files: 126 passed, 1 intentional skip
  • core hydration matrix: 55 passed
  • touched-file oxlint --deny-warnings
  • pnpm run check:reliability-gates
  • pnpm run check:max-lines-ratchet
  • commit hooks (oxlint, react-doctor lint, oxfmt)
  • pnpm test — repository-wide Windows run completed with broad pre-existing platform failures unrelated to this diff, including /bin/sh assumptions, POSIX path expectations, symlink cases, and unrelated source/snapshot assertions; the affected matrix above is green
  • pnpm run check:code-quality:changed — wrapper fails on this host with spawnSync pnpm.cmd EINVAL; its exact underlying oxlint scan passes directly

Electron UI automation was intentionally skipped: this is main-process executable resolution with no visual change, and a visible proof would require modifying real user shell profiles while providing weaker evidence than the deterministic real-process oracle.

Compatibility and policy

  • Windows-only ownership is runtime-gated; the real-process test is also Windows-gated
  • WSL agent detection remains guest-isolated; switching to WSL restores the native host baseline
  • SSH resolves on the SSH host; paired runtimes apply the same process-local fix on their own host
  • folder workspaces and git worktrees share the corrected local process environment
  • macOS/Linux merge behavior is unchanged
  • no RPC, stream, persisted schema, dependency, authentication, or permission change

Performance and review

A delegated performance audit measured restoration at 0.066 ms for 100 PATH segments and 0.793 ms for 1,000 (0.834 ms max). The change retains one generation (two PATH strings plus one key), adds no subprocess, listener, timer, polling, IPC, or network work.

Three fresh adversarial review rounds ran. Round 1 added the CLI TypeScript project entry; Round 2 gated the real Windows oracle off non-Windows CI; both independent Round 3 lanes returned clean. The final internal review found no in-scope issue or future-PR suggestion.

@coderabbitai

coderabbitai Bot commented Aug 11, 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 Plus

Run ID: 67b5835e-3b7d-48ac-ac7b-1b343cac5d01

📥 Commits

Reviewing files that changed from the base of the PR and between 1f2e18a and 3fed395.

📒 Files selected for processing (6)
  • config/tsconfig.cli.json
  • src/main/startup/hydrate-shell-path.test.ts
  • src/main/startup/hydrate-shell-path.ts
  • src/main/startup/windows-shell-path-ownership.test.ts
  • src/main/startup/windows-shell-path-ownership.ts
  • src/main/startup/windows-shell-path-restoration.windows.test.ts

📝 Walkthrough

Walkthrough

The change adds Windows PATH ownership management. It tracks baseline and application-applied PATH values, preserves externally added segments, and restores PATH state across shell probes and configuration changes. Shell hydration now supports both PATH and Path keys and uses shared Windows path normalization. Tests cover ownership behavior, shell switching, asynchronous generation fencing, exact PATH formatting, external entries, cache isolation, and failed hydration. The CLI TypeScript configuration includes the new module.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the primary change: restoring Windows PATH state before shell changes.
Description check ✅ Passed The description clearly explains the root cause, fix, compatibility impact, testing, and known environment-specific limitations.
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 💡 1
📝 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.

@Jinwoo-H
Jinwoo-H merged commit c96ded8 into main Aug 11, 2026
45 checks passed
@Jinwoo-H
Jinwoo-H deleted the OrcaWin/sta-3889-windows-path-restore branch August 11, 2026 18:50
zpyoung pushed a commit to zpyoung/orca that referenced this pull request Aug 14, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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.

2 participants