Skip to content

test(cuda.core): resume the Windows test run when the driver is stuck in OOM - #3695

Merged
juenglin merged 7 commits into
NVIDIA:mainfrom
juenglin:test/windows-restart-on-sticky-oom
Dec 3, 2026
Merged

juenglin merged 7 commits into
NVIDIA:mainfrom
juenglin:test/windows-restart-on-sticky-oom

Conversation

@juenglin

@juenglin juenglin commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

Works around the Windows pinned-pool OOM cascade in #3472 (NVBugs 7092346) in the test infrastructure only. No cuda.core production code changes, and the device-access grant from #3405 stays.

Problem. On Windows (WDDM/MCDM), a host pinned pool with device access granted can leave the process permanently returning CUDA_ERROR_OUT_OF_MEMORY; cuCtxSynchronize and cuMemGetInfo fail the same way. The state is per process, and the test that trips it is arbitrary, so xfail would mark the wrong tests and hide real failures. Pinned memory is used by about 31 test files.

Change

  • helpers/sticky_oom.py and conftest.py: after a failing setup or call phase that mentions OOM, probe cuCtxSynchronize and cuMemGetInfo. If both return OOM the process is stuck, so stop the session with exit code 75 and print one line naming the bug. Finished tests are appended to a resume file; a restart skips them. The test that exposed the bug is not recorded, so it reruns; this also holds for a flaky(reruns=...) test whose earlier attempt failed. A test that failed with OOM in any phase is not recorded either: the first symptom can come before the probe can confirm the stuck state (e.g. in a teardown with no current context), so it reruns, and a genuine OOM fails again in the fresh process. Tests that failed are listed in a second file, and the run still fails if any exist after a restart, so a restart cannot turn a real failure green. A probe that raises propagates, and only a failed or interrupted session becomes exit code 75. Inert outside Windows. A genuine OOM leaves the probe False, so real failures still fail.
  • ci/tools/run-tests: run_pytest_with_restarts reruns the unfinished core tests in a fresh process on exit code 75, up to 3 times, with one JUnit file per attempt. Any other exit code passes through unchanged.

Testing

  • Reproduced the bug locally with PinnedMemoryResource create/allocate/close loops: 3 of 4 parallel processes broke after about 62,000 iterations, one at iteration 2. The probe was False before and True after.
  • Stop-and-resume checked with throwaway tests driven through run_pytest_with_restarts: exit 75 then the second attempt skips finished tests; an earlier real failure still ends in exit 1; a flaky test that fails, then trips the stuck state on its rerun, runs again after the restart; an OOM in a teardown before the stuck state is detected reruns after the restart and the run passes (it failed in Windows CI before 39ff0b7), while a teardown that always raises OOM still ends in exit 1. The restart loop was also checked with a fake pytest (2 restarts then success; give up after 3; other exit codes pass through).
  • No unit tests are added, because the code is temporary. Not yet run on a Windows runner.

Follow-ups

  • Gate on driver version so it switches off once the fixed driver is the CI minimum; remove it then.

Refs #3472. Tracking: NVBugs 7092346.

Checklist

  • I have read the Contributing Guidelines.
  • New or existing tests cover these changes. (Temporary test-infrastructure code; verified with throwaway scenarios, see Testing.)
  • The documentation is up to date with these changes.

🤖 Generated with Claude Code

juenglin and others added 2 commits December 2, 2026 17:41
On Windows (WDDM/MCDM), a host pinned pool with device access granted can
leave the process permanently returning CUDA_ERROR_OUT_OF_MEMORY (NVBugs
7092346, NVIDIA#3472). The test that trips it is arbitrary, so xfail would hide
real failures and blame the wrong tests.

After a failing setup/call phase that mentions OOM, probe cuCtxSynchronize
and cuMemGetInfo; if both return OOM the process is stuck. Stop the session
with exit code 75, record finished tests in a resume file, and skip them on
a restart. Inert outside Windows; a genuine OOM leaves the probe False.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…k in OOM

Wrap the cuda.core pytest run so exit code 75 (stuck driver, NVBugs 7092346)
reruns the unfinished tests in a new process, up to 3 times, with one JUnit
file per attempt. Every other exit code passes through unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@copy-pr-bot

copy-pr-bot Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions github-actions Bot added CI/CD CI/CD infrastructure cuda.core Everything related to the cuda.core module labels Dec 3, 2026

@jpascucci-nv jpascucci-nv 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.

Sol 6.1 high says - I'm not sure it's as important as it claims but -
[P1] Restarts can hide unrelated test failures — conftest.py:125
pytest_runtest_logfinish records failed tests as finished. If an ordinary assertion fails before a later test triggers sticky OOM, the restart deselects that earlier failure. The runner then returns only the final attempt’s status, allowing CI to pass.
Reproduced with the PR’s hooks and restart loop:

  • First attempt: 2 failed, exit 75.
  • Restart: 2 passed, 1 deselected, final exit 0.
    Only record successfully completed tests, or preserve unrelated failures across attempts.

juenglin and others added 2 commits December 3, 2026 10:19
The workaround is removed once the fixed driver is the minimum CI
driver, so its helpers do not need their own tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…tarts

A test that failed before the driver got stuck was recorded as finished
and skipped on restart, so a passing last attempt could turn the run
green. Record failed tests separately, and fail the run after a restart
if any exist. Failures are taken from the logged reports, because
pytest-rerunfailures relabels a failed attempt it will rerun as "rerun"
after makereport.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juenglin
juenglin marked this pull request as ready for review December 3, 2026 18:29
@jpascucci-nv jpascucci-nv added this to the cuda.core 1.4.0 milestone Dec 3, 2026
@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

Summary

Summary by CodeRabbit

  • Tests
    • On affected systems, test runs now stop when a test leaves CUDA in a persistent out-of-memory state, then resume unfinished tests in a fresh process, with up to three restart attempts.
    • Results from earlier attempts are retained, so a later successful run does not erase previously recorded test failures.
    • Other test exit codes remain unchanged. Failures in log processing affect the result only when pytest succeeds.

The change detects sticky CUDA OOM during pytest runs, records test progress, and retries the core CI test run after exit code 75. Each attempt writes a separate JUnit file.

Changes: Sticky OOM Test Restart Flow

Layer / File(s) Summary
OOM detection and test progress
cuda_core/tests/helpers/sticky_oom.py
Adds a Windows platform check and a probe for a stuck CUDA driver. Identifies OOM failures and reads or records completed test IDs.
Pytest OOM and resume hooks
cuda_core/tests/conftest.py
Checks driver state after OOM diagnostics. Tracks test outcomes, skips previously completed tests during collection, and sets the dedicated exit code after a sticky-OOM stop.
CI pytest restart handling
ci/tools/run-tests
Routes the core test run through a wrapper that retries exit code 75 up to three times and uses a separate JUnit file for each attempt. A successful retry still returns failure if an earlier attempt recorded failed tests.

Possibly related issues

  • NVIDIA/cuda-python issue 3472: The change detects a stuck driver after OOM and resumes the test run, but it does not address the reported pinned-memory OOM cascade.

Suggested reviewers: andy-jost, jpascucci-nv

Change: Other

Merge Risk: Moderate · up to bf9bf

This change only affects Windows CI test recovery after a sticky CUDA out-of-memory state. In one narrow case, a genuine test failure followed by an out-of-memory teardown can be lost when the test passes on the restart, so CI could report success despite that failure. Fix this before relying on the restart flow.

Security architecture risk: Moderate · up to bf9bf

The restart is bounded and confined to the test infrastructure, but a passing retry can hide a genuine earlier OOM-marked test failure, an independent pytest interruption, or a log-processing failure. The change affects confidence in the cuda.core CI result, not the shipped library.

Retained concerns

  • Minor · reliability · inferred: A genuine OOM-marked failure and a test that never ran leave the same checkpoint state. If a later sticky-OOM stop causes a restart and that earlier test passes in the fresh process, the wrapper can return success. Rerunning ambiguous OOM failures is deliberate; assuming a genuine failure must recur is not enforced by the protocol. Without a restart, pytest’s failure status still governs.
  • Minor · reliability · inferred: Once sticky OOM is latched, the finish hook rewrites any INTERRUPTED status that reaches it to 75 without checking what interrupted pytest. If an independent interruption reaches that hook and the wrapper survives, a successful retry can replace the interrupted verdict that the base would have propagated as a failure. This does not apply to cancellation that terminates the wrapper.
  • Trivial · reliability · inferred: The base failed the core step if log folding failed. The new runner preserves a log-folder error on an otherwise passing attempt, but discards it when pytest returns 75. A later successful retry can leave CI green despite incomplete logs for tests checkpointed on the earlier attempt and not rerun.

View findings in the submitted review

Security review details

Security Blast Radius

  • observed — The changed authority is over the wrapped core suite’s test selection, retry budget, and final CI verdict. The separate Cython invocation still uses the original pipeline, and the exact diff does not change production access controls or runner provisioning.

Trust Boundaries and Controls

  • observed — The outer runner supplies the checkpoint path and bounds the retries, but its decision relies on status and files produced by the test process. The ledgers are progress records, not an attestation independent of pytest.

Dependencies

  • observed — On Windows, a matching failed setup or call triggers a probe. It needs a current CUDA context and requires both context synchronization and memory-info calls to return OOM. No current context leaves the stop unconfirmed; probe exceptions are not swallowed. The fresh-process rerun does not independently distinguish a transient genuine OOM from the driver fault.

Data and control flow

  • observed — The runner clears the two ledgers at the start of each invocation. Pytest appends node IDs, and the next process reads the completion ledger before running tests. CI uploads the results directory on non-cancelled Windows wheel jobs; the wrapper does not merge the per-attempt XML files.

Resilience and Maintainability Implications

  • observed — Ordinary failures are appended to .failed before the test is marked complete. If that append raises, the completion append is not reached. If the failure append succeeds but completion does not, the test remains eligible to rerun and the failure still blocks a green retry. This corrects the earlier done-before-failed concern without making the two files an atomic transaction.
  • inferred — A passing retry establishes that the remaining selection passed and the failure ledger was empty, not that every earlier attempt was free of genuine failures. Ambiguous OOM-marked failures are rerun without a durable verdict record. JUnit files preserve separate attempts, but they do not participate in the wrapper’s pass decision.
  • observed — Internal and usage errors are no longer converted to sticky-OOM status. The remaining limit is stop attribution: the latch and INTERRUPTED status do not identify who interrupted pytest. Log folding likewise contributes its status when pytest succeeds, but not when pytest requests recovery.

Rollout and rollback

  • inferred — Pytest now requests the stop and the CI runner decides whether to resume. A new hook paired with the base runner fails the step on 75 without resuming; a new runner paired with base hooks has no sticky-OOM recovery signal. Operators who need recovery must run both sides of the protocol. Reverting both restores single-attempt behavior; a new wrapper invocation starts with cleared ledgers rather than resuming an earlier job.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments

Major 1
  1. important: Keep the triggering test eligible after an earlier rerun completion.
Minor 2
  1. important: Surface unexpected probe errors.
  2. Once sticky OOM is latched, the session-finish hook replaces pytest's incoming exit status with 75 without checking that the session stopped cleanly for that OOM. CI can therefore resume after a separate internal error that reaches the hook and return success after a passing retry. The two-file checkpoint adds a specific failure case: if an already-running failed test writes its finished entry but the corresponding failure append errors, the next attempt can skip that test without carrying its failure forward. The retry limit and failed-file check do not cover a failure that was never saved.
Trivial 1
  1. The merge-base core invocation failed if either pytest or the log folder failed under pipefail. The new wrapper disables errexit around the pipeline and retains only pytest's status. If pytest exits successfully but fold_pytest_log fails, the core test step can pass with incomplete logs. This affects every invocation of the wrapped core suite, not just Windows jobs that encounter sticky OOM.
Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4561499 and 1a77afa.

Files selected for processing: 3

  • ci/tools/run-tests
  • cuda_core/tests/conftest.py
  • cuda_core/tests/helpers/sticky_oom.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Comment thread cuda_core/tests/conftest.py Resolved
Comment thread cuda_core/tests/helpers/sticky_oom.py Resolved
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

- Do not record a test as finished after an attempt that
  pytest-rerunfailures will rerun, so a test that fails once and then
  exposes the stuck driver still runs in the restarted process.
- Let a broken probe raise instead of reporting a healthy driver.
- Turn the exit status into 75 only for a failed or interrupted run, so
  an internal or usage error is not retried.
- Write the failure entry before the finished entry.
- Fail the core test step again when the log folding step fails.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@juenglin
juenglin enabled auto-merge (squash) December 3, 2026 18:54

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments

Minor 1
  1. important: Propagate failed context-query statuses.
Trivial 3
  1. After a sticky OOM is latched, pytest_sessionfinish treats any INTERRUPTED status as permission to restart. It does not distinguish completion of the requested sticky stop from an independent interruption that reaches the same hook. Unlike the merge-base invocation, the wrapper can replace that interruption with a later passing verdict. This does not imply that cancellation which kills the wrapper is recoverable.
  2. The runner now propagates a log-folder failure when pytest succeeds, but not when pytest returns 75. A restart can therefore lead to a green run even though logging failed for an earlier attempt whose completed tests will not be rerun. The merge-base pipeline treated a log-folder failure as a failed core step.
  3. The recovery hooks exempt only one node ID from checkpointing. If tests overlap when the driver becomes stuck, another in-flight test can fail from the same process-wide condition after the latch is set, bypass the probe, and be checkpointed as a genuine failure. The next process skips that test and carries its failure forward even if the driver is healthy. This fails closed for CI verdicts, but can defeat recovery in threaded Windows runs; use of that combination in CI was not established.
Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1a77afa and e5b157f.

Files selected for processing: 3

  • ci/tools/run-tests
  • cuda_core/tests/conftest.py
  • cuda_core/tests/helpers/sticky_oom.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review.

Comment thread cuda_core/tests/helpers/sticky_oom.py Resolved
… restart

The first test of a stuck-driver cascade can fail with OOM before the
stuck state is detected, e.g. in a teardown with no current context to
probe. It was recorded as a finished failure, so the restart skipped it
and ci/tools/run-tests failed the run although every test passed in the
fresh process (seen in PR NVIDIA#3695's Windows CI).

Do not record a test whose attempt failed with OOM in any phase: it runs
again after a restart, where a genuine OOM fails again and a symptom of
NVBugs 7092346 passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use current_context_handle(), which raises on a failed cuCtxGetCurrent,
instead of treating any failure as "no context". cuCtxGetCurrent still
succeeds in the stuck state (it reported no context in NVIDIA#3695's Windows
CI), so this does not stop the restart from working.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments

Major 1
  1. important: Keep a non-OOM failure when a teardown OOM makes the test rerun.
Minor 2
  1. A genuine OOM-marked failure and a test that never ran leave the same checkpoint state. If a later sticky-OOM stop causes a restart and that earlier test passes in the fresh process, the wrapper can return success. Rerunning ambiguous OOM failures is deliberate; assuming a genuine failure must recur is not enforced by the protocol. Without a restart, pytest’s failure status still governs.
  2. Once sticky OOM is latched, the finish hook rewrites any INTERRUPTED status that reaches it to 75 without checking what interrupted pytest. If an independent interruption reaches that hook and the wrapper survives, a successful retry can replace the interrupted verdict that the base would have propagated as a failure. This does not apply to cancellation that terminates the wrapper.
Trivial 1
  1. The base failed the core step if log folding failed. The new runner preserves a log-folder error on an otherwise passing attempt, but discards it when pytest returns 75. A later successful retry can leave CI green despite incomplete logs for tests checkpointed on the earlier attempt and not rerun.
Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e5b157f and bf9bf51.

Files selected for processing: 2

  • cuda_core/tests/conftest.py
  • cuda_core/tests/helpers/sticky_oom.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

# has the one that exposed the stuck driver or one that failed with OOM
# before the stuck state was detected (e.g. in a teardown, which has no
# current context to probe): all must run again.
if nodeid in _rerun_nodeids or nodeid in _oom_nodeids or nodeid == _sticky_oom_nodeid:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Major · Functional Correctness · Heavy lift

important: Keep a non-OOM failure when a teardown OOM makes the test rerun.

In cuda_core/tests/conftest.py:151-153, a test with a call-phase failure and a teardown OOM never reaches record_finished. Keeping the test unfinished is correct, since it must rerun after a restart. The call failure, however, stays only in the process-local _failed_nodeids. In the fresh process after the restart, the test can pass. The finished-test record then has no entry for the call failure, so the run can pass despite that failure. The PR states that a restart must not turn a genuine failure green.

Persist a non-OOM failure in a form that survives the restart. Keep that failure separate from completion. Leave the test unfinished so it reruns. Tests whose failures are only OOM should keep their current treatment.

@juenglin
juenglin merged commit 366db83 into NVIDIA:main Dec 3, 2026
121 checks passed
juenglin added a commit to juenglin/cuda-python that referenced this pull request Dec 3, 2026
Follow-up to NVIDIA#3695, addressing the remaining CodeRabbit findings.

- A test whose call failed for a reason other than OOM and then hit an
  OOM in teardown was left unfinished so it reruns, but its real failure
  was dropped: a pass after the restart turned the run green. Such a test
  is now also listed in the .failed file.
- run_pytest_with_restarts ignored a log-folding failure in an attempt
  that exited with the sticky-OOM code. A fold failure in any attempt now
  fails the run.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/CD CI/CD infrastructure cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants