fix(context): stop crashing when the working directory was deleted (CLI-1XG) - #1642
Merged
Merged
Conversation
…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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
BYK
approved these changes
Sep 28, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sentry issue: CLI-1XG
Fixes CLI-1XG
Root cause
buildContext()insrc/context.tscalledprocess.cwd()without a guard, so once the CLI's starting directory has been removed, Node throwsENOENT: process.cwd failed ... uv_cwdbefore any command runs.Reproduction
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 logicalPWDwhenprocess.cwd()throws.PWDstill names the deleted directory, so:ContextErrorinstead of crashing.If
PWDis 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 likeinitandbuild downloadwrite intocwd.Checked against the npm bundle, run from a deleted directory:
sentry --version0.46.0-dev.0, exit 0sentry auth statussentry issue list(with token)Tests
test/lib/context.test.tscovers thePWDfallback and the rethrow whenPWDis 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 isdelta-upgrade.mocked.test.ts, which also fails onorigin/mainin this environment (zstd/Node version) and is unrelated.biome checkandtsc --noEmitpass.