Skip to content

fix(cli): start on Windows when USERPROFILE is empty - #2345

Merged
morluto merged 4 commits into
morluto:mainfrom
gefrezim:fix/windows-empty-userprofile-startup
Oct 13, 2026
Merged

morluto merged 4 commits into
morluto:mainfrom
gefrezim:fix/windows-empty-userprofile-startup

Conversation

@gefrezim

@gefrezim gefrezim commented Oct 12, 2026 •

Copy link
Copy Markdown

Summary

On Windows, an empty USERPROFILE stops every rea command at startup, including rea --version, with a raw Node stack trace. This makes the launcher treat that empty selection as unset so the CLI starts and resolves the account profile.

Related to #2325 / #2332 (empty home selections), but a separate failure: the crash happens while Incur is imported, before homeDirectoryFromEnvironment runs, so the Windows fallback added in #2332 is not reachable from the real CLI without this.

Problem and expected behavior

Smallest trigger, native Windows, current main:

$ USERPROFILE="" node scripts/rea.mjs --version     # Git Bash on Windows
file:///.../node_modules/incur/dist/internal/agents.js:4
const home = os.homedir();
                ^
SystemError [ERR_SYSTEM_ERROR]: A system error occurred: uv_os_homedir returned ENOENT (no such file or directory)

Node's os.homedir() on Windows throws for a set-but-empty USERPROFILE instead of consulting the account profile (os.userInfo().homedir still returns it). incur/dist/internal/agents.js calls os.homedir() at module scope, so the import in scripts/rea.mjs rejects.

Expected: an empty USERPROFILE behaves like an unset one, as #2325 describes for HOME.

Change and scope

scripts/rea.mjs deletes an empty USERPROFILE from process.env on win32 before any runtime import. The launcher is the earliest stage and the only one that runs before Incur's import-time lookup. Node then falls back to the account profile, and REA's own resolver sees the variable as unset.

Not included: POSIX HOME handling (owned by #2332), any change to Incur, and relative non-empty home values.

Follow the contribution scope: not applicable, ordinary fix within existing boundaries.

Contract and boundary impact

  • Semantic owner and earliest changed stage: executable dispatcher (scripts/rea.mjs), before runtime imports.
  • Contribution scope fit and linked maintainer decision: not applicable (startup fix).
  • CLI and MCP/tool-catalog contract: none; commands that previously crashed now start.
  • Provider, bridge, target-format, or platform compatibility: Windows only; the branch is not taken on other platforms.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/cli/emptyHomeStartup.test.ts runs the compiled CLI with HOME="" and USERPROFILE="" and expects --version and --help to succeed.
  • Base reproduction or other evidence: executed on native Windows 11, Node 24.21.0. On unmodified main (1c37914) --version, doctor --json, setup --client cursor --yes --dry-run --json and mcp doctor all exit 1 with the uv_os_homedir error. With the launcher change reverted, the new test fails on that same error; with it, the test passes.
  • User-visible CLI/MCP output (if applicable): with the fix, USERPROFILE="" rea --version prints the version, and setup --dry-run plans against the account profile (C:\Users\<account>\.cursor\mcp.json).
  • Remaining proof gaps: the regression only exercises the failing path on a Windows runner; on POSIX it passes before and after. --mcp server mode was not exercised (the launcher change applies before that branch).

Validation performed

  • npm run build:cached — passed
  • npx vitest run tests/boundary/cli/emptyHomeStartup.test.ts — 1 passed (fails without the launcher change)
  • npm run check:fast — typecheck and lint passed
  • npm run verify:test-discovery — all test files discovered exactly once
  • npx oxfmt --check on both changed files — passed
  • Not run: the full suite, npm run check, npm run check:pr.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: native Windows 11 only; no provider involved.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: removes one empty variable from the launcher's own environment on Windows; no new paths, processes or network access.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

Node's Windows home lookup throws ERR_SYSTEM_ERROR (uv_os_homedir ENOENT)
for an empty USERPROFILE instead of consulting the account profile. Incur
resolves the home while it is imported, so every command, including
`rea --version`, stopped with a raw stack trace before REA ran.

Treat the empty selection as unset in the launcher, before any runtime
import, and cover startup with a compiled-CLI regression.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

N0zoM1z0 added a commit that referenced this pull request Oct 13, 2026
Follow-up to #2345; thanks to @gefrezim for the import-time home lookup diagnosis.

Normalize only an empty Windows USERPROFILE before runtime dependency imports, preserving all nonempty caller selections. Reuse the existing public setup dry-run regression in the Windows curated CI lane. No additional filesystem query, engine call, cache or retry.

Verified real Windows Node 24.18.0 CLI unset/empty/selected-profile controls, setup dry-run home selection and unchanged configuration, and baseline/candidate SDK stdio MCP catalogue parity. Nine related tests and static/docs checks passed. No IDA or Ghidra engine was used. Scoped resource observations and measurement limits are recorded in experiments/analysis-efficiency/windows-empty-profile.md.

Fixed the review finding and original CI package-scope ownership failure. Current-head CI is green; the unrelated MCP identity timeout passed on a failed-job rerun without changing its code or timeout. Current-head review completed with no further findings.
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

@greptileai review

@greptile-apps

greptile-apps Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

This PR is set for a Plus review. TREX isn't supported with Plus or Apex reviews yet, so Greptile reviews this PR at Base while TREX is on.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The current diff appears safe to merge.

Summary

The Windows launcher fix is already present in the target commit. This PR now adds regression coverage for empty home variables and a defensive zero-budget check in ProviderStartupDeadline.remainingMs().

  • A timed-out provider startup deadline reports no time left.
  • CLI tests now cover version and help with empty home variables.

Reviews (4) · Last reviewed commit: "test(process): retain fractional deadlin..." · Reviewed by Greptile

morluto and others added 2 commits October 13, 2026 19:55
Node timers can fire while performance.now() is still a fraction of a
millisecond short of the monotonic deadline. ProviderStartupDeadline then
reported interruption "timeout" and an aborted signal while remainingMs()
returned ceil(0.x) = 1, so polling loops guarded by remainingMs() > 0
(Hopper and Ghidra startup) could run past an elapsed deadline, and the
real-timer test "aborts a bounded wait when its real monotonic deadline
expires" failed intermittently in CI (expected 1 to be 0).

Once the deadline's own timer has classified a timeout, report zero
remaining time. A deterministic regression test fires the timer with the
monotonic clock 0.4 ms short of the deadline.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@morluto morluto added bug Something isn't working area: cli CLI adapter and one-shot commands area: runtime Process capture and runtime observation P2: medium Medium priority issue labels Oct 13, 2026
@morluto
morluto merged commit d4f0c5e into morluto:main Oct 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands area: runtime Process capture and runtime observation bug Something isn't working P2: medium Medium priority issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants