Skip to content

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

Open

Description

@MBanucu

What happened

I run the standalone freebuff binary through an explicit ELF interpreter instead of exec'ing it directly (glibc-runner on Termux/Android, no proot). The CLI starts fine, and the in-process file tools work (read/write/edit), but every tool that spawns a process fails:

Terminal command broker failed: terminal command broker protocol response was missing

Restart Freebuff and try again.

code_search fails the same way:

Failed to execute ripgrep: ENOENT: no such file or directory,
posix_spawn '/data/data/com.termux/files/usr/glibc/lib/rg'.
Vendored ripgrep not found; ensure @codebuff/sdk is up-to-date or set CODEBUFF_RG_PATH.

freebuff doctor passes, because it never exercises the broker.

This is not a request for official Termux support — the bug is generic to any launch that goes through a loader rather than direct execve() of the bundle, which is also how some Nix wrappers and sandboxed launchers work.

Steps to reproduce

Any Linux, with the standalone binary:

# works (direct exec):
~/.config/manicode/freebuff

# starts, but every tool that spawns a command fails:
$PREFIX/glibc/bin/ld.so --library-path $PREFIX/glibc/lib ~/.config/manicode/freebuff

Then ask the agent to run any command (e.g. echo ok). File tools keep working; shell/git/code search do not.

Environment: Termux (unrooted), Android 15, aarch64; freebuff 0.2.36 standalone binary (npm launcher output) run through glibc 2.44 from glibc-runner 2.0-3.

Why it fails

When a program is started as ld.so prog, the kernel's main executable is the loader, so /proc/self/exe — and therefore process.execPath — is the loader, not the bundle:

$ $PREFIX/glibc/bin/ld.so --library-path $PREFIX/glibc/lib $PREFIX/glibc/bin/bash -c 'readlink /proc/$$/exe'
/data/data/com.termux/files/usr/glibc/lib/ld-linux-aarch64.so.1

cli/src/utils/terminal-command-broker.ts (defaultBrokerInvocation) spawns the broker with executable: process.execPath. The child that actually runs is therefore:

$ $PREFIX/glibc/bin/ld.so --terminal-command-broker
ld.so: unrecognized option '--terminal-command-broker'

ld.so exits immediately without writing the protocol file. Because the exec itself succeeds (it is the loader that fails), no spawn error is emitted; the parent only sees the missing result file and reports protocol response was missing.

cli/src/native/ripgrep.ts makes the same assumption: in compiled mode it extracts/looks for rg in path.dirname(process.execPath), i.e. $PREFIX/glibc/lib/rg, which does not exist — hence the posix_spawn .../glibc/lib/rg ENOENT. packages/code-map/src/init-node.ts and cli/src/pre-init/tree-sitter-wasm.ts also derive asset locations from dirname(process.execPath).

Suggested fix

  • Preferred: run the broker in-process (or as a worker) instead of re-exec'ing the bundle.
  • If a separate process is required, resolve the bundle path independently of process.execPath — e.g. process.argv[0]/process.argv0 when it points at the bundle, or detect a loader (ld-linux*, ld.so*) and re-exec through it: [execPath, '--library-path', dirname(execPath), bundlePath, TERMINAL_COMMAND_BROKER_FLAG].
  • Or expose an override for the broker command, mirroring CODEBUFF_RG_PATH, so launchers that exec via a loader can supply the correct command line.
  • Apply the same resolution to the dirname(process.execPath) lookups for rg and tree-sitter.wasm.

Workaround

CODEBUFF_RG_PATH=~/.config/manicode/rg fixes code search only. Nothing I can set in this environment fixes the broker, because its executable path comes from process.execPath; the CLI has to be launched through proot instead, which defeats the point of running it natively.

Logs

Terminal tool result as surfaced in the session:

Terminal command broker failed: terminal command broker protocol response was missing

Restart Freebuff and try again.

Repeating the call produces the same result; restarting Freebuff does not change it.

Activity

  1. MBanucu commented on Nov 18, 2026

    @MBanucu
    Author

    FWIW, I kept the repro and the workaround in a small project: https://github.com/MBanucu/freebuff-native-termux

    The relevant piece for this issue is shim/freebuff-spawn-shim.c, a freestanding LD_PRELOAD object that rewrites exactly one exec — path == process.execPath (the loader) plus --terminal-command-broker — into ld.so --library-path DIR BINARY --terminal-command-broker. With it the protocol file comes back as {"ok":true,"exitCode":0}; code_search is fixed separately with CODEBUFF_RG_PATH, as you suggested. test/shim-test.sh asserts the rewritten argv and that children don't inherit the preload, so it can serve as a spec for a real fix.

    Not proposing the preload hook as the fix — it just confirms the failure is confined to how the broker resolves its executable. Happy to test a patch that resolves the bundle independently of process.execPath.

  2. added
    area:cli
    bot:triaged
    type:bug
    on Nov 18, 2026
  3. MBanucu commented on Nov 18, 2026

    @MBanucu
    Author

    For anyone hitting this on Termux: the cause is exactly what the title says. When the binary is started through the glibc loader (ld-linux-aarch64.so.1 --library-path … freebuff), process.execPath is the loader, so the broker re-exec sends --terminal-command-broker to the loader, which rejects it before it can write its result file. The same dirname(process.execPath) assumption is what breaks the ripgrep extraction.

    I have a workaround working on aarch64 against 0.2.36, on a stock Termux userland (no proot, no ptrace, no second userland): a small LD_PRELOAD shim that rewrites that one exec into

    ld.so --library-path <libdir> <binary> --terminal-command-broker
    

    and strips LD_PRELOAD from child environments so bionic sh/git/rg start normally. The freebuff binary is used untouched.

    This is a workaround, not a fix. The real fix is probably one of:

    1. resolve the interpreter when execPath is a loader and re-exec <loader> --library-path … <entry> --terminal-command-broker, or
    2. pass the entry script explicitly to the broker spawn instead of relying on process.execPath, or
    3. take the broker path from process.argv[1] when execPath resolves to a dynamic loader.

    I'm not asking you to host or adopt the shim. If someone wants to iterate on a real fix, I'm happy to test patches against 0.2.36 on the device and report back.

  4. added a commit that references this issue on Dec 4, 2026
    aeedd5f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibot:triagedtype:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions