fix(staged): keep ACP agent alive by pinning its dir on PATH + log stderr#760
Merged
Conversation
…derr Starting a Claude ACP session could fail with an opaque "ACP init failed: server shut down unexpectedly". The agent subprocess was dying before the `initialize` response because `claude-agent-acp` is a `#!/usr/bin/env node` script, and the session working directory's clean-env login shell did not always expose a compatible `node` on PATH (Hermit/direnv can replace PATH, nvm may not activate). The shebang then failed with `env: node: No such file or directory` and the process exited instantly. Two fixes: - Prepend the resolved agent binary's own directory to PATH in the `exec` line so the interpreter that ships alongside the binary is always found, regardless of the session dir's shell init. - Stop discarding the agent's stderr (was `Stdio::null`); pipe it and drain it to the log. The failed-shebang message and any shell-init errors are now visible instead of surfacing only as "server shut down unexpectedly". Not a version issue: claude-agent-acp 0.39.0 is current and the negotiated protocol version (V1) matches. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
Starting a Claude ACP session in the staged app could fail with an opaque error:
The agent subprocess was dying before responding to the
initializehandshake. Root cause:claude-agent-acpis a#!/usr/bin/env nodescript, and the agent isexec'd inside the session's working directory through a clean-env (env_clear) login shell. If that directory's shell init doesn't put a compatiblenodeon PATH (Hermit/direnv can replace PATH, nvm may not activate), the shebang fails withenv: node: No such file or directory(exit 127) and the process exits instantly. Its stdout closes before theinitializeresponse → the client reports "server shut down unexpectedly".It was hard to diagnose because the agent's stderr was sent to
/dev/null, hiding the realenv: node: ...message.Not a version issue:
claude-agent-acp0.39.0 is the latest, and the negotiated protocol version (ProtocolVersion::LATEST= V1) matches what the agent speaks.Fix
In
crates/acp-client/src/driver.rs:Pin the agent binary's directory on PATH for the
exec. The exec line is nowexec env PATH=<binary_dir>:"$PATH" <binary> <args>. Since the resolved binary lives in a node bin dir that also containsnode, this guarantees the shebang's interpreter is always found regardless of what the session dir's shell init does. Falls back to the plain form if the binary has no parent dir.Stop discarding the agent's stderr. Changed
Stdio::null()→Stdio::piped()and drain it line-by-line intolog::warn!(tagged with agent label + session id). Future spawn/shebang/shell-init failures are now visible instead of vanishing.Verification
cargo checkandcargo test -p acp-clientpass (16 tests).env: node: No such file or directory, exit 127) withnodestripped from PATH, then confirmed the new exec line negotiatesinitializesuccessfully under the same stripped PATH.🤖 Generated with Claude Code