Repository navigation
Add the ACP client engine: isolated agent launch, handshake, bounded update stream (#4292 stage 1) - #4319
Merged
Conversation
…update stream (stage 1) An in-memory session with one external agent over stdio JSON-RPC: launch through the shared process helpers, initialize with no fs or terminal capability, session/new, prompt turns as typed events, permission requests surfaced (once-only choices), cancellation, and bounds on everything the agent sends. Tested against a scripted fake agent, hostile cases included. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…e a permission waits Credentials sent as JSON escapes bypassed the raw-byte pass; every surfaced string is now cleaned after decoding, redacted before it is cut. The idle clock does not run while a permission request waits and restarts when it is resolved. Tests for both, and for a credential straddling the cut. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
mstomar125
force-pushed
the
issue-4292-session-1
branch
from
November 20, 2026 07:43
37d238f to
e3f932c
Compare
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.
Summary
Stage 1 of the session side of the ACP chat (#4292): the client engine that runs one external agent over stdio and produces an in-memory stream of typed events. Nothing is written to the graph, no gRPC, no UI, nothing launches it yet: inert until stage 2.
Agent-lane sign-off: the user (Mayank) explicitly granted agent-lane sign-off for this build on 2026-11-20 ("you have signoff on each"); it stands in for the agent owner's. This PR touches
packages/agent(newacp/module,lib.rsexport, one accessor on the shared process helper).What is in this PR
New
packages/agent/src/acp/:launch.rs:AcpLaunchdescriptor (program, args, literal env, named daemon env, credential references), validated (no NUL, bounded, valid and non-repeated env names, base variables not overridable).wire.rs:AcpLimits(every bound in one struct),AcpError, and a bounded line reader: a line over the message limit is dropped while it streams past and never held; a byte ceiling is enforced inside the read loop so a stream with no newline cannot grow.events.rs: typed events and update parsing. Tool input/output, diffs and locations are never copied out; the echo of the user's own message is dropped; plan updates render as a markdown checklist; every string is bounded.engine.rs:AcpSession::start(launch +initialize+session/newinside one startup limit, credential lookup included) and an actor that owns the process and connection:prompt,cancel,answer_permission,close.tests.rs: engine tests against a scripted Python fake agent (unix only, like the existing runner tests).Reuse, not copy: process launch, process-group guard, private 0700 working directory, reap, credential resolution inside a timeout and the raw-byte redactor all come from
local_agent/process.rsandredaction.rs(merged with the tool runners). The only edit there is aworking_dir()accessor onIsolated.Protocol decisions (per the approved spec and rulings)
initializeoffersfs: {readTextFile: false, writeTextFile: false}andterminal: false; no elicitation.session/newsendsmcpServers: [](daemon-supplied context is a later stage).session/set_mode/set_config_optionare never called, so a bypass mode is never selected.session/request_permissionis answered-32601(fs/terminal/extension methods included), counted against a cap.AcpEvent::PermissionRequest, never auto-answered. Onlyallow_once/reject_onceoptions are surfaced and accepted;allow_always/reject_alwaysare hidden and cannot be selected (an answer naming any option not surfaced is refused). Waiting requests are answeredcancelledon cancel, on timeout, and past the pending cap; a flood beyond the per-turn cap ends the session.session/cancel, waiting permissions answered cancelled, a grace period, then the process group is killed.Bounds (all in
AcpLimits, tested with small values)Per-message size (oversize dropped, repeats end the session), per-turn and per-session bytes, per-turn update count, noise lines and bytes, unwanted requests and stray responses, pending and per-turn permissions, prompt size, startup, turn, idle (not counted while a permission waits for the user), permission wait, cancel grace, write, and a stalled event reader. JSON depth stays on serde's default recursion limit: a deeply nested line is noise.
Untrusted-agent handling: credentials are removed from the raw bytes of every line in one pass before parsing, and from error text before it is cut; responses are matched by id; stderr is drained and discarded; the child is killed on drop (process group), on close, on any fault; the private working directory is removed.
Review fixes (security review of 270cb5a)
\uXXXXbypass a raw-byte match). Regression: a fake agent sends the credential as raw JSON escapes in a text chunk, thought, plan entry, title, tool call, command name and permission option name; no surfaced event holds the credential or any 4-character piece of it. A unit test checks a credential straddling the cut at every offset.BINDING requirements for stage 2 and later
AcpSession::redacton ACCUMULATED text before storing or showing it (a credential split across two streamed chunks is invisible to the per-line and per-string passes) and must never log or store raw updates.AcpLaunch::validateis a shape check, not a policy: a relative program or PATH search, a leading-, symlinks, and literal env values that select a bypass or permission mode are NOT forbidden by it. Anything built from node fields or peer-authored data goes through a code-owned allow-list.validateforbids overriding them), so the Claude adapter would run with the user's real HOME, config and login and could reach the macOS keychain. Stage 2 must isolate it (a literalCLAUDE_CONFIG_DIRor equivalent, or an explicit private-HOME option on the descriptor) and supply the adapter's token ONLY throughsecrets(resolved inside the startup timeout, in the redaction set, never logged). A process-group kill does not reach descendants that callsetsid.allow_always/reject_always, never callsession/set_mode, never act onModeupdates (display only).session/updatenotifications afterTurnEndedare possible (capped at 256 by the unwanted-message counter): the writer must tolerate or drop them. HandleTurnFailed { auth_required }without ever sending credentials the user did not configure.consumer_stall, 60 s, with commands delayed). A stage-4 session end must callcloseor drop the handle on every exit path.Known limits, for the next stages
session/resume,session/load) is not in this stage.Staged plan (each PR independently mergeable, smallest and most security-relevant first)
session/new(system prompt append +nodespace mcpentry), still behind no caller.ai-chat-messageparts (batched text, in-place tool updates, version-conflict retry, stop-reason system messages, permission answers as system messages), against the in-memory stream.node_id, send prompt, cancel, answer permission, subscribe, terminate), session id vocabulary, end write (session_status,last_active).session/resume, fall back toload+ replay suppression, fall back to a new session with a marker; startup recovery of staleactivechats.Testing
allow_alwaysaccepted, option validation removed, cancel not answering waiting permissions.bun run quality:fixclean;bun run test:changedwas queued behind another gate at PR time (result will be commented); the core gate runs viabun run merge.🤖 Generated with Claude Code