← Back to Pull requests

write_unraisable_default prints through sys.stderr and the traceback module #56

Closed
unknown closed this pull request without merging on Oct 20, 2026 13:47 UTC
View on GitHub
unknown unknown commented on Oct 20, 2026 04:25 UTC
Author

PyError::write_unraisable_default writes to sys.stderr and prints the exception with the traceback module, following error.py write_unraisable_default, with the output rules of errors.c write_unraisable_exc / write_unraisable_exc_file.

  • sys.stderr is read first. If the sys module or its stderr attribute is missing, or the value is None, nothing is printed and the object's __repr__ is not called. There is no fallback to the host stderr.

  • The header is written as separate file.write calls:

  • - with an object: the message (default Exception ignored in), then ": ", then the object's repr (or <object repr() failed>), then the line end
    - without an object: the message followed by ":\n"
    - with no message and no object: no header, so the exception is the first line

    An extra_line (the cffi onerror report) replaces the final newline, as in error.py.

  • The exception is printed by traceback._print_exception_bltin(exc, file), through display_through_traceback_module, with the same stream the header went to. lib-python/3/traceback.py _print_exception_bltin takes an optional positional file (exc, file=None, /). The _PyErr_Display caller keeps the one-argument call.

  • If traceback cannot be imported or the call raises, write_exception_from_parts renders the exception with the supplied traceback onto the same stream.

  • write_unraisable_default does not set __traceback__ on the exception, so sys.__unraisablehook__ leaves the exception unchanged. The signal wakeup-fd report and the cffi onerror report install their traceback before the call, as format_unraisable_v does.

  • The sys.stderr lookup and the file.write call were split out of write_to_sys_stderr into write_bytes_to_file.
  • Verification


    On macOS arm64, dynasm, with LLBC re-extracted:
  • cargo test --all --no-default-features --features dynasm,cpyext,pyre-module --exclude majit-backend-wasm: pass

  • pyre/extra_tests/run.py --gated-only --dynasm-only: 194/194

  • pyre/check.py --backend dynasm: 599 passed, 3 failed. The failures are range_ctor_in_loop, getframe_loop_callee_on_frame_chain and str_search_index_bounds, which fail the same way on current main.

  • pyre/cpython_tests/run.py --filter test_signal, test_sys, test_cmd_line_script, test_thread, test_threading, test_gc, test_weakref: no regressions

  • A script that drives sys.__unraisablehook__ produces the same output as CPython 3.15.0, apart from object addresses. It covers each header case, a failing __repr__, a __repr__ that replaces sys.stderr, sys.stderr = None, a supplied traceback, and a __del__ report, and records the individual writes.

  • cargo check -p pyre-interpreter -p pyre-module with dynasm, with --no-default-features --features dynasm, and with sandbox,dynasm: pass

  • cargo check -p pyre-wasm --target wasm32-unknown-unknown --features wasm-host: pass
  • 🤖 Generated with Claude Code

    Diff: 375 lines (+281 / -94) across 4 files Reviewer: youknowone Review duration: 562m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.43) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 375 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.355
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #56"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.9% (MEDIUM) · Higher = larger blast radius
    42.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.5% · Safe to merge
    18.5%