[gh-aw] Write session frames larger than the capture pipe whole instead of failing the run with `Errno 11`

Merged
DS
16d ago
+97-4

This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.

Why we make these changes

The engine's session recorder wrote each signed frame to the protected capture descriptor with a buffered print(..., flush=True). In CI that descriptor is non-blocking, so a frame larger than the 64 KiB pipe raised BlockingIOError: [Errno 11] write could not complete without blocking out of the event hook. The frame was cut off, the next frame reused its sequence number, and AWF rejected the capture. This is #13878: it failed the Community Demand recovery runs for incident #13809, which a later run recovered by landing 1.5 KB under the limit.

Over 14 days, 3 of 84 pydantic-ai engine runs wrote a frame over 64 KiB, and all 3 failed this way. Two were reasoning at the 16,384-output-token cap, in Community Demand runs 44341327034 and 44335212137. One was a grep result at the 64,000-character tool output cap, in CI Review run 42914239491.

The recorder now writes each line with a loop that takes partial writes and, when the pipe is full, waits with poll until the reader makes room. The descriptor's O_NONBLOCK flag is left as it is, because its open file description is shared with the processes that started the engine.

New public surface

None.

User-visible behavior

A reasoning part or tool result larger than the capture pipe, on a workflow compiled from this revision:

before: [Errno 11] write could not complete without blocking
        ERR_VALIDATION: AWF protected session capture could not be verified or published
after:  the frame reaches the capture whole and in sequence, and the run completes

Verification

  • test_frames_larger_than_a_full_non_blocking_capture_pipe_are_written_whole fills a non-blocking capture pipe, then writes a 100,000-character reasoning frame and a tool-result frame of 120 KB escaped JSON while the reader starts late. It fails on main with the Errno 11 error and passes here.
  • A manual run through the real harness script and generated recorder on Python 3.12, with a 75 KB frame and a reader 1 s late, raises the Errno 11 error on main and writes the frame whole here.

What changes for existing users

Nothing, except that runs which hit this failure now complete.

[!NOTE]
Follow-up pin step. This repository's locks compile the engine from the revision .github/workflows/shared/engine-zai.md imports (pydantic.md@c9c896e9), so their runs still fail this way until that import moves. After this PR merges, a follow-up PR moves the import to this PR's merge commit, recompiles the 12 locks, carries a live Community Demand run as proof, and closes #13878, as #12960 did for #12818. Workflows that import pydantic.md@main get the fix on their next recompile.

Telemetry gap. Logfire scrubs the content of a run's final tool result, which is the frame that failed, so its size could not be read back for run 42914239491 and was estimated by re-running the grep.

PR decisions

2026-11-18 · Take #13878 now · iter -

2026-11-18 · One PR closes both issues · iter -

2026-11-18 · Close #13809 on the recovery run · iter -

2026-11-18 · Fix every frame type · iter -

  • Decision: Fix #13878 for reasoning and tool-result frames so a frame of any size is written whole
  • Why: Logfire: 3/84 runs had a >64 KiB root frame, all failed, one from a tool result; manager answer in /home/agent/pydantic/ai/fix-gh-aw-engine-eagain-13878/local-notes/dispatch-20261118T200509Z.md
  • Source: https://github.com/pydantic/pydantic-ai/issues/13878
  • Session: 79ca73a8-3725-41b7-a089-8e355358d49a

2026-11-18 · Skip the O_NONBLOCK setter hunt · iter -

  • Decision: Make the write path correct in any descriptor mode: handle partial writes and EAGAIN by waiting until writable, without flipping O_NONBLOCK on a shared file description
  • Why: Manager answer in /home/agent/pydantic/ai/fix-gh-aw-engine-eagain-13878/local-notes/dispatch-20261118T200509Z.md
  • Source: https://github.com/pydantic/pydantic-ai/issues/13878
  • Session: 79ca73a8-3725-41b7-a089-8e355358d49a

2026-11-18 · Pin move only to a released harness version · iter -

  • Decision: Report where the fixed write path runs in CI and how CI picks it up before changing shared/engine-zai.md; 'A pin can only move to a released harness version'
  • Why: Manager answer in /home/agent/pydantic/ai/fix-gh-aw-engine-eagain-13878/local-notes/dispatch-20261118T200509Z.md
  • Source: https://github.com/pydantic/pydantic-ai/issues/13878
  • Session: 79ca73a8-3725-41b7-a089-8e355358d49a

2026-11-18 · Telemetry gap is a PR-body note · iter -

  • Decision: State in the PR body that the failing frame size is unreadable because Logfire scrubs it; no follow-up issue
  • Why: Manager answer in /home/agent/pydantic/ai/fix-gh-aw-engine-eagain-13878/local-notes/dispatch-20261118T200509Z.md
  • Source: https://github.com/pydantic/pydantic-ai/issues/13878
  • Session: 79ca73a8-3725-41b7-a089-8e355358d49a

2026-11-18 · pre-push review 1 of 3 at d1dcff4bd7954342a5f696c5f7555a39eafd3bd5 · iter -

2026-11-18 · Engine import pin in a follow-up PR · iter -

  • Decision: This PR: recorder fix and tests, shared/engine-zai.md untouched, body says Refs #13878 and Refs #13809; a follow-up PR moves the import to this PR's merge commit, recompiles the 12 locks, carries the live Community Demand run, and closes #13878
  • Why: A squash merge orphans this branch's commits, so an import pinned to one points at a SHA main never contains; #12960 precedent. Manager dispatch local-notes/dispatch-20261118T201801Z.md
  • Source: https://github.com/pydantic/pydantic-ai/pull/12960
  • Session: 79ca73a8-3725-41b7-a089-8e355358d49a
  • Supersedes: Close #13809 on the recovery run

2026-11-18 · pre-push review 1 of 3 at d1dcff4bd7954342a5f696c5f7555a39eafd3bd5 · iter -

2026-11-18 · pre-push review 2 of 3 at 93d0e6a46eaf96c7f78ebbef7c1bb76053c309ed · iter -

2026-11-18 · pre-push review 2 of 3 at 93d0e6a46eaf96c7f78ebbef7c1bb76053c309ed · iter -

2026-11-18 · Step 7 second opinion: none · iter -

  • Decision: No additional review surface for PR 13915
  • Why: Overmanager's pick via /home/agent/pydantic/ai/manager/local-notes/dispatch-20261118T205431Z.md: gh-aw engine recorder only, with a test that fails on main
  • Source: https://github.com/pydantic/pydantic-ai/pull/13915
  • Session: 79ca73a8-3725-41b7-a089-8e355358d49a

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_01HhQjZ9HJ1LmMnVuKkMGHVp


Summary by cubic

Fixes gh-aw engine runs failing with BlockingIOError: [Errno 11] when a session frame is larger than the non-blocking capture pipe. The recorder now writes each line with a loop that handles partial writes and waits for the reader to make room, so frames reach the capture whole and in sequence.

  • Leaves the descriptor's O_NONBLOCK flag untouched since its open file description is shared with the processes that started the engine.
  • Adds a test that fills a non-blocking pipe and writes reasoning and tool-result frames larger than the pipe while the reader starts late.