← Back to Pull requests

Exit spawned test workers with os._exit to avoid gloo abort at shutdown #9100

Closed
unknown closed this pull request without merging on Nov 17, 2026 12:34 UTC
View on GitHub
unknown unknown commented on Nov 17, 2026 08:48 UTC
Author

Fixes #9089.

Root cause


A worker of TestAutoTPCompileTiedEmbeddings::...[False] occasionally aborts with terminate called without an active exception after the test body has passed.

Native backtrace of the abort (CPU, gloo, torch 2.14, Python 3.12):

std::terminate
_Unwind_ForcedUnwind
pthread_exit
PyEval_RestoreThread            <- interpreter is finalizing
libtorch_python ... c10::TensorImpl::decref_pyobject
c10d::ProcessGroupGloo::runLoop

  • Non-daemonic workers are started with the spawn method, so they run full interpreter finalization on exit. fork/forkserver children end with os._exit.

  • During finalization a gloo runLoop thread can still be releasing the last reference to a Python-owned tensor. Acquiring the GIL there makes CPython pthread_exit the thread, and the forced unwind through a noexcept frame calls std::terminate.

  • destroy_process_group() alone is not enough: with DeepCompile the compiled graph keeps the TP group alive (placeholder meta['example_value']), so the gloo threads are not joined.
  • This reproduces without DeepSpeed: 2 spawned gloo ranks doing one all_reduce and returning without destroy_process_group() abort in 3 of 60 runs.

    Fix (test harness workaround)


    Spawned workers now exit through a small mp.Process subclass that calls os._exit after _bootstrap, matching the existing fork/forkserver behavior. No collective runs at teardown, so a rank whose test fails cannot leave the others blocked.

    Testing


    Local CPU repro (DS_ACCELERATOR=cpu, DS_DISABLE_REUSE_DIST_ENV=1, pytest --forked -m sequential unit/compile/test_tp_compile.py::TestAutoTPCompileTiedEmbeddings, repeated):
  • before: 9 aborted runs / 66

  • after: 0 / 60
  • Harness semantics: a test failing on only one rank still reports Worker 1 exited with code 1 with the assertion; pytest.skip inside workers is still propagated.

    Other non-daemonic tests on CPU (unit/compile/test_tp_compile.py, unit/pipe/test_pipe_module.py, unit/comm/test_dist.py, unit/v1/compile/test_compile_zero.py, unit/v1/autotp/test_tp_plan_e2e.py, unit/v1/half_precision/test_keep_in_fp32_modules.py): 139 passed, 62 skipped.

    Diff: 272 lines (+204 / -68) across 3 files Reviewer: jinyouzhi Review duration: 225m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 272 lines diff across 3 files
    0.39
    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%
    60%
    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.336
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #9100"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 39.5% (MEDIUM) · Higher = larger blast radius
    39.5%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 15.6% · Safe to merge
    15.6%