Design out the `test_timeout_reads_stderr_back_over_a_slow_exec` and `test_exploration[openai]` test flakes

Merged
DS
1mo ago
+86-20

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.

CheckOldNew
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 linefailspasses
Realtime [openai] exploration, 20 runs beside a thread advancing the global random4 failed, CI's FlakyFailure0 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 -

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 -

2026-11-04 · pre-push review 1 of 3 at ea3cff1caf7c0f75836eb197cd8cd24b7bbbc0fe · iter -

2026-11-04 · pre-push review 1 of 3 at ea3cff1caf7c0f75836eb197cd8cd24b7bbbc0fe · iter -

2026-11-04 · pre-push review 2 of 3 at 3fed89be13f529014baa3245fdebded48dbd57ef · iter -

2026-11-04 · pre-push review 2 of 3 at 3fed89be13f529014baa3245fdebded48dbd57ef · iter -

2026-11-04 · exempt delta after review 2 · iter -

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 -

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.