Skip to content

fix(run): propagate signal exit code instead of unwrap_or(1) - #2681

Merged
aeppling merged 1 commit into
rtk-ai:developfrom
guyoron1:fix/run-signal-exit-code
Jun 28, 2026
Merged

aeppling merged 1 commit into
rtk-ai:developfrom
guyoron1:fix/run-signal-exit-code

Conversation

@guyoron1

Copy link
Copy Markdown
Contributor

Summary

  • Replace status.code().unwrap_or(1) with exit_code_from_status(&status, "run") in Commands::Run (main.rs:2334)
  • Signal kills (SIGTERM, SIGKILL, OOM) now produce POSIX-conventional 128+signal exit codes instead of silently mapping to 1
  • Uses the same helper already used by Commands::Proxy at line 2515

Fixes #2680

Test plan

  • cargo fmt --all — no formatting changes
  • cargo clippy --all-targets — no warnings
  • cargo test --all — all tests pass
  • Manual: rtk run "sleep 99" &; kill -TERM $! should exit 143 (not 1)

`Commands::Run` used `status.code().unwrap_or(1)` which silently
maps signal kills (SIGTERM, SIGKILL, OOM) to exit code 1 instead
of the POSIX-conventional 128+signal. Use the existing
`exit_code_from_status()` helper already used by Commands::Proxy.

Fixes rtk-ai#2680
@aeppling

Copy link
Copy Markdown
Contributor

hey @guyoron1 thanks for the contribution, lgtm for better transparency on exit code propagation

@aeppling
aeppling merged commit 113ae11 into rtk-ai:develop Jun 28, 2026
12 checks passed
sBucka added a commit to sBucka/rtk that referenced this pull request Jul 3, 2026
Two gaps found on re-review against the same bug classes rtk has
already fixed elsewhere:

- Exit code was read via .code().unwrap_or(1), which silently reports
  1 for a signal-killed curl (e.g. a timeout SIGTERM) instead of the
  conventional 128+signal. This is the exact bug fixed for `rtk run`
  in rtk-ai#2681; switched to the existing exit_code_from_output() helper.
  (curl_cmd still has the old pattern — left untouched, out of scope
  for this PR.)

- The Markdown conversion was emitted directly, bypassing the
  never-worse guard (core::guard::never_worse / runner::emit_guarded)
  that curl_cmd already goes through. Without it, pathological/
  adversarial HTML that happens to convert to something larger than
  the raw response would silently cost more tokens than plain curl —
  the same regression class rtk-ai#2551/rtk-ai#2554 generalized the guard to
  prevent. Now both the HTML and passthrough paths converge through
  emit_guarded before tracking, matching curl_cmd's structure.

No behavior change for the common case (real pages still convert and
shrink as before); this only changes the signal-exit-code edge case
and adds a safety net for the pathological-HTML edge case. Re-verified
against example.com, api.github.com/zen, and jsonplaceholder — HTML
still converts, JSON/plain-text still passes through untouched.
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.

rtk run: signal exit code not propagated (unwrap_or(1))

2 participants