Skip to content

[None][test] Dump a stack traceback when a test hangs#16374

Open
BowenFu wants to merge 6 commits into
NVIDIA:mainfrom
BowenFu:feat/hang-traceback-on-timeout
Open

[None][test] Dump a stack traceback when a test hangs#16374
BowenFu wants to merge 6 commits into
NVIDIA:mainfrom
BowenFu:feat/hang-traceback-on-timeout

Conversation

@BowenFu

@BowenFu BowenFu commented Jul 14, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features

    • Added optional periodic hang traceback collection during test execution.
    • Captures thread stack traces when tests exceed their timeout or are interrupted.
    • Saves hang diagnostics alongside periodic test reports for easier troubleshooting.
    • Added configuration support to enable or disable this behavior and control when diagnostics are captured.
  • CI Improvements

    • Automated test runs now enable periodic hang traceback reporting by default.

Description

A per-test timeout or stage wall-clock kill leaves only an empty Test terminated unexpectedly record — we know which test hung (via unfinished_test.txt, #16358) but not where. Seen on L0 #47641 DGX_B200-PyTorch-6: test_kv_cache_v2_scheduler.py::TestKVCacheV2LoRA::test_lora_v2 hung the full --timeout=3600 window and was hard-killed; no traceback survived.

This adds opt-in hang-traceback dumping to the periodic-junit plugin:

  • Watchdog: a private threading.Timer armed per test dumps every thread's stack to output-dir/hang_traceback.txt at ~90% of the timeout, just before the kill.
  • Signal path: faulthandler.register(SIGINT/SIGTERM, chain=True) dumps at C level on a wall-clock kill even when the main thread is stuck in native CUDA, then chains to the existing report-saver.

Gated by --periodic-hang-traceback (default off), enabled in the L0 stage command. Controller-side only, so it covers non-xdist stages; xdist-worker coverage is future work.

Sample output

Before: test_lora_v2 FAILED "Test terminated unexpectedly" (stdout/stderr empty).
After — hang_traceback.txt (illustrative):

===== hang watchdog fired for kv_cache/test_kv_cache_v2_scheduler.py::TestKVCacheV2LoRA::test_lora_v2 =====
Current thread (most recent call first):
  File ".../torch/cuda/__init__.py", line 985 in synchronize
  File ".../_torch/pyexecutor/kv_cache_manager_v2.py", line 312 in _reclaim_blocks
  File ".../kv_cache/test_kv_cache_v2_scheduler.py", line 431 in test_lora_v2

Test Coverage

tests/integration/defs/utils/test_periodic_junit.py — timeout resolution (marker/global), hang dump, cancel-on-complete, no-arm-without-timeout. Pure-Python, no GPU.

PR Checklist

  • PR description clearly explains what and why.
  • PR follows TRT-LLM coding guidelines.
  • No API changes; new pytest option is opt-in and defaults off.
  • Please check this after reviewing the above items as appropriate for this PR.

@BowenFu
BowenFu requested review from a team as code owners July 14, 2026 12:17
@BowenFu
BowenFu marked this pull request as draft July 14, 2026 12:18
@BowenFu
BowenFu force-pushed the feat/hang-traceback-on-timeout branch from 068ad07 to 37412ea Compare July 14, 2026 12:24
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Periodic pytest reporting gains an opt-in --periodic-hang-traceback flag. When enabled, PeriodicJUnitXML uses faulthandler to capture timeout-triggered and signal-triggered thread tracebacks in a sidecar file.

Changes

Periodic hang traceback reporting

Layer / File(s) Summary
CLI option and reporter wiring
jenkins/L0_Test.groovy, tests/integration/defs/conftest.py
Adds the pytest flag, passes its value into PeriodicJUnitXML, reports the setting, and enables the flag in Jenkins test commands.
Reporter hang-dump configuration
tests/integration/defs/utils/periodic_junit.py
Adds hang-dump constructor settings, faulthandler state, and conditional setup during pytest configuration.
Timeout and shutdown traceback capture
tests/integration/defs/utils/periodic_junit.py
Schedules and cancels traceback watchdogs around tests and dumps all thread stacks during signal-driven shutdown.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Pytest
  participant PeriodicJUnitXML
  participant faulthandler
  participant TracebackFile
  Pytest->>PeriodicJUnitXML: configure hang traceback
  PeriodicJUnitXML->>faulthandler: enable output
  Pytest->>PeriodicJUnitXML: start test
  PeriodicJUnitXML->>faulthandler: schedule timeout dump
  faulthandler->>TracebackFile: write thread stacks
  Pytest->>PeriodicJUnitXML: finish test
  PeriodicJUnitXML->>faulthandler: cancel watchdog
  Pytest->>PeriodicJUnitXML: signal shutdown
  PeriodicJUnitXML->>faulthandler: dump all thread stacks
  faulthandler->>TracebackFile: flush output
Loading

Suggested reviewers: niukuo

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise, specific, and matches the main change: adding traceback dumping for hanging tests.
Description check ✅ Passed The description follows the template well with Description, Test Coverage, and PR Checklist sections completed.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/integration/defs/conftest.py`:
- Around line 2086-2095: Add regression tests in test_conftest.py and
test_periodic_junit.py covering the default and explicitly enabled
--periodic-hang-traceback values, propagation into PeriodicJUnitXML via
dump_hang_traceback, and the related registration log. Keep these tests narrowly
scoped and independent of GPU or model access, using existing test fixtures and
symbols where available.

In `@tests/integration/defs/utils/periodic_junit.py`:
- Around line 108-112: Annotate the new hang-traceback state and all related
helpers and pytest hooks in the surrounding changes, including _hang_file, with
precise types and explicit return types. Type each pytest item parameter using
the appropriate item type, avoid Any, and ensure annotations cover the functions
through the referenced range while preserving their existing behavior.
- Around line 433-442: The SIGINT/SIGTERM traceback dump currently depends on
the Python handler running, so native C/CUDA hangs may prevent it. In the
setup/registration flow associated with the existing hang handler and _hang_file
persistence, register faulthandler for SIGINT and SIGTERM with chain=True while
retaining the current handler for report persistence; extend the integration
tests to cover signal delivery in subprocesses.
- Around line 376-421: Update _effective_timeout to match pytest-timeout
resolution, including keyword timeout marker values, global timeout fallback,
and func_only semantics. Move watchdog cancellation from pytest_runtest_teardown
to the teardown phase that runs after fixture finalizers, preserving the
existing arming behavior and warning handling. Add coverage in
test_periodic_junit.py for keyword/global resolution, func_only markers, and a
hanging fixture finalizer.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 0adafb3d-bb2e-410b-be31-cd3834c7f715

📥 Commits

Reviewing files that changed from the base of the PR and between 1662a87 and 068ad07.

📒 Files selected for processing (3)
  • jenkins/L0_Test.groovy
  • tests/integration/defs/conftest.py
  • tests/integration/defs/utils/periodic_junit.py

Comment thread tests/integration/defs/conftest.py
Comment thread tests/integration/defs/utils/periodic_junit.py Outdated
Comment thread tests/integration/defs/utils/periodic_junit.py Outdated
Comment thread tests/integration/defs/utils/periodic_junit.py Outdated
@BowenFu
BowenFu force-pushed the feat/hang-traceback-on-timeout branch from 37412ea to 3c4c7fb Compare July 14, 2026 12:36
@BowenFu
BowenFu marked this pull request as ready for review July 14, 2026 12:43
@BowenFu

BowenFu commented Jul 14, 2026

Copy link
Copy Markdown
Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59204 [ run ] triggered by Bot. Commit: 3c4c7fb Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59204 [ run ] completed with state FAILURE. Commit: 3c4c7fb
/LLM/main/L0_MergeRequest_PR pipeline #47703 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@BowenFu
BowenFu force-pushed the feat/hang-traceback-on-timeout branch from 3c4c7fb to cc32cf7 Compare July 15, 2026 02:25
@BowenFu

BowenFu commented Jul 15, 2026

Copy link
Copy Markdown
Author

/bot run

@github-actions

Copy link
Copy Markdown

⚠️ Bot command ignored: The /bot command must appear at the very beginning of the comment (no leading blank lines or spaces). Please post a new comment with /bot as the first character.

@BowenFu

BowenFu commented Jul 15, 2026

Copy link
Copy Markdown
Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59339 [ run ] triggered by Bot. Commit: cc32cf7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59339 [ run ] completed with state SUCCESS. Commit: cc32cf7
/LLM/main/L0_MergeRequest_PR pipeline #47819 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

A per-test timeout or stage wall-clock kill currently leaves only an empty
"Test terminated unexpectedly" record, so a hang is named (via unfinished_test.txt)
but not diagnosable — there is no stack showing where it is stuck.

Add opt-in hang-traceback dumping to the periodic-junit plugin:
- Watchdog (primary): arm faulthandler.dump_traceback_later() at each test's setup
  for ~90% of its timeout and cancel on teardown, so every thread's stack is
  written to output-dir/hang_traceback.txt just before the test is killed. The
  watchdog thread fires even when the main thread is stuck in an un-interruptible
  C/CUDA call — exactly when the thread-method per-test timeout cannot unwind it.
- Signal path: also dump on SIGINT/SIGTERM (e.g. a stage wall-clock kill) before
  saving results, via async-signal-safe faulthandler.dump_traceback().
- enable() additionally captures native fatal signals (SIGSEGV/SIGABRT/...).

Gated by --periodic-hang-traceback (default off), enabled in the L0 stage command
next to --periodic-save-unfinished-test. Complements surfacing the culprit test:
the sidecar file gives the "where" to pair with the "who".

Note: the plugin runs controller-side, so the watchdog covers non-xdist stages
(where the controller is the test process); xdist-worker coverage is future work.

Signed-off-by: Bowen Fu <5812640+BowenFu@users.noreply.github.com>
@BowenFu

BowenFu commented Jul 15, 2026

Copy link
Copy Markdown
Author

/bot run

@BowenFu
BowenFu force-pushed the feat/hang-traceback-on-timeout branch from 16a1079 to 8e0a537 Compare July 15, 2026 07:45
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59394 [ run ] triggered by Bot. Commit: 8e0a537 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59394 [ run ] completed with state SUCCESS. Commit: 8e0a537
/LLM/main/L0_MergeRequest_PR pipeline #47868 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@BowenFu

BowenFu commented Jul 15, 2026

Copy link
Copy Markdown
Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59416 [ run ] triggered by Bot. Commit: 8e0a537 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59416 [ run ] completed with state SUCCESS. Commit: 8e0a537
/LLM/main/L0_MergeRequest_PR pipeline #47886 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@ZhanruiSunCh ZhanruiSunCh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for infra part.

@BowenFu

BowenFu commented Jul 17, 2026

Copy link
Copy Markdown
Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59980 [ run ] triggered by Bot. Commit: 8e0a537 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #59980 [ run ] completed with state FAILURE. Commit: 8e0a537
/LLM/main/L0_MergeRequest_PR pipeline #48374 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@BowenFu

BowenFu commented Jul 20, 2026

Copy link
Copy Markdown
Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60305 [ run ] triggered by Bot. Commit: fb5459c Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60305 [ run ] completed with state FAILURE. Commit: fb5459c
/LLM/main/L0_MergeRequest_PR pipeline #48653 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@BowenFu

BowenFu commented Jul 21, 2026

Copy link
Copy Markdown
Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60550 [ run ] triggered by Bot. Commit: 2734625 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60550 [ run ] completed with state FAILURE. Commit: 2734625
/LLM/main/L0_MergeRequest_PR pipeline #48870 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@BowenFu

BowenFu commented Jul 21, 2026

Copy link
Copy Markdown
Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60597 [ run ] triggered by Bot. Commit: 2734625 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60597 [ run ] completed with state FAILURE. Commit: 2734625
/LLM/main/L0_MergeRequest_PR pipeline #48911 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@BowenFu

BowenFu commented Jul 22, 2026

Copy link
Copy Markdown
Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60910 [ run ] triggered by Bot. Commit: 4562138 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60910 [ run ] completed with state FAILURE. Commit: 4562138
/LLM/main/L0_MergeRequest_PR pipeline #49177 completed with status: 'ABORTED'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

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.

7 participants