Skip to main content

Module subprocess

Module subprocess 

Source
Expand description

Shared subprocess wrapper for M2/M3 tools.

Every M2 tool spawns apr <subcommand> [...args] --json and passes stdout through to the MCP client verbatim. Non-zero exit maps to isError: true with stderr attached. This module centralizes that pattern so each tool is a thin definition + a list of CLI args.

M3 (FALSIFY-MCP-006) adds run_apr_cancellable, which polls a std::sync::mpsc::Receiver between try_wait checks and escalates to SIGTERM → (grace window) → SIGKILL on the spawned subprocess when a cancellation is signalled. The non-cancellable run_apr is kept as a thin wrapper for tools that don’t support cancellation yet.

#2418: the failure path used to pick either stderr or stdout — stdout only when stderr was empty. apr qa writes its JSON gate report to stdout and a one-line summary to stderr, so every failing QA run (the tool’s primary use case) reached the client as a single line with the >3 KB report thrown away. [failure_result] now keeps the summary as the first content block and attaches the report as a second one, so a failing gate is as inspectable as a passing one.

Constants§

CANCEL_GRACE_MS
Default grace window between SIGTERM and SIGKILL for cancelled calls.

Functions§

run_apr
Spawn apr <args...> and wait synchronously. Shorthand for the non-cancellable path used by every tool except apr.run.
run_apr_cancellable
Spawn apr <args...> cancellable via cancel_rx.
run_apr_streaming
Spawn apr <args...> and stream stdout line-by-line to on_line.
run_program
Generic-over-program variant of run_apr. run_apr binds program to crate::apr_bin::apr_binary — the running apr executable — so the version the user launched is the version that answers.
spawn_cancellable
Generic over the binary. run_apr_cancellable binds program to crate::apr_bin::apr_binary — the running apr executable — which is what production code should use.
spawn_streaming
Generic-over-program variant of run_apr_streaming. Production callers pass crate::apr_bin::apr_binary; tests use it to inject a mock.