Skip to content

Harden timing-dependent Studio backend tests (nvidia-smi cache, cold /api/health) - #12275

Merged
danielhanchen merged 3 commits into
mainfrom
fix-gpu-query-cache-test-races
Sep 29, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
fix-gpu-query-cache-test-races

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Problem

studio/backend/tests/test_gpu_query_cache.py::test_a_child_started_before_an_invalidation_is_not_joined (added in #11995) failed on a CI run of an unrelated PR (Python 3.13, a-k shard):

assert first_result == [[(0, 180000, 183359), (1, 170000, 183359)]]
At index 0 diff: [(0, 64, 183359), (1, 64, 183359)] != [(0, 180000, 183359), (1, 170000, 183359)]

It passes on reruns and locally, so it is timing dependent.

Cause

The test starts a thread that spawns the fake nvidia-smi, sleeps a fixed 0.15 s, then sets the free memory the NEXT reading should see. It assumes the first child has already read its state by then. On a loaded runner the Python child can start later than that, reads the new state, and returns 64 MiB. The caching code behaves correctly; the test raced.

Three more tests from #11995 have the same shape (start a thread, fixed sleep, change the fake's state): test_a_static_read_after_redetection_does_not_join_an_older_child, test_an_older_answer_does_not_overwrite_a_newer_empty_one and test_a_fit_check_does_not_join_an_older_child.

Fix

The fake writes its call line only after reading its state, so FakeSmi.wait_for_call(needle, count) polls for that line (30 s bound, assertion on timeout), and the four tests wait for one more matching call than before the thread started instead of sleeping. Test-only change.

Evidence

The four tests, pinned to one CPU core shared with 4 busy loops (so child start-up is slow, like a loaded runner), 3 runs each:

before after
contended core 1 failed, 3 passed (3 of 3 runs) 4 passed (3 of 3 runs)
whole file, idle host 38 passed 38 passed

Also: the cold /api/health launcher-deadline test

studio/backend/tests/test_health_answers_within_probe_budget.py::test_a_cold_health_call_answers_inside_the_launcher_deadline failed once on #11929's Python 3.13 shard:

AssertionError: the first /api/health call took 2.06s, past the 2.0s the desktop probe allows

The cold path is the 1.0 s detection budget wait plus one threadpool hop, and it measures 1.02 to 1.07 s both idle and on a core shared with busy loops, so that run was a one-off stall of about a second on the runner. The 2.0 s bound is the launcher's real timeout (read from the Rust client) and stays as is, as #9724 intended. If the first cold measurement misses it, a fresh process measures once more and the lower reading is asserted:

cold readings result
1.03 s pass
2.06 s, then 1.03 s (one stall) pass
2.3 s, then 2.2 s fail
real run with a 1.2 s delay injected into the first /api/health call fail

…e gpu_query tests

Four tests started a thread, slept a fixed 0.15 to 0.5 s, then changed the fake's state, assuming the older child had already read it. On a loaded runner the child can start later and read the state meant for the next reading (seen as test_a_child_started_before_an_invalidation_is_not_joined reading 64 MiB instead of 180000). The fake logs each call after reading its state, so wait for that line.
@danielhanchen danielhanchen self-assigned this Sep 29, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-29T14:58:54.539187Z db12e0c Manual request
🔒 Security Review ⚠️ Failed 2026-09-29T11:17:14.157990Z bfd66df PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…eadline test

A shared CI runner stalled one cold call to 2.06s against the desktop probe's 2.0s timeout (#11929's Python 3.13 shard); the same call takes 1.02-1.07s idle and on a contended core. A fresh process measures again and the lower reading is asserted, so a cold-path regression (checked with a 1.2s first-call delay) still fails while a one-off stall does not. The 2.0s bound itself is unchanged.
@danielhanchen danielhanchen changed the title Wait for the fake nvidia-smi child to start instead of sleeping in the gpu_query tests Harden timing-dependent Studio backend tests (nvidia-smi cache, cold /api/health) Sep 29, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: db12e0c8cf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 311572e into main Sep 29, 2026
27 of 32 checks passed
@danielhanchen
danielhanchen deleted the fix-gpu-query-cache-test-races branch September 29, 2026 19:16
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.

1 participant