Skip to content

Fix process.execPath resolution when launched via an ELF loader - #1800

Open
YrFnS wants to merge 3 commits into
CodebuffAI:mainfrom
YrFnS:fix/elf-loader-exec-path
Open

YrFnS wants to merge 3 commits into
CodebuffAI:mainfrom
YrFnS:fix/elf-loader-exec-path

Conversation

@YrFnS

@YrFnS YrFnS commented Dec 4, 2026

Copy link
Copy Markdown

Resolves the on-disk bundle path independently of process.execPath, which points at the loader (e.g. ld.so) when the CLI is started through an ELF interpreter. Applies the resolved path to ripgrep extraction, tree-sitter.wasm lookup, smoke diagnostics, and re-execution of the terminal command broker (preserving loader arguments), plus code-map's tree-sitter lookup.

Fixes #1688

Resolve the on-disk bundle path independently of process.execPath, which
points at the loader (e.g. ld.so) when the CLI is started through an ELF
interpreter. Applies the resolved path to ripgrep extraction, tree-sitter.wasm
lookup, smoke diagnostics, and re-execution of the terminal command broker
(preserving loader arguments), plus code-map's tree-sitter lookup.

Fixes CodebuffAI#1688
@YrFnS
YrFnS force-pushed the fix/elf-loader-exec-path branch from 8db3536 to aeedd5f Compare December 4, 2026 09:41
@codebuff-team

Copy link
Copy Markdown
Contributor

Good find and a well-reasoned fix for issue #1688 — process.execPath pointing at ld.so instead of the bundle itself is a real class of bug in compiled Bun binaries, and the existing comment in tree-sitter-wasm.ts already hints the team was aware of adjacent issues here. The new cli-binary-path.ts module is clean, has solid unit tests covering direct exec, loader exec, and the loader re-exec path with preserved library-path args, and the integration points (ripgrep extraction, tree-sitter wasm lookup, diagnostics, terminal-command-broker re-exec) all make sense.

Two concerns:

  1. packages/code-map/src/init-node.ts reimplements isElfLoaderPath/resolveBundlePathForExec inline rather than importing from cli/src/utils/cli-binary-path.ts. I understand code-map likely can't depend on cli, but this duplication (including the loader-basename heuristics) will drift over time — consider hoisting the shared logic into a lower-level package (e.g. @codebuff/common) that both can depend on, especially since it has no test coverage in this location.

  2. The loader-basename detection (ld.so, ld-linux*, ld-musl*, ld64.so.2) is a heuristic and may miss some distro-specific loader names (e.g. versioned glibc loaders like ld-2.31.so on older systems, or custom interpreter paths set via --dynamic-linker). Worth documenting this limitation or making the fallback-to-first-existing-file logic a bit more defensive given it's now load-bearing for binary distribution.

Overall the change is scoped correctly, doesn't touch any forbidden paths, and is testable — recommend porting with the code-map duplication flagged for follow-up.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree labels Dec 4, 2026
Move cli-binary-path into @codebuff/common so code-map uses the same
implementation (and tests) instead of an inline copy. Recognize versioned
glibc, uClibc and ld.so.N loaders, and document that detection is by file
name only.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terminal broker and ripgrep break when the CLI is launched through an ELF loader (process.execPath is the loader)

2 participants