Skip to content

fix(pty): probe Windows PATH registry via absolute reg.exe#8994

Open
xianjianlf2 wants to merge 1 commit into
stablyai:mainfrom
xianjianlf2:fix/inapp-terminal-cursor-cli-path-8834
Open

fix(pty): probe Windows PATH registry via absolute reg.exe#8994
xianjianlf2 wants to merge 1 commit into
stablyai:mainfrom
xianjianlf2:fix/inapp-terminal-cursor-cli-path-8834

Conversation

@xianjianlf2

Copy link
Copy Markdown
Contributor

The Windows in-app terminal refreshes its PATH from the persisted Environment registry keys (HKLM/HKCU) at spawn time, so newly installed CLIs resolve without an app restart (readPersistedWindowsPathSegmentsbuildPtyHostEnv). That probe shelled out with a bare reg.exe.

When Electron's main process inherits a PATH that omits System32 (Start Menu and service launches), a bare reg.exe through execFileSync/libuv throws ENOENT. node-pty spawns the shell via ConPTY, which always searches System32, so the terminal itself still opens — but the registry probe silently fails (its additions are swallowed by the catch), leaving the in-app terminal on only the stale launch-time PATH. A CLI installed into a directory that a fresh system terminal picks up from the registry — e.g. the Cursor agent CLI — then reports 'agent' is not recognized as an internal or external command, while the exact same command works in a system terminal.

Fix: resolve reg.exe by its absolute System32 path, matching the existing icacls/whoami/cmd handling in win32-utils.ts (added there for this exact stripped-PATH reason).

  • Added getRegExePath() to win32-utils.ts.
  • windows-environment-path.ts now uses it.
  • Unit test asserts the probe invokes the absolute System32 reg.exe, so a stripped Electron PATH still reaches the registry.

This is a correct, codebase-consistent hardening of the registry-refresh path. I could not reproduce on Windows, so I'm referencing rather than closing the issue — a maintainer can confirm it resolves the reporter's exact trigger.

Refs #8834

X: @mark86202384100

The in-app terminal on Windows refreshes its PATH from the persisted
Environment registry keys (HKLM/HKCU) so newly installed CLIs resolve
without an app restart. That probe shells out with a bare `reg.exe`.

When Electron's main process inherits a PATH that omits System32 (Start
Menu and service launches), a bare `reg.exe` through execFileSync/libuv
throws ENOENT. node-pty spawns the shell via ConPTY, which always
searches System32, so the terminal itself still opens -- but the registry
probe silently fails and its additions are dropped. The in-app terminal
is then left with only the stale launch-time PATH, so a CLI installed
into a directory that a fresh system terminal picks up from the registry
(e.g. the Cursor `agent` CLI) reports "not recognized as an internal or
external command", while the same command works in a system terminal.

Resolve reg.exe by its absolute System32 path, matching the existing
icacls/whoami/cmd handling in win32-utils.ts.

Closes stablyai#8834
@coderabbitai

coderabbitai Bot commented Jul 16, 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: 17259826-e3d6-462d-b63d-2445c09bfd17

📥 Commits

Reviewing files that changed from the base of the PR and between cf02cc4 and 59cae5a.

📒 Files selected for processing (3)
  • src/main/pty/windows-environment-path.test.ts
  • src/main/pty/windows-environment-path.ts
  • src/main/win32-utils.ts

📝 Walkthrough

Walkthrough

Adds getRegExePath to construct an absolute Windows reg.exe path from SystemRoot, with a fallback to C:\Windows. Updates persisted PATH registry reads to use this helper and adds a test verifying both registry queries use the absolute executable path.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the fix, but it misses the required template sections for Screenshots, Testing, AI Review Report, Security Audit, and Notes. Reformat the PR description to match the template and add the missing sections, including screenshots status, testing checklist, AI review, security audit, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title succinctly and accurately summarizes the main change: using an absolute reg.exe path for the Windows PATH registry probe.
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.

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.

@AmethystLiang
AmethystLiang requested a review from Jinwoo-H July 16, 2026 17:17
@AmethystLiang AmethystLiang assigned OrcaWin and unassigned Jinwoo-H Jul 20, 2026
@AmethystLiang
AmethystLiang requested review from OrcaWin and removed request for Jinwoo-H July 20, 2026 18:37
andrewyatesai pushed a commit to andrewyatesai/orca-alab that referenced this pull request Jul 21, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

3 participants