Skip to content

fix(staged): preserve ACP launch environments - #849

Merged
matt2e merged 3 commits into
mainfrom
wrong-build-cache
Jul 3, 2026
Merged

fix(staged): preserve ACP launch environments#849
matt2e merged 3 commits into
mainfrom
wrong-build-cache

Conversation

@matt2e

@matt2e matt2e commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

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.

matt2e and others added 3 commits July 2, 2026 21:06
…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>
@matt2e
matt2e requested review from baxen and wesbillman as code owners July 3, 2026 01:14
@matt2e
matt2e merged commit d0939eb into main Jul 3, 2026
6 checks passed
@matt2e
matt2e deleted the wrong-build-cache branch July 3, 2026 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant