Repository navigation
fix(core): stdout-only filters silently swallow a tool's stderr - #3772
Conversation
25429d0 to
7b89028
Compare
The six tests adopted from upstream rtk-ai#3772 spawn rtk without RTK_DB_PATH, so every run booked fake-tool savings into the developer's history.db. Point them at a per-test file in the tempdir, as tests/stderr_passthrough_test.rs already does. Also names rtk-ai#2878 as the upstream issue it is. Co-Authored-By: Claude Fable 5.1 <[email protected]>
fix(core): forward stderr from stdout-only filters on every exit (adopt upstream rtk-ai#3772)
|
Hey @KuSh Looks sound, stderr should be forwarded. For most tools it's a few lines of pure signal, so passing it through uncompressed is fine for now One case to flag: prettier writes its whole report to stderr, so rtk prettier --check . on a large repo goes from 1 token to ~26k. Not a blocker for this PR |
`RunOptions::stdout_only()` is documented as "stdout-only to filter, stderr passthrough", but the passthrough half was never implemented: stderr was captured and dropped on every path except `skip_filter_on_failure`. A tool that reports on stderr and leaves stdout empty therefore produced nothing at all. golangci-lint is the visible case -- a config or build error goes to stderr, the filter is handed an empty stdout, and the never-worse guard replaces its "JSON parse failed" fallback with the empty string, so both streams end up silent. The same shape applies to every other stdout-only filter: ruff, pytest, rspec, rubocop, gh, glab, prettier, tree, wc. Savings are also measured against running the command directly, so the stderr that is forwarded has to be counted as emitted. Comparing stdout to stdout while printing stderr as well booked a passed-through stream as if it had been filtered away. The guard keeps comparing against stdout. stderr is forwarded verbatim on both sides, so it cancels: never-worse reduces to `filtered <= stdout`, and widening the baseline to the combined output would let rtk emit more than the command it replaces. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Six cases over a fake tool on PATH, covering both halves of the contract: the
tool's own stderr has to reach the user, and rtk must not invent a stdout
message in its place.
The prettier case is the one that is easy to get wrong. It writes its report to
stderr and nothing to stdout even on a successful run, so a filter's empty-input
placeholder ("Error: prettier produced no output") would be printed over a run
that worked. An empty stdout from a command that printed nothing on stdout is
the correct answer.
Also pinned: stderr is not replayed onto stdout on top of being forwarded, a
genuinely silent command stays silent, forwarding is not golangci-specific, and
exit codes propagate -- including golangci-lint's exit 1, which means issues
were found and is reported without failing the build.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
7b89028 to
baf3a10
Compare
|
One thing worth flagging, though not a blocker: |
Every
RunOptions::stdout_only()filter drops the tool's stderr. When a tool reports on stderr and leaves stdout empty,rtkprints nothing at all — on either stream.src/cmds/README.mddocuments the constructor as "stdout-only to filter, stderr passthrough, no tee", but the passthrough half was never implemented:run_captured_filteronly emits stderr on theskip_filter_on_failurepath, which most callers do not enable.Impact
Around 30 call sites:
ruff,pytest,rspec,rubocop,prettier,phpunit,phpstan,gh,glab,go test,golangci-lint,tree,wc,psql.Partially addresses #2878, which documents the prettier case in detail. That issue's first defect — stderr discarded before the filter ever sees it — is fixed here, so the
[warn]lines now reach the user. Its second defect (filter_prettier_outputexcluding[warn]lines) is prettier-specific and is not touched by this PR, so #2878 should stay open.How it broke
Two commits compound:
078ad1dmovedgolangci_cmdontorunner::run_filteredand deleted a block whose own comment read// Always forward stderr (config errors, missing linters, etc.).861a46daddedguard::never_worse. Understdout_onlythe baseline is stdout, so with stdout empty any filter output counts as "worse than nothing" and collapses to the empty string.Together: silence on both streams.
The fix
Forward the captured stderr, and count it. The guard keeps comparing against stdout, which is the correct baseline: stderr is forwarded verbatim on both sides, so it cancels, and never-worse reduces to
filtered <= stdout. Widening the baseline to the combined output would let rtk emit more than the command it replaces.Tracking now measures against the full raw output and counts what was actually emitted — comparing stdout to stdout while printing stderr booked a passed-through stream as if the filter had removed it, overstating savings in
rtk gain.Tests
Six integration tests over a fake tool on PATH, pinning both halves of the contract: the tool's stderr must reach the user, and rtk must not invent a stdout message in its place. The prettier case covers the second — it writes its report to stderr and nothing to stdout even on a successful run, so a filter's empty-input placeholder would otherwise be printed over a run that worked.
cargo test --all: 2927 passing. fmt clean, 0 clippy warnings.