Fix flaky `RenderSandbox` supervisor output-limit test

Merged
DS
21d ago
+3-1

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):

TestResult
main4 failed, DID NOT RAISE WorkspaceOutputLimitError
this PR4 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.run documents a "short output-drain grace", and core's LocalWorkspaceBackend uses 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 -

2026-11-14 · pre-push review 1 of 3 at 719517ce5bc28d5faad41caefc62c1b1bed1d424 · iter -

2026-11-14 · pre-push review 1 of 3 at 719517ce5bc28d5faad41caefc62c1b1bed1d424 · iter -

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 -

2026-11-14 · pre-push review 2 of 3 at 86deb58474efeee2b67ca5703c131ea0c9f455e1 · iter -

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.