Skip to content

Orchestrator shutdown tests: write the partial frame directly instead of racing the drainer - #17782

Merged
danielhanchen merged 2 commits into
mainfrom
fix/orchestrator-shutdown-tests-wait-for-child
Nov 14, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix/orchestrator-shutdown-tests-wait-for-child

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

studio/backend/tests/test_orchestrator_switch_waits.py::test_worker_crash_mid_frame_cannot_block_the_shutdown_deadline failed three times today on PRs that do not touch the orchestrator (#17645, #17743 and #17776), all with the same signature:

tests/test_orchestrator_switch_waits.py:385: assert runner.exitcode == 0
E   AssertionError: assert 1 == 0
  File ".../test_orchestrator_switch_waits.py", line 366, in crash_after_drain
    assert proc.exitcode == 1

The worker in that test does replies.put(<1 MiB frame>) and then assert replies._reader.poll(30) on its own end of the reply pipe before crashing. But the code under test, _shutdown_subprocess -> _drain_unread_replies, starts a drainer thread that reads that same pipe. When the drainer gets the whole frame first, the worker's poll finds nothing and waits its full 30 s, while the parent's proc.join(30) expires first and sees exitcode is None. test_forced_shutdown_does_not_read_an_interrupted_queue_frame polls the same pipe from the parent and has the same race.

The orchestrator is fine. The tests depended on thread scheduling.

Fix

A helper, _write_partial_frame, writes a length header claiming the whole 1 MiB frame plus the first 32 KiB of it straight to the pipe, then the worker crashes (or sleeps, for the interrupted-writer test). This is less than one pipe buffer, so the write never blocks. Any reader is left inside a partial frame every time, which is the state both tests mean to set up. The interrupted-writer test now waits on a wrote event instead of polling the shared pipe. On Windows, where PipeConnection has no raw write, the helper falls back to the old put.

Tests

  • Reproduced the CI failure on main by adding time.sleep(1) in the worker before its poll: assert 1 == 0, the same error as CI. With the same delays added around the new partial write, both tests still pass.
  • test_orchestrator_switch_waits.py: 14 passed, three times under -n 8.
  • Both tests ran 30 times on 10 concurrent loops, base and head. Both passed every time locally, so the flake is not reproducible here without the forced delay above.

… of racing the drainer

test_worker_crash_mid_frame_cannot_block_the_shutdown_deadline failed three times today on
unrelated PRs (#17645, #17743, #17776) with the runner exiting 1. Its worker put a 1 MiB
frame and then polled its own end of the reply pipe before crashing, but the shutdown path
under test starts a drainer thread that reads that same pipe. When the drainer took the whole
frame first, the poll waited its full 30 s and the parent's 30 s join expired first.
test_forced_shutdown_does_not_read_an_interrupted_queue_frame polls the same pipe the same way.

Write a length header plus 32 KiB of the frame straight to the pipe instead, so the reader is
left inside a partial frame deterministically, and signal the interrupted-writer test with an
event rather than a poll.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T23:52:10.967367Z 8e95b0e Manual request
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d17f4bfd30

ℹ️ 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".

Without it the worker could exit before the feeder thread wrote any of the frame, so the
crash test would pass on an empty pipe instead of an interrupted frame.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 8e95b0eed4

ℹ️ 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 fd7f6ad into main Nov 14, 2026
@danielhanchen
danielhanchen deleted the fix/orchestrator-shutdown-tests-wait-for-child branch November 14, 2026 23:54
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