rtk icon indicating copy to clipboard operation
rtk copied to clipboard

rtk swallows exit codes of bash/python one-liners, causing phantom failures and false passes

Open nitrocode opened this issue 3 months ago โ€ข 2 comments

Summary

An independent eval (3 real tasks against hidden acceptance tests, Sonnet 5 medium, 9 replicates per arm, comparing rtk off / rtk defaults / a tuned config) found rtk's shipped defaults are 16% more expensive per passing run than not using rtk at all, with a lower pass rate (8/9 vs 9/9) and a 199-turn/$17.20 outlier vs a normal 71-104 turns/~$6. Root cause, per direct turn-log analysis: rtk swallows the exit code of bash and python one-liners run through the recognized-tool rewrite path.

Impact

  1. Phantom failures: the command actually succeeded, but the lost exit code makes it look like it failed. The agent then hunts a bug that doesn't exist, burning turns and tokens.
  2. False passes: a test run looks like it passed when it didn't. The agent moves on, and the real failure surfaces later in unrelated code, which reads as flaky tests and triggers a deep, unnecessary investigation.
  3. Workarounds: once an agent notices the exit code was consumed, it spends turns rewriting the one-liner to dodge rtk, but only when the one-liner is simple enough to rewrite around.

All three cost turns and tokens rather than capability, matching the measured outlier and near-miss failure in the eval's default-settings arm.

Relation to existing issues

Checked #2974 (open, priority:critical) first, it covers exit-code swallowing for the pnpm/eslint recognized-tool path specifically, and explicitly states "trivial commands propagate correctly, so this is specific to the recognized-tool path, not general exit handling." This report is about bash/python one-liners, which contradicts that scoping, so it looks like a distinct, broader instance of the same underlying bug rather than a duplicate. Also related: #2735 (golangci-lint, same class).

Ask

Given the measured cost impact (a 16% regression vs not using rtk at all, i.e. rtk's own defaults can be net-negative), this seems to warrant treating exit-code propagation as a correctness invariant across every recognized-tool and passthrough path, not just fixing it path-by-path as reports come in.

nitrocode avatar Aug 09 '26 04:08 nitrocode

wshm ยท Automated triage by AI

๐Ÿ” Automated Triage

๐Ÿ› Category bug
๐Ÿ”ด Priority critical
๐ŸŽฏ Confidence 85%

Summary

rtk's recognized-tool rewrite path swallows exit codes for bash/python one-liners, causing phantom failures and false passes with measurable cost regressions vs not using rtk โ€” recommend treating exit-code propagation as a correctness invariant across all recognized-tool/passthrough paths, not a per-path fix.


Triaged automatically by wshm ยท This is an automated analysis, not a human review.

pszymkowiak avatar Aug 09 '26 04:08 pszymkowiak

I tried to reproduce this on current develop (b748a5f, rtk 0.48.0) and couldn't. The method: take each command, run it raw, then run whatever rtk rewrite turns it into (what the hooks do), and compare exit codes.

35 cases, 0 mismatches, including:

  • python3 -c 'import sys; sys.exit(3)', python3 -c 'raise SystemExit(4)', python3 - <<EOF ... sys.exit(7), bash -c 'exit 5', sh -c 'exit 6'
  • the same one-liners after a rewritten tool: git status && python3 -c '...exit(8)', ls a.txt && python3 -c '...exit(13)', grep -r alpha . && bash -c 'exit 14', head -n 1 a.txt && python3 ... (-> rtk read --head-lines 1 ...)
  • script and test-runner paths: python3 script.py, python3 -m unittest, cargo test (-> rtk cargo test, exit 101), make (-> rtk make)
  • pipes, ; sequences, for loops, and nested bash -c "python3 -c ..."

One detail that matters for this issue: bare python3 -c / bash -c / sh -c one-liners aren't rewritten at all (they're on the skip list in src/discover/rules.rs), so they never enter an rtk code path. When they're chained after a rewritten tool, the chain keeps the one-liner's status.

So on current develop, I don't think the one-liner path swallows exit codes. It may have been fixed since the eval ran (this was filed against an August build). @nitrocode, if you can still reproduce it, the exact command string and rtk --version would help pin it down.

Either way, the ask here (treat exit-code propagation as an invariant, not a per-path fix) seemed worth locking in, so I opened a regression test for it: #4203. It checks raw vs rewritten exit codes over a matrix like the one above and fails if a future change swallows one.

Protocol-zero-0 avatar Sep 22 '26 21:09 Protocol-zero-0