Design out the `test_timeout_reads_stderr_back_over_a_slow_exec` and `test_exploration[openai]` test flakes
This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.
No linked issue: two CI flakes, each on a PR that does not touch the code under test, and each passed on rerun.
Why we make these changes
Sprites: test_timeout_reads_stderr_back_over_a_slow_exec failed assert '' == 'ready' on run 41726667191 (#12339). The command's 0.5 s deadline starts before the exec handshake, so a loaded runner killed the command before it printed to its stderr capture. The test now freezes the loop's clock, which anyio deadlines read, as #12347 did for IPythonCodeMode (row E2). The command opens a FIFO once it has printed, and only then does the test move the clock past the deadline. A real-time threading.Event wait bounds that read as a hang guard. The read-back's handshake moves the clock 1.5 s instead of sleeping. tests/clock_utils.py's Clock only offsets real time, so it cannot hold the deadline while the command starts.
Realtime: test_exploration[openai] raised FlakyFailure on run 41734704033 (#12386). Hypothesis fails a data.draw during which the global random state changes, and SessionMachine.start drew provider_options that way. The strategy itself is pure: another thread in the xdist worker advanced the global state during the draw, and did not on replay. provider_options is now an @initialize argument drawn through st.runner(); Hypothesis checks explicit draws and @given arguments, not stateful rule arguments.
That changes the derandomized examples, and test_exploration[gpt-live] then meets an existing GPT-Live case of known finding 8763c #3. A delegation the model started, still unread when a tool round's results go out, settles first, and the wait for the round's answer ends with it. It reproduces without Hypothesis on main's library code. Its violation names the round's response rather than the input, so the finding's matcher now reads that form too, on GPT-Live only, and test_known_live_tool_results_sent_while_an_unread_delegation_speaks pins it.
New public surface
None.
Verification
Proving tests: test_timeout_reads_stderr_back_over_a_slow_exec, test_exploration[openai] (unchanged; its draw moved in SessionMachine.start), and test_known_live_tool_results_sent_while_an_unread_delegation_speaks.
| Check | Old | New |
|---|---|---|
| Sprites, 200 serial runs under CPU stress (16 busy loops on 10 cores) | 4 failed, assert '' == 'ready' | 0 failed |
| Sprites, command 1 s slow to reach its first line | fails | passes |
Realtime [openai] exploration, 20 runs beside a thread advancing the global random | 4 failed, CI's FlakyFailure | 0 failed |
A Sprites mutant bounding the read-back by 1 s fails both versions. The Sprites module, test_simulation.py (all seven explorations) and test_invariants.py pass; pyright and ruff are clean.
What changes for existing users
Nothing: tests only.
PR decisions
2026-11-03 · frozen loop clock, not clock_utils.Clock · iter -
- Decision: The test freezes the running loop's clock and moves it itself; the command reports it has printed through a FIFO
- Why: Clock only adds an offset to real time, so it cannot keep the 0.5 s deadline from passing while the command starts; keeping timeout=0.5 avoids a longer timeout, and a FIFO avoids a polling wait (Flake fixes conditions)
- Source: https://github.com/pydantic/pydantic-ai/tree/fix/sprites-slow-exec-timeout-flake
- Session: 359abaa3-39b4-4ee8-8026-f8aa211091ae
2026-11-03 · no known-flakes entry · iter -
- Decision: check-ci-runs Known flakes and #8898 get no entry for this test
- Why: Neither lists it, and this PR removes the flake; an entry would only add a file outside the test module, which the flake-fix definition forbids
- Source: https://github.com/pydantic/pydantic-ai/tree/fix/sprites-slow-exec-timeout-flake
- Session: 359abaa3-39b4-4ee8-8026-f8aa211091ae
2026-11-04 · bundle the realtime exploration flake · iter -
- Decision: Fix tests/realtime/simulation/test_simulation.py::test_exploration[openai] in this PR too, by drawing provider_options as an @initialize argument
- Why: Requested by David; the strategy uses no random: another thread advanced the global random state during the only checked draw (DataObject.draw), as a forced repro with a random-advancing thread shows
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/41734704033
- Session: 359abaa3-39b4-4ee8-8026-f8aa211091ae
2026-11-04 · realtime fix lands outside the failing test module · iter -
- Decision: The fix edits tests/realtime/simulation/_machine.py, so the PR misses the Flake fixes definition's same-module condition; a maintainer merges
- Why: The draw lives in SessionMachine.start, shared by all seven machines; test_simulation.py only runs them
- Source: https://github.com/pydantic/pydantic-ai/tree/fix/sprites-slow-exec-timeout-flake
- Session: 359abaa3-39b4-4ee8-8026-f8aa211091ae
2026-11-04 · pre-push review 1 of 3 at ea3cff1caf7c0f75836eb197cd8cd24b7bbbc0fe · iter -
- Decision: reserved; dispatched
- Why: reviewed tree 88bbc54bf0789341dda410ab402e75231d81bf95; scope 854b3d08bd..ea3cff1caf (full branch, first review; Sprites fix only, realtime half pending a manager decision)
- Source: https://github.com/pydantic/pydantic-ai/tree/fix/sprites-slow-exec-timeout-flake
- Session: 359abaa3-39b4-4ee8-8026-f8aa211091ae
2026-11-04 · pre-push review 1 of 3 at ea3cff1caf7c0f75836eb197cd8cd24b7bbbc0fe · iter -
- Decision: remediated: FIFO wait bounded by a real-time thread join (hang guard, 120 s like the module's other hang guards), FIFO path shell-quoted
- Why: reviewed tree 88bbc54bf0789341dda410ab402e75231d81bf95; finding 1 valid in substance (a command that never reaches the FIFO hangs the frozen-clock test), though its example is not (the fixture patches the retry delays to 0); finding 2 cheap and correct
- Source: https://github.com/pydantic/pydantic-ai/tree/fix/sprites-slow-exec-timeout-flake
- Session: 359abaa3-39b4-4ee8-8026-f8aa211091ae
2026-11-04 · pre-push review 2 of 3 at 3fed89be13f529014baa3245fdebded48dbd57ef · iter -
- Decision: reserved; dispatched
- Why: reviewed tree 6143d9a4cfbe903bf0b73d4b79f72b9fa2b1c812; follow-up scope ea3cff1caf (tree 88bbc54bf0)..3fed89be13 plus call-1 findings
- Source: https://github.com/pydantic/pydantic-ai/tree/fix/sprites-slow-exec-timeout-flake
- Session: 359abaa3-39b4-4ee8-8026-f8aa211091ae
2026-11-04 · pre-push review 2 of 3 at 3fed89be13f529014baa3245fdebded48dbd57ef · iter -
- Decision: remediated: the FIFO reader sets a threading.Event after the read and the test asserts Event.wait(120), so a crashed read fails instead of passing as done; both call-1 findings confirmed fixed
- Why: reviewed tree 6143d9a4cfbe903bf0b73d4b79f72b9fa2b1c812; finding valid (is_alive cannot tell a finished read from a raised one)
- Source: https://github.com/pydantic/pydantic-ai/tree/fix/sprites-slow-exec-timeout-flake
- Session: 359abaa3-39b4-4ee8-8026-f8aa211091ae
2026-11-04 · exempt delta after review 2 · iter -
- Decision: Push the review-2 remediation without a third review, chaining from reviewed 3fed89be13f529014baa3245fdebded48dbd57ef; review 3 stays for the realtime half
- Why: Exempt row: test-harness repair, test code only; established expectation: the test confirms the FIFO handshake before moving the clock (review 2's own finding); module rerun
- Source: https://github.com/pydantic/pydantic-ai/tree/fix/sprites-slow-exec-timeout-flake
- Session: 359abaa3-39b4-4ee8-8026-f8aa211091ae
2026-11-04 · realtime half held for a decision · iter -
- Decision: The PR ships the Sprites fix alone until the manager picks split or fold for the realtime flake
- Why: The only reliable realtime fix (st.runner() argument draw) moves the derandomized examples, and test_exploration[gpt-live] then hits a GPT-Live wait.early violation that reproduces without Hypothesis; a warning filter still failed 1 of 20 runs
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/41734704033
- Session: 359abaa3-39b4-4ee8-8026-f8aa211091ae
- Supersedes: bundle the realtime exploration flake
2026-11-04 · fold the realtime flake; hold the enqueue · iter -
- Decision: David: do not enqueue #12449; fold the realtime exploration fix into it, recording the GPT-Live wait.early violation the new examples surface as a known finding
- Why: David chose fold over split when asked
- Source: https://github.com/pydantic/pydantic-ai/pull/12449
- Session: 359abaa3-39b4-4ee8-8026-f8aa211091ae
- Supersedes: realtime half held for a decision
2026-11-04 · pre-push review 3 of 3 at 0a315d3fb3be2ebe6a7da3ab26574a727196a301 · iter -
- Decision: reserved; dispatched
- Why: reviewed tree 2e1162acae453aeb839e188b0cefb5d851d2b7f7; follow-up scope 3fed89be13 (tree 6143d9a4cf)..0a315d3fb3 (review-2 remediation plus the realtime half) plus call-2 findings
- Source: https://github.com/pydantic/pydantic-ai/pull/12449
- Session: 359abaa3-39b4-4ee8-8026-f8aa211091ae
2026-11-04 · pre-push review 3 of 3 at 0a315d3fb3be2ebe6a7da3ab26574a727196a301 · iter -
- Decision: remediated: the response-form match is gated to GPT-Live, the only provider it was reproduced on; the 8763c #3 title names the open GPT-Live case by its condition (the self-started delegation settles first) and reads the fixed one as otherwise. Budget exhausted; pushing after local checks
- Why: reviewed tree 2e1162acae453aeb839e188b0cefb5d851d2b7f7; both findings valid (scope rule: place the change only where the defect reproduced; the title read as open and fixed at once); call-2 finding confirmed fixed
- Source: https://github.com/pydantic/pydantic-ai/pull/12449
- Session: 359abaa3-39b4-4ee8-8026-f8aa211091ae
2026-11-05 · defer: GPT-Live delegation settling first ends a tool round's wait · iter -
- Decision: Filed as #12571 instead of fixing here; route: immediate work, assigned to dsfaccini (pydanty:skip)
- Why: Out of scope for this PR — a library design decision in _LiveLifecycle resting on unrecorded provider behavior
- Source: https://github.com/pydantic/pydantic-ai/issues/12571
- Session: 359abaa3-39b4-4ee8-8026-f8aa211091ae
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.