Propagate the traced script's sys.exit code without losing trace output#87
Merged
KaykCaputo merged 2 commits intoJul 9, 2026
Merged
Conversation
runpy.run_path() lets a traced script's SystemExit fly through
_trace_script, so for any script ending in sys.exit() — most CLI
tools, every argparse program — the summary, all exports and
--compare silently never run.
Catch SystemExit at the run boundary, finish reporting, and return
the script's own exit code at the end. Python semantics preserved:
sys.exit() -> 0, sys.exit(7) -> 7, sys.exit('msg') -> msg on
stderr with code 1. --fail-on-regression codes still win.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
KaykCaputo
approved these changes
Jul 9, 2026
KaykCaputo
left a comment
Owner
There was a problem hiding this comment.
Nice, I hadn't thought about that. That's a very important point. Thanks! Feel free to continue the discussion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Last of the small fixes from my fork — after this one I'd like to open a Discussion about upstreaming some larger features.
Symptom: any traced script that ends with
sys.exit()— which includes most CLI tools and everyargparseprogram — silently loses all oracletrace output:runpy.run_path()lets the script'sSystemExitfly straight through_trace_script, so the summary,--json/--csv/--htmlexports, and--comparenever run, and oracletrace exits with whatever code the script raised — without having done its job.Fix: catch
SystemExitaroundrun_path, keep tracing/reporting/exports intact, and surface the script's own exit code at the very end (Python semantics preserved:sys.exit()→ 0,sys.exit(7)→ 7,sys.exit("msg")→ message on stderr, code 1). Gate codes (--fail-on-regression) still take precedence, since that's the CI contract.Tests: four e2e subprocess tests — code propagated, exports written after
sys.exit, string-argument semantics, baresys.exit()success.🤖 Generated with Claude Code