Skip to content

fix(runner): surface a failing tool's stderr under stdout-only filtering - #3029

Closed
georgyia wants to merge 1 commit into
rtk-ai:developfrom
georgyia:fix/stdout-only-swallows-stderr
Closed

georgyia wants to merge 1 commit into
rtk-ai:developfrom
georgyia:fix/stdout-only-swallows-stderr

Conversation

@georgyia

Copy link
Copy Markdown

Fixes #3026

Problem

uv run rtk pytest says nothing at all when pytest is missing from the venv — exit 1, a single newline on stdout, empty stderr. As the issue puts it, this is the dangerous quadrant: a test run that produces no output and no error text reads as a quiet pass, and the exit code is the only surviving signal.

$ uv run rtk pytest --version >out.txt 2>err.txt; echo "exit=$?"
exit=1
$ wc -c out.txt err.txt
       1 out.txt        # a single newline
       0 err.txt        # nothing

Root cause

uv is the trigger, not the culprit — and it isn't a spawn failure either.

Filters that compress stdout pass RunOptions::stdout_only, which keeps stderr out of the filter input. But run_captured_filter only ever emitted raw_stderr inside its skip_filter_on_failure branch. Callers that pair stdout_only with early_exit_on_failure (ls, tree) reach that branch and print stderr; callers that don't captured stderr and dropped it:

stdout_only caller early_exit_on_failure stderr on failure
ls, tree yes shown
pytest, ruff, prettier, go test, golangci-lint, phpunit, phpstan, pint, rubocop no dropped

Why only the combination goes mute: standalone rtk pytest looks fine because python is absent, so the spawn fails outright and the anyhow error prints loudly. Under uv run the venv supplies python, so rtk takes its python -m pytest fallback, the spawn succeeds, and the child's diagnostic goes to the stderr that was being discarded:

$ uv run python -m pytest --version
/tmp/uvp/.venv/bin/python3: No module named pytest     # 51 bytes, exit 1
$ uv run rtk pytest --version
                                                        # 0 bytes, exit 1

Fix

Emit stderr when the child fails:

if opts.filter_stdout_only && exit_code != 0 && !result.raw_stderr.trim().is_empty() {
    eprint!("{}", result.raw_stderr);
}

Only on failure — on a successful run stderr is the incidental noise RTK exists to suppress, and the filtered stdout already carries the result. This is the rule ls/tree already get via early_exit_on_failure, applied to the callers that were missing it. No double-printing: FilterMode::CaptureOnly buffers stderr without echoing, and the skip_filter_on_failure branch returns before this point.

This likely covers more than #3026. The table above is a family, and #2878 ("rtk prettier silently hides prettier 3 failures — stdout-only capture + [warn] filter") names this exact mechanism. I've deliberately scoped this PR to the shared runner defect and made no filter-specific claims; I haven't verified #2878 end-to-end, so I'm flagging the overlap rather than asserting a fix.

Verification

before after
uv run rtk pytest --version (missing) exit 1, stderr 0 B exit 1, stderr 50 B: No module named pytest
uv run rtk pytest --version (installed) exit 0, stderr 0 B exit 0, stderr 0 B — unchanged

Reproduced against real uv in a fresh uv init + uv venv project, both with and without pytest installed.

  • New tests in tests/stderr_passthrough_test.rs put a failing shim on PATH (stderr message, empty stdout, nonzero exit) and drive it through rtk ruff, a bare stdout_only caller. failing_tool_stderr_reaches_the_user fails on the pre-fix runner and passes after; successful_tool_stderr_stays_suppressed passes both ways, pinning that no new noise is introduced on success.
  • cargo fmt --all --check clean, cargo clippy --all-targets zero warnings, cargo test --all 2495 passed / 0 failed.

Verified on Linux (rust:latest); the tests are #![cfg(unix)] as they rely on a shell shim and PermissionsExt.

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test --all
  • Manual testing: uv run rtk pytest --version with and without pytest in the venv
  • Regression tests added, confirmed failing before the fix
  • Token savings: N/A (error-path fix, no filter change)

`uv run rtk pytest` produced no output at all when pytest was missing from the
venv: exit 1, a single newline on stdout, nothing on stderr. A test run that
prints nothing and reports no error reads as a quiet pass, leaving the exit code
as the only signal.

The trigger is uv, but the defect is in the runner. Filters that compress stdout
pass RunOptions::stdout_only, which keeps stderr out of the filter input — and
run_captured_filter only ever emitted stderr inside its skip_filter_on_failure
branch. Callers that pair stdout_only with early_exit_on_failure (ls, tree) hit
that branch and print stderr; callers that don't (pytest, ruff, prettier, go
test, golangci-lint, phpunit, phpstan, pint, rubocop) captured stderr and
dropped it on the floor.

Standalone `rtk pytest` looks fine only because python is absent there: the spawn
fails outright and the anyhow error prints. Under `uv run` the venv supplies
python, so rtk falls back to `python -m pytest`, the spawn succeeds, and the
child's "No module named pytest" goes to the stderr that was being discarded.

Emit stderr when the child fails. Only on failure: on a successful run stderr is
the incidental noise RTK exists to suppress, and filtered stdout already carries
the result.

Fixes rtk-ai#3026
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @georgyia,

Thanks for your contribution. You’ll need to sign the CLA before we can move forward.

A few notes on your PR:
This will break golangci_cmd.rs, since it deliberately behaves that way for the “lint issues found” case, and possibly rspec_cmd.rs too.
phpstan_cmd.rs would also duplicate diagnostics.
Also, result.raw_stderr is captured by stream.rs's CaptureOnly thread, which doesn't warn on truncation the way the other capture paths there do (stream.rs:376,384) — worth adding that same 10 MiB warning, since this PR is what makes that stderr visible to the user for the first time.

Most of this should be fixed by gating on stdout:

if opts.filter_stdout_only && exit_code != 0
    && result.raw_stdout.trim().is_empty()
    && !result.raw_stderr.trim().is_empty()
{
    eprint!("{}", result.raw_stderr);
}

The bug you’re trying to fix is really that stdout is empty or useless and the diagnostic is stuck in stderr, so this should only kick in when stdout is also empty. Most tools exit nonzero with populated stdout, which helps gate against a noise regression.

A few other points:

  • Token-savings tracking (raw_for_tracking / shown) doesn't include the new shown stderr bytes, so that should be fixed.
  • With those changes, you'll need a test covering the stdout non-empty + nonzero exit + benign stderr → no dump case.
  • Bonus: you could avoid skip_filter_on_failure duplication by adding an emit_stderr_if_present helper.

@KuSh

KuSh commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

Thanks for tracking this down, the writeup of why only the stdout_only plus no-early-exit combination went mute was exactly right. This landed on develop on 2026-09-12 in #3772, which forwards a stdout-only filter's stderr in the same place in run_captured_filter and also counts those bytes in the savings total. It forwards unconditionally rather than only on failure, because tools like prettier write their whole report to stderr on a successful run, so the one behaviour your PR pinned differently is a deliberate choice there. Closing as covered, but please comment or reopen if you see a case that still comes out silent.

@KuSh KuSh closed this Sep 12, 2026
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.

uv run rtk <tool> swallows the spawn-failure message when the tool is missing — exit code correct, output empty

3 participants