Fix the `test_each_browser_gets_only_the_sessions_it_watches` flake by waiting for the queued input it asserts on
This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.
- Closes #13424
Why we make these changes
test_each_browser_gets_only_the_sessions_it_watches failed in CI with assert ('queued', 'queued') == ('running', 'queued').
Root cause: the wait matched an earlier live message. b reads queued twice: once when its go input queues, before its turn starts, and again when and then queues behind the running turn. The test asserted on the first live message where b reads queued. When a's read loop had not yet taken its go as b's go queued, that message is the early one, published while a still read queued.
Fix: the test first waits for b to read running, then for the queued that and then publishes. By then a's turn has started and is held at its gate, so a reads running on any scheduling. No production change: WebService.live_changed publishes each state change in order, and the test now waits for the state it asserts.
The teardown TimeoutError follows from the failed assertion, not a second defect. The failure leaves both turns held at their gates, and /exit is not a during_turn command, so it queues behind a's turn. Fleet.exit's running.result(timeout=10) then times out (10.02 s in CI).
New public surface
None.
Verification
- Forced ordering. A local-only patch queues
a'sgowithout wakinga's read loop untilb'sgohas queued. That is the CI ordering. On main the test fails with CI's exact assertion, then the same teardownTimeoutError. On this branch it passes. - Repeated. Unforced on this branch,
uv run --with=pytest-repeat pytest tests/clai2/test_web_sessions.py::test_each_browser_gets_only_the_sessions_it_watches --count=30, without-n: 30 passed.
Forcing patch (local only, not committed)
# before the two `go` posts
inbox = fleet.launch._inbox
inbox.put = inbox._entries.append # queue without waking the read loop
# ... the two `go` posts ...
del inbox.put
fleet.portal.call(inbox._ready.set)
live messages socket one read up to the asserted one, as (session, state, busy):
| messages | |
|---|---|
| main | a queued busy, b idle → a queued busy, b queued busy (asserted) |
| this branch | … → a running busy, b queued busy (asserted) |
What changes for existing users
Nothing. The diff is one wait in one test.
PR decisions
2026-11-16 · our worker fixes #13424 · iter -
- Decision: David chose to fix the flake with a managed worker rather than the outside volunteer on the issue
- Why: David's call, relayed by the managing session
- Source: https://github.com/pydantic/pydantic-ai/issues/13424
- Session: a8a7e6a5-2e49-44b1-8f1f-65639818590c
2026-11-16 · no claim comment on #13424 · iter -
- Decision: Post nothing on the issue; the PR's Closes line links it
- Why: Managing session's call; it overrides the flake-claim comment step of pushing-commits-to-the-repo
- Source: https://github.com/pydantic/pydantic-ai/issues/13424
- Session: a8a7e6a5-2e49-44b1-8f1f-65639818590c
2026-11-16 · fix the test's wait, not production · iter -
- Decision: Wait for b to read running before waiting for its queued; no production change
- Why: Production publishes each state in order; the wait matched the live message from b's own go queuing, before either turn started (forced ordering reproduces CI's ('queued', 'queued'))
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/43489664177/job/132107318724
- Session: a8a7e6a5-2e49-44b1-8f1f-65639818590c
2026-11-16 · pre-push review 1 of 3 at 03720be22b28cc1eacc19df0f28716dd62c62720 · iter -
- Decision: Reserved: fresh light-tier (Haiku) reviewer via claude -p from a detached policy-base checkout at e551dbbcc3, read-only tools, no fan-out
- Why: Reviewed tree e5e385a6bb993db1c3382f0725e94ea7b1d70a7b; full branch c7586d79b6..03720be22b; first review; light tier because no hosted review has commented on earlier pushes
- Source: https://github.com/pydantic/pydantic-ai/tree/03720be22b28cc1eacc19df0f28716dd62c62720
- Session: a8a7e6a5-2e49-44b1-8f1f-65639818590c
2026-11-16 · pre-push review 1 of 3 at 03720be22b28cc1eacc19df0f28716dd62c62720 · iter -
- Decision: No valid findings; 2 dismissed with evidence: live messages are whole snapshots built at publish (WebService.live_message), and a's turning is set before gates['home'].started, so the post-running queued always carries a running; the matched message on main predates a's turn, no lag
- Why: Reviewed tree e5e385a6bb993db1c3382f0725e94ea7b1d70a7b; full branch c7586d79b6..03720be22b; haiku via claude -p from policy-base e551dbbcc3; candidate worktree unchanged during the review
- Source: https://github.com/pydantic/pydantic-ai/tree/03720be22b28cc1eacc19df0f28716dd62c62720
- Session: a8a7e6a5-2e49-44b1-8f1f-65639818590c
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.
Summary by cubic
Fixes the flaky test_each_browser_gets_only_the_sessions_it_watches by waiting for the queued input it actually asserts on.
- The old wait matched
b's firstqueuedstate, published when its owngoinput queued before either turn started. - The test now waits for
bto readrunningfirst, then for thequeuedthatand thenpublishes, soaalways readsrunning. - No production change; the diff is one additional wait in one test. Closes #13424.