Skip to content

fix(context): stop crashing when the working directory was deleted (CLI-1XG) - #1642

Merged
BYK merged 1 commit into
mainfrom
cursor/fix-deleted-cwd-crash-fe99
Sep 28, 2026
Merged

BYK merged 1 commit into
mainfrom
cursor/fix-deleted-cwd-crash-fe99

Conversation

@cursor

@cursor cursor Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Sentry issue: CLI-1XG

Fixes CLI-1XG

Root cause

buildContext() in src/context.ts called process.cwd() without a guard, so once the CLI's starting directory has been removed, Node throws ENOENT: process.cwd failed ... uv_cwd before any command runs.

Reproduction

mkdir /tmp/gone && cd /tmp/gone && rmdir /tmp/gone
sentry --version   # Error: ENOENT: process.cwd failed ... uv_cwd (exit 1)
sentry auth status # same crash

This mostly affects agents running inside a git worktree that got cleaned up underneath them. Every command crashes, even ones that never touch the filesystem, and each crash is reported as an unexpected error.

Fix

resolveCwd() falls back to the shell's logical PWD when process.cwd() throws. PWD still names the deleted directory, so:

  • lookups under the missing path find nothing (DSN and project-root checks already treat ENOENT as expected);
  • commands with explicit targets, and ones that don't need local files, work normally;
  • auto-detection fails with the usual ContextError instead of crashing.

If PWD is missing or not absolute, the original error is rethrown, so that case behaves exactly as before. The fallback never substitutes a different existing directory (home, /), because commands like init and build download write into cwd.

Checked against the npm bundle, run from a deleted directory:

Command Before After
sentry --version ENOENT crash, exit 1 0.46.0-dev.0, exit 0
sentry auth status ENOENT crash, exit 1 "Not authenticated", exit 10
sentry issue list (with token) ENOENT crash, exit 1 "Could not auto-detect organization and project", exit 22

Tests

  • New test/lib/context.test.ts covers the PWD fallback and the rethrow when PWD is empty or relative. The fallback test fails without the fix.
  • vitest run test/lib test/commands test/types test/script: 9986 passed, 1 failed. The failure is delta-upgrade.mocked.test.ts, which also fails on origin/main in this environment (zstd/Node version) and is unrelated.
  • biome check and tsc --noEmit pass.
Open in Web View Automation 

…entry CLI-1XG)

buildContext() called process.cwd() unguarded. When the directory the CLI
was started in has been removed (e.g. an agent's git worktree cleaned up
under it), Node throws ENOENT (uv_cwd) and every command, including
--version, crashed before running.

Fall back to the shell's logical PWD, which still names that directory,
when process.cwd() fails. Lookups under the missing path find nothing, so
commands with explicit targets work and auto-detection fails with the
normal ContextError. Without an absolute PWD the original error is
rethrown unchanged.

Fixes CLI-1XG

Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
@vercel

vercel Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Sep 28, 2026 12:17pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Sep 28, 2026 12:17pm UTC

Request Review

@BYK
BYK marked this pull request as ready for review September 28, 2026 12:23
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Sep 28, 2026
@BYK
BYK merged commit 4633458 into main Sep 28, 2026
36 checks passed
@BYK
BYK deleted the cursor/fix-deleted-cwd-crash-fe99 branch September 28, 2026 12:29

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — 2fb52feb Deployed Sep 28, 2026 by vercel[bot]
Preview – sentry-local — 2fb52feb Deployed Sep 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants