Repository navigation
acp-tools: Add a probe that lists an ACP adapter's commands - #9
Conversation
Port the one-off probe from cgwalters-forge/tracker#677 into the toolbox, so checking which commands an ACP adapter offers no longer needs an ad hoc script. It speaks just enough ACP to get the adapter's agentCapabilities and its available_commands_update. The whole exchange has one deadline, and adapter output is bounded in line size and queue depth, so a stuck or noisy adapter cannot hang the caller or exhaust its memory. Verified with `just check`, using inline `sh` fake adapters. Generated-by: https://github.com/cgwalters/#llms
There was a problem hiding this comment.
VERDICT: CHANGES
Reviewed admitted head a34942e8894e4403d0748010d878236382e055c5 against merge base 5e5eae2a9fb8646c2cefeaf6745aab2af0f39b5a.
-
blocker — The advertised whole-exchange timeout does not bound the exchange.
crates/misctool/src/acp_tools.rs:140-142performs synchronous writes with no deadline. An adapter can read initialize, emit a request with a string ID larger than the pipe capacity, then stop reading stdin; the mirrored ID in the error reply blocks this thread indefinitely, so even--timeout 1never reaches cleanup. Independently, atcrates/misctool/src/acp_tools.rs:158-161, expiration merely changesrecv_timeoutto a zero-duration receive: queued messages still succeed. A continuous stream of ignored notifications or blank lines can therefore keep the loop alive past its deadline. Bound writes as well as reads, and explicitly reject an expired deadline before consuming another message. Add regressions for a non-reading adapter and continuously available irrelevant output, with an independent outer watchdog so the tests cannot hang. -
important — Adapter output is buffered without any memory bound.
crates/misctool/src/acp_tools.rs:107-111combines an unbounded channel withBufRead::lines(), which also accumulates an unlimited unterminated line. A noisy adapter can exhaust the probe's memory through either a single enormous line or a backlog of small messages; the timeout is not a memory limit. Set a maximum frame size and bound the pending-message queue, while preserving deadline enforcement when applying backpressure. Cover both oversized unterminated output and a producer faster than the consumer. -
important — An early command update bypasses the session creation result.
crates/misctool/src/acp_tools.rs:281-285returns success onavailable_commands_updateeven whilesession_createdis false. If the adapter sends the update before itssession/newresponse, the probe kills it and reports exit 0 without ever checking that response; a subsequent JSON-RPC error or missing response is silently treated as success despite the documented error behavior. Retain the early update, wait for a successful session response, and only then return the command list. Add tests for update-before-success, update-before-error, and update-without-response.
No workflow or ownership-policy files change in this diff. A person still needs to approve the merge.
Generated-by: https://github.com/cgwalters/#llms
a34942e to
6d70b88
Compare
There was a problem hiding this comment.
VERDICT: APPROVE
Reviewed admitted head 6d70b8838a32c374d2da83689a325364245306c8. No blockers found. A person still needs to approve the merge.
Follow-ups
- important —
crates/misctool/src/acp_tools.rs:275–280: terminate the adapter's descendants, not just its immediate wrapper.Dropkills only the direct child, while adapter descendants inherit the caller's stderr throughStdio::inherit(). For example,acp-tools --timeout 1 -- sh -c 'sleep 300; :'kills the shell at the deadline but leavessleeprunning with stderr open. A caller usingCommand::output()or another output-capturing subprocess API consequently waits for that descendant to close the pipe, potentially indefinitely, even though the CLI process itself exits on time. Wrapper-based adapter launchers can exhibit this without malicious behavior, and successful probes can leave workers running too. Establish and clean up an adapter process group/tree, and add a regression case with a non-exec wrapper that checks both bounded output collection and descendant cleanup; the existing timeout cases useexecand miss this.
Add an
acp-toolssubcommand that starts an ACP adapter over stdio, sendsinitializeandsession/new, waits foravailable_commands_update, and prints the adapter'sagentCapabilitiesand the names of the commands it offers. This ports the one-off probe from cgwalters-forge/tracker#677 into the toolbox. Output is plain text by default and one JSON object with--json. The whole exchange has one deadline,--timeout(default 30s, max 600s), so a stuck adapter cannot hang the caller. Timeouts, adapter exit and JSON-RPC errors exit 1 with a message saying which step failed. The tool reads no credentials and opens no network connections; the adapter inherits the environment. It adds a serde_json dependency.Verified with
cargo fmtandjust check; the tests use an inlineshfake adapter, with no real model. The repository has nojust fmtrecipe, so I rancargo fmtdirectly.Two review passes ran, with no blockers. The first pass found that the wait could outlast the deadline when an adapter closed stdout but kept running; that is fixed. Follow-ups still open: a failed write waits out the rest of the deadline before reporting (a short grace period would avoid that); writes to an adapter that never reads stdin are not bounded by the deadline; an error reply with
"id": nullreports as a timeout rather than the error; adapter output in error messages has no length cap; and no tests yet cover asession/newerror or an update that arrives before thesession/newresponse.Closes #4