fix(cli): robust path/working-dir detection for native image on Linux/WSL #1633
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.
Summary
Fixes an issue where
elide mcp
(and other CLI entrypoints) could fail on WSL/Ubuntu with:Tracking: Fixes #1583
Root cause
In GraalVM native images, initialization of
user.dir
can throw ifgetcwd(2)
fails in certain directories/configurations (seen on WSL). Our CLI startup referencedSystem.getProperty("user.dir")
during early initialization and also relied on the process command path, which may be relative; together, this could surface the native image error on WSL when invoked from particular directories (e.g.,~/elide
).What changed
resolveBinaryPathForNative()
:ProcessHandle.current().info().command()
when absolute; resolve symlinks/proc/self/exe
(absolute, stable)safeWorkingDirectory()
:System.getProperty("user.dir")
/proc/self/cwd
; thenPWD
; thenHOME
; finally.
initializeEntry(...)
when in native-image runtime code:binPath
viaresolveBinaryPathForNative()
safeWorkingDirectory()
toinstallStatics(...)
These fallbacks are only engaged when running as a native image on Linux/WSL; JVM behavior remains unchanged.
Why this works
/proc/self/exe
gives a canonical absolute path to the running binary on Linux/WSL, independent ofuser.dir
./proc/self/cwd
provides an absolute working directory path even ifuser.dir
initialization encountered issues inside SVM, avoiding the "Could not determine current working directory" failure mode.Verification
:packages:cli
successfullyRisk
Low. Changes are guarded for native image runtime and rely on standard Linux
/proc
fallbacks only when needed. No behavioral change for JVM runs.— Augment Code