Fix flaky `RenderSandbox` supervisor output-limit test
This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.
Closes #12717
test_supervisor_output_bound_preserves_captured_prefix fails with DID NOT RAISE WorkspaceOutputLimitError. It failed both merge-group runs of https://github.com/pydantic/pydantic-ai/pull/13327, which doesn't touch the harness (run 43489871730, run 43493273844), and was first reported from job 127376811467.
Root cause
The command, head -c 10485761, writes one byte past the 10 MiB limit and exits with up to a pipe buffer of that output still unread, the byte over the limit last. Once the direct child exits, the supervisor drains its pipes only for _DRAIN_GRACE, which the workspace_harness fixture patches to 0.2 s. On a slow runner the grace ends before the supervisor reads that byte, and the command reports a normal exit. The failing call in run 43489871730 took 0.53 s, under the product's 2 s grace, so the fixture's 0.2 s grace is the one that expired.
Fix
head now writes 1 MiB past the limit, more than a pipe buffer holds. It cannot exit until the supervisor has read past the limit, so the limit fires and stops the command while head still runs, and the drain grace never decides the outcome.
https://github.com/pydantic/pydantic-ai/pull/12933 by adtyavrdhn diagnosed the same cause and patches _DRAIN_GRACE to 300 s for this test instead. That moves the deadline rather than removing it. This PR lands the fix on its own, since #12933 bundles 17 flakes, so this test stops failing merge-queue runs sooner.
Verification
Forced reproduction: a temporary 1 s time.sleep in the supervisor right after it first sees the direct child exit, standing in for a runner stall, with 4 concurrent runs (pytest -n 4 --dist each):
| Test | Result |
|---|---|
main | 4 failed, DID NOT RAISE WorkspaceOutputLimitError |
| this PR | 4 passed |
On this PR the supervisor first sees head exit only after the limit has stopped it, so the stall lands after the outcome is decided. That ordering is the fix. Without the stall, 80 runs (5 rounds of 16 concurrent copies) passed on both main and this PR, so the forced stall is the reproduction.
Scope
- Test module only. The supervisor and its 2 s product grace are unchanged:
SupportsCommands.rundocuments a "short output-drain grace", and core'sLocalWorkspaceBackenduses the same 2 s. - The test no longer writes exactly one byte over the limit. No other test pinned that exact count, and its assertions on the limit and the 64 KiB preview are unchanged.
What changes for existing users
Nothing.
PR decisions
2026-11-14 · Fix #12717 outside #12933 despite its open claim · iter -
- Decision: Fix the flake in its own PR and comment on #12933 so it can drop this test
- Why: David asked for a separate small PR; #12933 bundles 17 flakes and conflicts with main
- Source: https://github.com/pydantic/pydantic-ai/issues/12717#issuecomment-6878215502
- Session: 8ec046ba-1fdc-4dc0-a53b-747f43e87a08
2026-11-14 · pre-push review 1 of 3 at 719517ce5bc28d5faad41caefc62c1b1bed1d424 · iter -
- Decision: reserved; dispatching reviewer (light tier)
- Why: tree 60e2202805ad870b49d7ce09ee28e99753a3a42f; scope fb64b4100..719517ce5 (full branch); first review
- Source: https://github.com/pydantic/pydantic-ai/tree/flaky-supervisor-output-bound
- Session: 8ec046ba-1fdc-4dc0-a53b-747f43e87a08
2026-11-14 · pre-push review 1 of 3 at 719517ce5bc28d5faad41caefc62c1b1bed1d424 · iter -
- Decision: remediated: replaced the 60 s drain-grace patch with an 11 MiB write that removes the race; filled verification; dropped the Closes bullet; stated David's override in the body; dismissed host-pipe attribution by removing it
- Why: tree 60e2202805ad870b49d7ce09ee28e99753a3a42f; scope fb64b4100..719517ce5 (full branch); the grace patch only moved the deadline and reads as a longer timeout under the flake-fix rule
- Source: https://github.com/pydantic/pydantic-ai/tree/flaky-supervisor-output-bound
- Session: 8ec046ba-1fdc-4dc0-a53b-747f43e87a08
2026-11-14 · Do not reuse #12933's drain-grace patch for this test · iter -
- Decision: Write 1 MiB past the limit so the limit fires while head runs, instead of patching _DRAIN_GRACE to a long value
- Why: A long grace still lets a long enough stall decide the outcome; the flake-fix rule excludes longer timeouts, and David asked for no change that only makes the race rarer
- Source: https://github.com/pydantic/pydantic-ai/pull/12933
- Session: 8ec046ba-1fdc-4dc0-a53b-747f43e87a08
2026-11-14 · pre-push review 2 of 3 at 86deb58474efeee2b67ca5703c131ea0c9f455e1 · iter -
- Decision: reserved; dispatching reviewer (light tier)
- Why: tree 07b776872b068088d42f5cb3094b9ac2c9325658; scope fb64b4100..86deb58474efeee2b67ca5703c131ea0c9f455e1 (full branch, substantive redesign since review 1 at 719517ce5)
- Source: https://github.com/pydantic/pydantic-ai/tree/flaky-supervisor-output-bound
- Session: 8ec046ba-1fdc-4dc0-a53b-747f43e87a08
2026-11-14 · pre-push review 2 of 3 at 86deb58474efeee2b67ca5703c131ea0c9f455e1 · iter -
- Decision: remediated PR body only: one ejected PR named; forced-stall row explained; attribution finding dismissed (line is aica-identity output); no code findings
- Why: tree 07b776872b068088d42f5cb3094b9ac2c9325658; scope fb64b4100..86deb5847 (full branch); pushed tree equals reviewed tree
- Source: https://github.com/pydantic/pydantic-ai/tree/flaky-supervisor-output-bound
- Session: 8ec046ba-1fdc-4dc0-a53b-747f43e87a08
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.
https://claude.ai/code/session_01BYcNCkCk4ChP59NLm6Rxb5
Summary by cubic
Fixes the flaky test_supervisor_output_bound_preserves_captured_prefix test so it no longer intermittently fails with DID NOT RAISE WorkspaceOutputLimitError on slow runners. Closes #12717.
The command head -c 10485761 wrote exactly one byte past the 10 MiB limit and exited with its last pipe buffer of output still unread, that over-limit byte last. When the supervisor's short drain grace expired before it read that byte, the command reported a normal exit. The command now writes 1 MiB past the limit, more than a pipe buffer holds, so head cannot exit until the supervisor reads past the limit and the limit fires while the command still runs.
Test module only. The supervisor and its 2 s product grace are unchanged, and there is no behavior change for existing users.