fix(staged): preserve ACP launch environments - #849
Merged
Conversation
…ions Local ACP sessions were launched via an attached interactive `$SHELL -ils` that piped `exec <agent-binary>` to stdin, relying on `precmd`/`chpwd` firing to activate Hermit. Empirically that path lands Homebrew ahead of Hermit, so the agent (and every per-command shell it spawns) resolved the wrong toolchain (e.g. cargo 1.95.0 instead of the pinned 1.96.1), diverging from pipeline steps and git ops which already draw from the ShellEnvCache. Instead, capture the interactive-login-shell env snapshot for the session's working directory — the same cached, Hermit-first snapshot pipeline steps and git ops use — and apply it directly to the agent binary (env_clear + captured vars), the way ShellEnv::apply_to does for pipeline steps. The agent's starting environment is the single determinant for everything it runs, so a Hermit-first snapshot propagates into its per-command shells too. - AcpDriver gains an env_snapshot field + with_env_snapshot builder; when set, the local branch spawns the binary directly instead of the `$SHELL -ils` + `exec` dance. The agent binary's own dir is still pinned onto PATH so its bundled interpreter (e.g. node) stays findable. - session_runner passes the ShellEnvCache snapshot for local sessions; remote/workspace sessions and any capture failure fall back to the old shell spawn. This keeps the agent, pipeline steps, and git ops all drawing from one env (consistency), resolves the pinned toolchain (correctness), and skips the per-session interactive-shell spawn (speed). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Matt Toohey <contact@matttoohey.com>
Only add the ACP agent binary directory when an env-shebang launcher cannot resolve its interpreter from the captured or shell-initialized PATH. Preserve Hermit-first snapshots and append broad toolchain directories such as /opt/homebrew/bin only as fallbacks. Cover the guarded direct-spawn and shell fallback behavior with ACP driver tests. Signed-off-by: Matt Toohey <contact@matttoohey.com>
Signed-off-by: Matt Toohey <contact@matttoohey.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.
Applies captured environment snapshots to local ACP launches, keeps guarded PATH fallbacks behind project-managed toolchains, and preserves inherited environments for remote sq ACP proxy sessions.