Let `on_run_error`, shielded capability cleanup and the model stream close run when an `anyio` scope cancels a run
This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.
No linked issue: the team found this bug while reviewing #10448. No user has reported it.
Why we make these changes
A run executes wrap_run, and each streamed model request executes wrap_model_request, in an asyncio task of its own, outside the caller's anyio cancel scopes. Teardown awaited those tasks plainly. Every re-cancel from a cancelled outer anyio scope (fail_after, move_on_after, a task-group cancel, a tool timeout= around a nested run) therefore reached the task as a native cancel, which ignores anyio shields. Shielded cleanup was cut, on_run_error was skipped, and an abandoned run_stream() left its model stream open. On early exit from agent.iter(), teardown also swallowed a native task.cancel().
Each of these tasks now runs under a cancel scope it owns (_utils.ScopedTask), and teardown passes the caller's cancellation on in the form it arrived. An anyio cancellation cancels the owned scope, so shielded work finishes and unshielded work is cut as before. A native cancellation is passed on once, with its message. An anyio cancellation that follows it still cancels the owned scope, and a native cancellation that follows an anyio one still reaches the task through the shielded wait. Teardown reads the task's outcome, as await did, so a hook frame that refers to its own task can't keep deps alive. Same family as #10341 and #10448.
The cancellation docs and the agent skill now say that cleanup must be shielded to survive an anyio cancellation, and that shielded cleanup doing I/O should be bounded with move_on_after(..., shield=True). The Daytona, E2B, Modal and Sprites on_run_error clean-up examples now shield destroy() under a 30-second bound.
Not in this PR: the startup wait in _run_lifecycle_hooks (cancel_and_drain(_ready_waiter, _wrap.task)) still sends one native cancel. Switching it to the scope cancel would change unshielded pre-handler cleanup under a deadline.
New public surface
None.
User-visible behavior
agent/abstract.py :: AbstractAgent.run() / .run_stream()
└─ agent/__init__.py :: Agent.iter()
└─ agent/__init__.py :: _run_lifecycle_hooks()
- └─ asyncio/tasks.py :: create_task(wrap_run(...))
- └─ asyncio/futures.py :: Future.__await__() # shielded cleanup cut, on_run_error skipped, early-exit native cancel lost
+ └─ _utils.py :: ScopedTask(wrap_run(...))
+ └─ _utils.py :: ScopedTask.result() # shielded cleanup finishes, on_run_error runs
+ └─ _utils.py :: ScopedTask.wait() # early exit: a native cancel propagates
└─ … unchanged machinery …
└─ _agent_graph.py :: ModelRequestNode.stream()
- └─ asyncio/tasks.py :: create_task(wrap_model_request(...))
- └─ asyncio/futures.py :: Future.__await__() # stream close cut, provider stream left open
+ └─ _utils.py :: ScopedTask(wrap_model_request(...))
+ └─ _utils.py :: ScopedTask.result() # stream closes; a returned response is recorded
Leaving node.stream() early under iter() in a cancelled anyio scope takes the same ModelRequestNode.stream() teardown: the model stream now closes before teardown returns, where main leaves it open past teardown and asyncio logs aclose(): asynchronous generator is already running at shutdown.
Verification
There are 37 new test cases across 18 tests. 17 fail on main and pass here. 6 pin ScopedTask invariants, which main has no ScopedTask to run against: it is freed without GC after its awaiter is cancelled, and a task error doesn't get the awaiter's cancellation as its __context__. The other 14 are guards that pass on both, and they pin what must not move:
- unshielded cleanup is still cut at the early-exit, success and stream sites (the
[False]cases); - a native cancel is delivered once, with its message, and one that lands after the hook returned reaches the caller with its message;
- a native cancel that lands in shielded
wrap_runcleanup after ananyiocancel still reaches it, so a cleanup error or the re-asserted cancel escapes the scope; - a cleanup failure after early exit is discarded;
- a response a capability returns after absorbing a cancel is still recorded;
- a
wrap_runthat holds its own task doesn't keepdepsalive afteriter()early exit.
Tests
test_iter_break_in_cancelled_scope_cancels_wrap_run_cleanup_like_the_scopetest_run_cancelled_by_anyio_scope_reaches_on_run_error_and_cancels_wrap_run_cleanup_like_the_scopetest_anyio_scope_cancelled_during_wrap_run_cleanup_cancels_it_like_the_scopetest_native_cancel_during_wrap_run_cleanup_is_delivered_oncetest_native_cancel_after_anyio_scope_cancel_reaches_shielded_wrap_run_cleanuptest_anyio_scope_cancelled_after_native_cancel_cancels_wrap_run_cleanup_like_the_scopetest_interrupted_iteration_releases_dependencies_of_wrap_run_holding_its_tasktest_native_cancel_during_teardown_releases_hook_frame_holding_its_tasktest_scoped_task_is_released_without_gc_after_its_awaiter_is_cancelledtest_scoped_task_result_raises_task_error_without_awaiter_cancellation_as_contexttest_native_cancel_after_hook_returned_reaches_caller_with_its_messagetest_tool_timeout_reaches_nested_run_error_hooktest_iter_break_teardown_propagates_external_cancellationtest_iter_early_exit_discards_wrap_run_cleanup_failuretest_stream_early_exit_in_cancelled_scope_closes_model_streamtest_run_stream_early_exit_in_cancelled_scope_cancels_model_request_cleanup_like_the_scopetest_run_stream_records_response_returned_after_absorbing_cancellationtest_run_stream_cancellation_is_not_masked_by_usage_limit_of_response_returned_after_it
What changes for existing users
Only runs cancelled from outside change: under a cancelled anyio scope, on_run_error now runs, shielded wrap_run and wrap_model_request cleanup finishes, an abandoned run_stream() closes its model stream, and a native cancel that reaches teardown ahead of the scope's own cancel is passed on as the scope's cancel; a run cancelled natively and then by its enclosing scope now ends cancelled instead of returning normally (or raising TimeoutError under fail_after); a native cancel during iter() early-exit teardown now propagates; and unshielded work is still cut.
PR decisions
2026-10-22 · early-exit teardown via ScopedTask, not cancel_and_drain · iter -
- Decision: early-exit teardown waits through _utils.ScopedTask; docs say cleanup must be shielded to survive an anyio cancel
- Why: removes the early-exit deadline trade-off pydanty flagged; unshielded cleanup is still cut
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#issuecomment-6226828231
2026-10-22 · bound shield-waiting tests with asyncio.timeout · iter -
- Decision: every new test whose teardown waits under a shield is bounded natively, with asyncio.timeout(READINESS_WAIT_TIMEOUT) or asyncio.wait(..., timeout=READINESS_WAIT_TIMEOUT)
- Why: a native bound, unlike anyio.fail_after, gets through the shield, so a broken drain fails instead of hanging CI
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#issuecomment-6226828231
2026-10-22 · keep silent discard of early-exit cleanup failure · iter -
- Decision: a wrap_run cleanup failure after iter() early exit stays discarded, no log
- Why: main drops the same error through its blanket except; logging would be a separate behavior change
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#issuecomment-6227785284
2026-10-22 · adopted PR #10479 at 2026-10-22 · iter -
- Decision: Branch-context bootstrapped from existing PR. Decisions prior to this entry are backfilled from PR conversation (no resolved review threads existed).
- Why: PR predates the branch-context setup in this worktree
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-22 · local merge 5bf34b003d dropped · iter -
- Decision: moved local branch to PR head 33c6179c2; old local merge kept at branch backup/local-merge-5bf34b003d
- Why: both parents are ancestors of the PR head and remerge-diff is empty, so it carried no PR changes
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-22 · CI Review: discard test can't fail -> invalid · iter -
- Decision: kept test_iter_early_exit_discards_wrap_run_cleanup_failure as is; clarified its comment only
- Why: removing the _wrap_task.exception() retrieval fails the unchanged test with RuntimeError: anyio's pytest TestRunner._exception_handler collects loop-reported exceptions and re-raises them after the test
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4351964727
2026-10-22 · CI Review: tool-timeout wall-clock race -> valid, fixed · iter -
- Decision: test_tool_timeout_reaches_nested_run_error_hook patches loop.time and the nested model request moves it past a 1s deadline
- Why: reproduced: a 100ms stall in the nested before_run made the timeout=0.05 version fail (run_errors == []); precedent is the Clock fixture in tests/test_request_timeout.py
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4351965168
2026-10-22 · pre-push gate exempt: test-only delta · iter -
- Decision: no pre-push-review dispatch for the CI Review remediation commit
- Why: exempt-delta row 'test-harness repairs': diff vs reviewed 31946d6a1 adds only test code/comments in tests/test_run_cancellation.py (intervening commits are no-conflict main merges and test-only 4987c3f58); established expectation is brief criterion 5; tests/test_run_cancellation.py passes
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-22 · Macroscope: UsageLimitExceeded masks anyio cancellation -> valid regression, fixed · iter -
- Decision: the anyio CancelledError branch in ModelRequestNode.stream() records the returned response's usage and appends it without the usage-limit check, then re-raises
- Why: reproduced: run_stream in a cancelled anyio scope, wrap_model_request substituting a 1000-token response, output_tokens_limit=100: main -> scope swallows the cancel; PR head -> UsageLimitExceeded escapes the scope and the response is lost. Precedent: the stream_error path skips the limit check so UsageLimitExceeded can't mask stream_error. Regression 1 of the 2-regression stop rule
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4354421893
2026-10-22 · pre-push review 1 of 3 at a3df7630f8495fd2eedb8bd0e77dc55dd9ceaa01 · iter -
- Decision: reserved; dispatching (budget counted per task: CI Review / Macroscope remediation)
- Why: tree d9cd5269be098bef33bae277046e1f9482c4c117; follow-up scope: PR-own commits 4987c3f58, 110e6c73f2, a3df7630f8 since reviewed 31946d6a1ff2d13953cb14e36e30f6cf4a006c9a (tree 24bd9651591e630c8bd64883c8d0e674f4e52bee); a3df7630f8 changes runtime
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-22 · pre-push review 1 of 3 at a3df7630f8495fd2eedb8bd0e77dc55dd9ceaa01 · iter -
- Decision: no findings
- Why: reviewed tree d9cd5269be098bef33bae277046e1f9482c4c117; scope 4987c3f58, 110e6c73f2, a3df7630f8 since 31946d6a1; fresh claude -p Opus from policy-base 2e1261eed
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-23 · final metadata check: 4 of 5 corrections kept · iter -
- Decision: Files-changed test links, one-sentence existing-users section (docs and out-of-scope notes moved to Why), path-form call-path nodes, added run_stream and asyncio labels; dropped the 'missing reserved entry' correction
- Why: each kept correction cites a pushing-commits-to-the-repo rule the body broke; the reserved pre-push entry was already in the body
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-24 · CI Review: unbounded shield in sandbox on_run_error examples -> valid, fixed · iter -
- Decision: six E2B/Modal/Sprites examples use anyio.move_on_after(30, shield=True); custom.md anyio note adds: bound shielded cleanup that does I/O with move_on_after(..., shield=True)
- Why: an unbounded shield lets a hung sandbox API outlive the user's fail_after deadline; repo precedent bounds every shielded I/O cleanup (workspaces/conformance.py uses move_on_after(30, shield=True); _workspace_provider.py, boxlite_sandbox/_backend.py, code_mode/_repl_store.py)
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4368108337
2026-10-24 · pre-push review 2 of 3 at 63d294d790ac8b6600c9b603168d9de19fb8c720 · iter -
- Decision: reserved; dispatching (CI Review bounded-shield remediation)
- Why: tree 3f49bc669d4783c33604283c512a86c8b18f1922; follow-up scope: 63d294d79 since reviewed a3df7630f8 (tree d9cd5269be098bef33bae277046e1f9482c4c117); docs code examples + one docs sentence, not an exempt delta
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-24 · pre-push review 2 of 3 at 63d294d790ac8b6600c9b603168d9de19fb8c720 · iter -
- Decision: remediated: comments and custom.md sentence now say the bound stops an indefinite hang, not one past the deadline
- Why: reviewed tree 3f49bc669d4783c33604283c512a86c8b18f1922; scope 63d294d79 since a3df7630f8; valid: move_on_after(30) starts when on_run_error runs, after fail_after fired, so a hung destroy() still runs up to 30s past the deadline; fresh claude -p Opus from policy-base ffbf82ef9
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-24 · pre-push review 3 of 3 at 3fe420c19f74cb375b61662e79c759e7e69f746f · iter -
- Decision: reserved; dispatching (verify review-2 wording finding)
- Why: tree 0e42198f849e105d39714accd376208af832fbaf; follow-up scope: 3fe420c19 since reviewed 63d294d79 (tree 3f49bc669d4783c33604283c512a86c8b18f1922); docs/** wording, not an exempt delta
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-24 · pre-push review 3 of 3 at 3fe420c19f74cb375b61662e79c759e7e69f746f · iter -
- Decision: no findings
- Why: reviewed tree 0e42198f849e105d39714accd376208af832fbaf; scope 3fe420c19 since 63d294d79; verified review-2 wording finding fixed; fresh claude -p Opus from policy-base ffbf82ef9; review budget exhausted
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-24 · CI: ScopedTask closure cycle keeps deps alive after interrupted iter() -> regression 2, stopped · iter -
- Decision: not fixed; reported to manager per the 2-regression stop rule; candidate fix saved at local-notes/scopedtask-cycle-fix.patch; local unpushed merge of upstream/main 8aa721276
- Why: reproduced: main's new tests/test_run_reference_cycles.py::test_interrupted_iteration_releases_dependencies[break|cancel] fail on PR head merged with main (green on main ffbf82ef9); ScopedTask.run() closes over self, so the cancelled task's CancelledError traceback -> run() frame -> self -> task is a cycle that pins wrap_run/_do_run frames and deps until GC; capturing a local scope instead fixes both, and test_run_reference_cycles/test_run_cancellation/test_streaming pass with it
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/40141291031
2026-10-25 · fold in ScopedTask cycle fix (regression 2), no 4th local review · iter -
- Decision: ScopedTask.run() closes over a local scope, not self, with a footgun comment; pushed c3ddd3bd2 with the no-conflict main merge 8aa721276; manager runs a fresh adversarial verifier on the pushed head instead of a 4th pre-push review
- Why: David chose option A after the 2-regression stop report; regression 2: main's test_interrupted_iteration_releases_dependencies[break|cancel] failed on PR+main because the cancelled task's traceback cycled back to ScopedTask; review budget 3 of 3 exhausted
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/40141291031
- Supersedes: CI: ScopedTask closure cycle keeps deps alive after interrupted iter() -> regression 2, stopped
2026-10-25 · fold in regressions 3 and 4 from the adversarial verifier on c3ddd3bd2 · iter -
- Decision: fix both in this PR; a separate reviewer then judges the PR's decisions and picks keep-and-polish or restart
- Why: David's call after the verifier and the manager reproduced both against main ffbf82ef9; past the 2-regression stop rule, so folded on his decision
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-25 · regression 3: early-exit teardown left a cancelled wrap_run task's CancelledError unread · iter -
- Decision: the early-exit branch of _run_lifecycle_hooks reads _wrap_task.exception() and suppresses the task's CancelledError, so a cancelled outcome is read as main's await read it; ModelRequestNode._stream needs no change, since its teardown always reads the outcome through wrap.result() or cancel_and_drain
- Why: reproduced: a wrap_run holding its own task (asyncio.timeout() as a local, or current_task()) kept deps alive until GC after iter() break or cancel on head, freed on main; ScopedTask.wait() uses asyncio.wait, which never reads the task's CancelledError, whose traceback pins the wrap_run frames; test_interrupted_iteration_releases_dependencies_of_wrap_run_holding_its_task
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-25 · regression 4: anyio cancel after a native cancel never reached ScopedTask's scope · iter -
- Decision: ScopedTask.wait() loops until the task finishes: an anyio cancellation cancels the task's scope and then waits shielded; a native one is passed on as one native cancel and the wait stays unshielded, so a later cancellation of the awaiter, anyio or native, still reaches the task
- Why: reproduced: native cancel then fail_after(0.5): head ran unshielded cleanup to completion or hung, main cut it at the deadline. Shape: a shield after the native cancel hides the outer scope's cancellation entirely (the effective deadline reads inf inside it), so it can't be detected there; going back to plain await would forward anyio's per-iteration re-cancels natively and cut shielded work, the defect this PR fixes. A second native cancel is forwarded like main's await forwards it; test_anyio_scope_cancelled_after_native_cancel_cancels_wrap_run_cleanup_like_the_scope
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-25 · pre-push gate at 127ce03f0ce28bf8a6540e5001ede230534e9b59: local budget exhausted · iter -
- Decision: no local pre-push review; the manager's outside reviewer covers this head
- Why: tree 5c19691d2b3f95785ca753bea38f3d55b46e20b1; budget 3 of 3 used (last reviewed 3fe420c19, tree 0e42198f849e105d39714accd376208af832fbaf); delta: main merge 8aa721276, ScopedTask closure fix c3ddd3bd2, regression 3 fix c72e580a0, regression 4 fix 127ce03f0; three target files pass
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-25 · independent review of 127ce03f0: keep and polish, apply items 1-8 · iter -
- Decision: keep the PR; apply the reviewer's polish items 1-8: centralize reading the outcome in ScopedTask (F1, F2, untested regression 2), forward the cancel message, strengthen the regression 4 test and pin F4, fix the custom.md, early-exit comment and wait() docstring wording, update the PR body, raise the tool-timeout test's timeouts, define CleanUpOnCancel once, fix the decision-2 wording
- Why: David's call on the reviewer's verdict: every lifetime regression traces to ScopedTask leaving the outcome read to its call sites; the bridge's other answers match plain anyio in one task
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-25 · F4 native cancel then the run's anyio scope cancel: keep the PR's outcome · iter -
- Decision: a run cancelled natively and then by its enclosing anyio scope ends cancelled (CancelledError propagates, scope.cancelled_caught is False) instead of main's normal return or TimeoutError; pinned in a test and stated in the PR body with the native-cancel-under-a-cancelled-anyio-scope case
- Why: David's call: matching main would lose the pending native cancel again and cut shielded cleanup; the PR's outcome is what asyncio.timeout does when an outside cancel is pending
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-25 · F11 StepPersistence.on_run_error unshielded save: deferred · iter -
- Decision: not in this PR; verify-then-mini-PR follow-up after this PR settles
- Why: the harness save isn't this PR's code; the PR only makes on_run_error reachable under an anyio cancel, where the unshielded save can be cut; needs its own verification of whether the snapshot can land without the run_failed event before a fix
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-25 · ScopedTask reads the outcome: shape · iter -
- Decision: _wait_passing_on_cancellation() returns the awaiter's first cancellation instead of raising it; wait() always reads the outcome and discards it; result() reads it only when it re-raises the awaiter's cancellation, and otherwise raises through task.result(); the early-exit read in _run_lifecycle_hooks is gone
- Why: reading inside the except block chains the task's CancelledError, which can be the run's own _run_error, to the awaiter's through context and adds a cycle; reading in wait() for result() too would swap the task's original CancelledError, with its message, for a fresh one; the reviewer's cycle diff shows the anyio stream cells unchanged and the native error-path cell now identical to main
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-25 · F1/F2 tests observe the hook's frame, not deps · iter -
- Decision: test_native_cancel_during_teardown_releases_hook_frame_holding_its_task[run|iter_break|run_stream] asserts a marker held only by the hook's frame is released
- Why: a cancellation propagating through the stdlib AsyncExitStack.aexit cycles with its frame and keeps deps until GC on head and main alike; the three cases fail at 127ce03f0 and on main (main's await re-raises the task's own CancelledError, so that stdlib cycle pins the hook's frames; iter_break also swallows the cancel there)
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-25 · regression 2 closure fix kept without a test that fails on revert · iter -
- Decision: ScopedTask.run() still closes over a local scope; no test pins it
- Why: reverting it in a scratch copy at 24a7a81cd leaves tests/test_run_reference_cycles.py and tests/test_run_cancellation.py passing, since every path now reads the outcome; it stays as the guard for a caller that never reads the task
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-25 · pre-push gate at ba93e4a0cc984be9f004c0e89c8700a283f813b0: local budget exhausted · iter -
- Decision: no local pre-push review; the manager's fresh adversarial verifier covers this head
- Why: tree 20107edf2c89af90e40966bd79982324de72de7c; budget 3 of 3 used; delta since the independent review of 127ce03f0: polish items 1-4 and 6-7 (24a7a81cd, ba93e4a0c); three target files pass; verifier repros and the reviewer's R-A and R-B cells match main
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-26 · second verifier on ba93e4a0c: fix B1 and B3, then another full adversarial round · iter -
- Decision: fix B1 (3.11 second native cancel during the final shielded drain skips the outcome read) and B3 (result() returns a value over a native cancel that never reached the task, losing the caller's message); soften result()'s docstring for B2; fix the early-exit comment nit; then a full verifier round on the new head
- Why: David's call; the manager reproduced B1 and B3; regressions 1-5 and F1/F2 stay fixed at ba93e4a0c
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-26 · B1: no drain after the native pass-on loop · iter -
- Decision: _wait_passing_on_cancellation drains shielded only in the anyio branch, where the task is still running; once the native loop ends the task is done, so it returns straight away and wait()/result() read the outcome outside the except block
- Why: on 3.11 that drain's gather yields even on a finished task, so a second native cancel raised out before the read; removing the await closes the path rather than reading inside except, which the decision log rules out; test_native_cancel_during_teardown_releases_hook_frame_holding_its_task[*-True] fails on 3.11 before the fix and runs on every version, since coverage is collected only on 3.14 and a 3.11-only test would leave its lines uncovered
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-26 · B3: a result wins over a native cancel only if the cancel reached the task · iter -
- Decision: ScopedTask records whether it passed a cancellation on; result() re-raises the awaiter's cancellation over a returned value when it didn't, as a plain await does
- Why: a native cancel landing after the hook returned, before the awaiter resumed, lost the caller's message to raise_if_cancelling's fresh error; test_native_cancel_after_hook_returned_reaches_caller_with_its_message fails on 3.13 before the fix and passes on main
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-26 · B2: result() docstring no longer claims plain-await parity for errors · iter -
- Decision: docstring says an error the task raised wins over a cancellation of the awaiter, without 'as with a plain await'; no 3.11 window named
- Why: after the B1 fix p2_window_error_sweep shows one cell (k=4) where the cancel wins, on 3.11 and 3.13 alike; its CancelledError carries CleanupError as context, the shape of main's k=2, so the second cancel landed after result() raised, during the error's propagation; the 3.11-only k=5 and k=6 cells are gone
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-26 · pre-push gate at 93ed830ba2496b015eab5a2da4590c021f877418: local budget exhausted · iter -
- Decision: no local pre-push review; the manager's next full adversarial round covers this head
- Why: tree 9c9b8db073cea5a8136a58cde88c29399fd98735; budget 3 of 3 used; delta since ba93e4a0c: B1 and B3 fixes, B2 docstring, early-exit comment (93ed830ba); three target files pass on 3.13 and 3.11; round-1 and round-2 repros and the R-A/R-B cells match main
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-26 · CI coverage: cancel-message test branch -> test-only fix · iter -
- Decision: test_native_cancel_after_hook_returned_reaches_caller_with_its_message uses one capability class per hook instead of branching on stream inside each hook
- Why: CI coverage at 93ed830ba missed tests/test_run_cancellation.py 2344->2346: with stream=True the run is cancelled before wrap_run returns; test-only delta, tests/test_run_cancellation.py passes (95)
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/40262673861
2026-10-26 · third verifier on 93ed830ba: fix C1, rerun every repro set, then David's review · iter -
- Decision: fix C1 (anyio cancel then a native cancel during the shielded drain loses the wrap_run cleanup error or the re-asserted absorbed cancel); fix the ModelRequestNode._stream comment and B3 test nits; rerun verify-10479, -r2, -r3 and the reviewer's leaks.py cells on 3.13 and 3.11; no new exploratory round
- Why: David's call; the manager reproduced C1 on 3.13 and main surfaces both the error and the re-asserted cancel; B1 and B3 held under attack
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-26 · C1: one drain loop, shielded once an anyio cancel arrives · iter -
- Decision: _wait_passing_on_cancellation keeps one loop with a shielded flag: an anyio cancel cancels the task's scope and shields the rest of the wait; every native cancel, before or after, is passed on with its message; result() returns a value only when a native cancel reached the task
- Why: the anyio branch's shielded gather was cut by a later native cancel and replaced the outcome with a CancelledError chained to the anyio cancel, which the scope swallowed; test_native_cancel_after_anyio_scope_cancel_reaches_shielded_wrap_run_cleanup[raise|return] fails at 10291c82f and passes on main; native-cancel-then-anyio-value probe now matches main (10291c82f returned the value)
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-26 · B3 test guards on 3.11 via asyncio.timeout · iter -
- Decision: test_native_cancel_after_hook_returned_reaches_caller_with_its_message waits with asyncio.timeout instead of asyncio.wait_for
- Why: on 3.11 wait_for waits in its own task, whose extra loop iterations let the run resume before the cancel lands; with asyncio.timeout the test fails against ba93e4a0c on 3.11.17 (re-asserted message instead of 'shutting down')
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-26 · pre-push gate at 1b5b1c1101c0169de7566633e8b7fae7eedf99bb: local budget exhausted · iter -
- Decision: no local pre-push review; the manager's verifier covers the new head
- Why: tree ad32e8b548cb152323999f0c9ea28518b7af911b; budget 3 of 3 used; delta since 10291c82f: C1 fix in ScopedTask._wait_passing_on_cancellation and result(), C1 test, B3 test 3.11 guard, _stream comment, concurrency.md bullet; three target files pass on 3.13 and 3.11
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-26 · pre-push gate at b1abc7a9b3881f9397f19d1ef45e5bb351440e0a: local budget exhausted · iter -
- Decision: no local pre-push review; push the upstream/main merge
- Why: tree e07013fbc63ab069a520c73be4aa46eeb3eab9be; budget 3 of 3 used; merge of 21a7ec01f; the only conflict was the _agent_graph.py _utils import list (ScopedTask beside #8822's aclose_if_supported); #8822 and #11009 don't touch the ModelRequestNode.stream() teardown; the three target files and tests/test_on_event.py pass on 3.13 and 3.11; CI had not run on 1b5b1c110 because the PR conflicted
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-26 · CI coverage: fallthrough after a with block -> test-only fix · iter -
- Decision: test_native_cancel_after_anyio_scope_cancel_reaches_shielded_wrap_run_cleanup returns after the shielded with block (the return variant reaches it) and keeps the unreachable raise AssertionError inside the try, after the wait that never returns
- Why: strict-no-cover at b1abc7a9b flagged tests/test_run_cancellation.py:2360 (raise AssertionError # pragma: no cover after the with): only the 3.14 coverage files record arc 2352->2360 from the with exit; a line trace on 3.11 and 3.13 never hits it, and both variants pass on 3.14, which they couldn't if it ran; exempt test-only delta, chained from b1abc7a9b; test passes on 3.13 and 3.11 and still fails at 10291c82f
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/40341785864
2026-10-27 · pydanty review on 3eabffae6: CHANGES_REQUESTED, 2 blocking -> triaged, no change yet · iter -
- Decision: triage both findings with repros and report to the manager before any push, reply or resolve; the review was partial (1 of 19 checks did not finish)
- Why: David asked for the review; the manager's dispatch holds every PR action until he sees the triage
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#issuecomment-6445300993
2026-10-27 · pydanty F2: stream-error teardown cancel_and_drain(wrap_task) -> (c) not a defect · iter -
- Decision: keep cancel_and_drain(wrap_task) in ModelRequestNode._stream's stream_error branch; the suggested 'await wrap.wait()' is net-negative
- Why: the line is unchanged from main and sends the one native cancel the consumer's stream error dooms the handler to; f2/stream_error_teardown.py gives identical results on head, main 0a25b73af and head+main across 14 cells on 3.13 and 3.11: the cancel lands while the hook is parked in its handler, so a shielded close after it finishes; only a second native cancel from outside cuts it, the same on main. The suggested fix stops cancelling the handler: after_model_request runs on every errored stream, and a consumer error followed by a scope cancel during cleanup loses the error (the scope swallows it)
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#issuecomment-6445300993
2026-10-27 · pydanty F1: overlap with #10258 -> complementary, textual conflict · iter -
- Decision: no change in this PR; whichever of #10479 and #10258 lands second resolves _run_lifecycle_hooks' error branch by keeping #10258's GeneratorExit/KeyboardInterrupt guard, #10479's _wrap.result() in the recovery branch, and #10479's early-exit else branch; merge order is David's call
- Why: #10258's four tests against 3eabffae6: the three GeneratorExit tests pass (they fail on main 0a25b73af), and the KeyboardInterrupt test fails as on main (KeyboardInterrupt escapes the loop); a scratch merge with that resolution passes all four, plus the three target files on 3.13 and 3.11; #10258 merges cleanly with main and conflicts only with #10479
- Source: https://github.com/pydantic/pydantic-ai/pull/10258
2026-10-27 · pydanty F2 reply posted: no change, suggested wrap.wait() net-negative · iter -
- Decision: replied on the PR with the verdict and the 14-cell table in ; cancel_and_drain(wrap_task) stays
- Why: David's go-ahead after confirming the line is byte-identical on upstream/main; load-bearing reason: wrap.wait() stops cancelling the handler, and loses the consumer's error under a cancelled scope. F1 (#10258 merge order) is held for David: no reply, no merge, #10258 untouched
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#issuecomment-6447177143
2026-10-27 · pydanty F1: #10258 lands first, this PR resolves the conflict after it · iter -
- Decision: after #10258 merges, merge main into this branch, apply scratchpad c1/f1_merge_resolution.diff (keep #10258's GeneratorExit/KeyboardInterrupt guard, this PR's _wrap.result() recovery and early-exit else), rerun #10258's four tests and the three target files on 3.13 and 3.11, then push; #10258 itself is not touched from this lane
- Why: David's call; the PRs are complementary and conflict only in _run_lifecycle_hooks' error branch; the resolution is already tested here (all four #10258 tests and the target files pass on 3.13 and 3.11), so resolving it in this PR keeps #10479's error-path and early-exit fixes from being undone
- Source: https://github.com/pydantic/pydantic-ai/pull/10258
2026-10-27 · post-#10258 resolution: redo against #10258's merged shape · iter -
- Decision: after #10258 merges, redo the _run_lifecycle_hooks conflict resolution against what merged, not against f1_merge_resolution.diff (which targets #10258's old head f2bc20242); then rerun #10258's tests plus the three target files on 3.13 and 3.11
- Why: #10258 changed shape: 2779aa2bb uses _utils.cancel_and_drain(_wrap_task) in the GeneratorExit/KeyboardInterrupt branch and adds _SHUTDOWN_EXCEPTIONS for the three guards; its head has since moved to e258997e3 (pins the _do_run shutdown guard with a test)
- Source: https://github.com/pydantic/pydantic-ai/pull/10258
2026-10-27 · post-#10258 resolution: correct the wrap_exc context comment · iter -
- Decision: fold a comment-only fix into the resolution: the comment on '_run_error.context = wrap_exc # pragma: lax no cover' must not say it 'Only fires for bugs in wrap_run implementations'; it fires whenever wrap_run raises an error other than the handler's, e.g. one that translates it
- Why: David's call; verified: a wrap_run that catches the iter() body's ValueError and raises Translated from it executes that line on head 3eabffae6 (line trace); main 0a25b73af reaches the same branch
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-27 · wrap_run's translated error lost on re-raise -> split · iter -
- Decision: split; manager validates after #10258/#10479 settle
- Why: pre-existing on main 0a25b73af and self-found; not filed; background and probes in local-notes/followups.md
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-27 · wrap_exc context comment: wording · iter -
- Decision: 'Write the comment fix to describe what the line does today. Do not promise that the context survives.' Planned: the block comment says wrap_run's other errors are set as the run error's context and the run error is raised (dropping 'so they're visible in tracebacks'); the pragma line's comment says it is reached when wrap_run raises its own error, e.g. one that translates the handler's
- Why: David's call; the context is overwritten by Python's implicit chaining on re-raise under run() and iter() (see the split entry), so 'visible in tracebacks' is false today; comment-only
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-27 · pre-push review 1 of 3 at 90936e9105f6abeff8c2d2b88e924eabef0949a8 (task: post-#10258 merge resolution) · iter -
- Decision: reserved; dispatching
- Why: tree 57cda41297d654d5fd0cf35baa6c3a58aee3eb3d; new task: David's dispatch 20261027T184904Z says 'Run the pre-push review' for the #10258 conflict resolution, and the budget is counted per task (as on 2026-10-22); policy-base and merge-base be15123e1; scope: the merge's conflict resolution (remerge-diff) and the PR's _run_lifecycle_hooks against #10258's merged shape, since 3eabffae6 (tree 4dc6e5ac192a94e162ed88b402d88c817dcdc115, pydanty-reviewed); not exempt: conflict resolution inside a merge
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-27 · pre-push review 1 of 3 at 90936e9105f6abeff8c2d2b88e924eabef0949a8 (task: post-#10258 merge resolution) · iter -
- Decision: remediated: the ScopedTask comment at the wrap_run task's creation now says teardown after the body returns, raises or exits early waits through ScopedTask, and _SHUTDOWN_EXCEPTIONS cancel and drain it instead
- Why: reviewed tree 57cda41297d654d5fd0cf35baa6c3a58aee3eb3d; scope: the merge's conflict resolution and the PR's _run_lifecycle_hooks against #10258's merged shape, since 3eabffae6; pydanty finding 1 verified resolved (the shutdown branch comes first, so GeneratorExit/KeyboardInterrupt never reach a ScopedTask wait; nothing of #10258 dropped); fresh claude -p Opus from policy-base be15123e1
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-27 · pre-push gate exempt at d00c0ac776353e3ee6187ed8b901fda8451d41a3: comment-only remediation · iter -
- Decision: no second review for the review-1 remediation
- Why: exempt-delta row 'Comments or docstrings only, no docs/** page': git diff 90936e910..d00c0ac77 changes three comment lines in agent/init.py and no non-comment line; chained from reviewed 90936e910 (tree 57cda41297d654d5fd0cf35baa6c3a58aee3eb3d)
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-27 · CI: Pyright time budget exceeded twice at d00c0ac77 -> main-wide margin, second rerun · iter -
- Decision: no code change; requested a second rerun of quality checks
- Why: Pyright passed with 0 errors both times but took 316.9s and 265.8s against PYRIGHT_TIME_BUDGET 260; today two other PRs failed the same step (core-native-compaction 274s, canonical-system-replay 263s) and many passing PR runs took 250-259s, so main sits at the budget; this PR adds no generic signatures since 3eabffae6 (241s step), and #8182 measures Pyright cost as proportional to code volume
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/40568058157
2026-10-27 · CI: Pyright time budget at d00c0ac77 -> second rerun passed · iter -
- Decision: quality checks and check passed on the second rerun; CI green on d00c0ac77
- Why: confirms the two budget overruns (316.9s, 265.8s, 0 errors each) were runner variance against a main-wide margin, not this PR
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/40568058157
2026-10-27 · pre-push gate exempt at 6746260455439787ad6d16b53528a24e113630e6: test case plus test-name reference · iter -
- Decision: no review dispatch; test_run_stream_early_exit_in_cancelled_scope_closes_model_stream becomes test_stream_early_exit_in_cancelled_scope_closes_model_stream[run_stream|iter], and agent_docs/concurrency.md cites the new name
- Why: manager's dispatch 20261027T195745Z: test-only commit for behavior the PR already changes; exempt-delta row 'missing coverage' for tests/test_streaming.py (established expectation: brief criterion 8, the ModelRequestNode.stream() teardown closes the stream); the concurrency.md edit swaps one test-name reference, a mechanical text refresh that touches no rubric rung (no code, behavior, API or policy); chained from reviewed 90936e910 via exempt d00c0ac77; the new [iter] case fails 10/10 on main be15123e1 source and passes 10/10 on head, on 3.13 and 3.11 ([run_stream] the same)
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-27 · pre-push review 1 of 3 at 84e41b9ed8d764cff78c0b528aa341f3d2539bc4 (task: douwebot remediation) · iter -
- Decision: reserved; dispatching
- Why: tree 021b9e153fe514ade235be1eeb6e9c725f9b6fc9; new task: dispatch 20261027T200943Z (douwebot triage), budget counted per task as on 2026-10-22 and 2026-10-27; policy-base 4572b6837, merge-base be15123e1; follow-up scope since reviewed 90936e910 (tree 57cda41297d654d5fd0cf35baa6c3a58aee3eb3d): exempt d00c0ac77 and 674626045, plus 84e41b9ed (Daytona on_run_error example on a docs/** page and its README twin, not exempt)
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4393834732
2026-10-27 · pre-push review 1 of 3 at 84e41b9ed8d764cff78c0b528aa341f3d2539bc4 (task: douwebot remediation) · iter -
- Decision: remediated: PR body 'Why' now names Daytona with E2B, Modal and Sprites as shielded on_run_error examples (metadata only, no commit)
- Why: reviewed tree 021b9e153fe514ade235be1eeb6e9c725f9b6fc9; scope d00c0ac77, 674626045, 84e41b9ed since 90936e910; prior finding (ScopedTask comment) verified fixed; Daytona example matches its siblings; fresh claude -p Opus from policy-base 4572b6837
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-27 · douwebot: unshielded Daytona on_run_error example -> valid, fixed · iter -
- Decision: the DaytonaSandbox on_run_error example in docs/harness/daytona-sandbox.md and its README twin uses anyio.move_on_after(30, shield=True) with its siblings' comment, saying 'delete' for Daytona
- Why: DaytonaSandbox arrived through a main merge (#10610) after the E2B/Modal/Sprites examples were shielded; its destroy() awaits AsyncDaytona.get and sandbox.delete, so under the cancelled anyio scope on_run_error now runs in, the unshielded call is cut like its siblings'; snippet passes ruff and pyright, docs parity passes
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4393834732
2026-10-27 · CI: Pyright reportUnusedImport in fake_daytona.py at 84e41b9ed -> new flake, rerun passed · iter -
- Decision: no code change; quality checks passed on rerun (attempt 2); CI green on 84e41b9ed
- Why: attempt 1 flagged tests/harness/daytona_sandbox/fake_daytona.py:31 'Import anyio.lowlevel is not accessed' though line 147 uses anyio.lowlevel.checkpoint(); the file is unchanged by this PR and identical on main 4572b6837, whose CI passed; local pyright 1.1.414 reports 0 errors on it; no other failed quality job since 18:00Z shows it; the PR changes no package versions
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/40580440729
2026-10-27 · douwebot: shared helper for wait()/result() re-raise -> skip (net-negative); scope -> _scope -> do · iter -
- Decision: no helper; added test_scoped_task_releases_itself_after_reraising_cancellation[wait|result x native|anyio] pinning the del step; renamed ScopedTask.scope to _scope
- Why: the suggested _discard_outcome_and_raise(cancellation) leaves the caller's cancellation local in the error's traceback, the cycle the del breaks: with it the ScopedTask outlives the run without GC (probe 3 of 4 cells, new test 4 of 4) while tests/test_run_reference_cycles.py and tests/test_run_cancellation.py still pass, since through an agent run the stdlib AsyncExitStack.aexit cycle hides it; the new test passes on head on 3.13 and 3.11.17; scope has no reader outside ScopedTask and _native_cancel_passed_on is already private
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4394162696
2026-10-27 · pre-push review 2 of 3 at 343cb32fea5eaa988094e51da9cfc0096dcdef13 (task: douwebot remediation) · iter -
- Decision: reserved; dispatching
- Why: tree 311ca73b2adc9e19bc4b85695e118cd01bf5d54d; policy-base 2c99448f3, merge-base be15123e1; follow-up scope 343cb32fe since reviewed 84e41b9ed (tree 021b9e153fe514ade235be1eeb6e9c725f9b6fc9): new ScopedTask release test plus ScopedTask.scope -> _scope, code, not an exempt delta
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4394162696
2026-10-27 · pre-push review 2 of 3 at 343cb32fea5eaa988094e51da9cfc0096dcdef13 (task: douwebot remediation) · iter -
- Decision: remediated: PR body Verification counts 35 cases across 17 tests and lists the ScopedTask release test as pinning an internal invariant (metadata only, no commit)
- Why: reviewed tree 311ca73b2adc9e19bc4b85695e118cd01bf5d54d; scope 343cb32fe since 84e41b9ed; rename has no leftover readers, the test is natively bounded and its unit-level reason is stated; fresh claude -p Opus from policy-base 2c99448f3
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-27 · pre-push review 3 of 3 at 608b5449ed2e9d302f182360e1c343090f1ff88a (task: douwebot remediation) · iter -
- Decision: reserved; dispatching
- Why: tree b9305d9fad3ec3a53c9ef5a8a3d59845676edc7c; policy-base 59ba7bf64, merge-base be15123e1; follow-up scope 608b5449e since reviewed 343cb32fe (tree 311ca73b2adc9e19bc4b85695e118cd01bf5d54d): agent skill sentence and agent_docs/concurrency.md bullet split, instruction text, not an exempt delta
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4394625493
2026-10-27 · pre-push review 3 of 3 at 608b5449ed2e9d302f182360e1c343090f1ff88a (task: douwebot remediation) · iter -
- Decision: no findings
- Why: reviewed tree b9305d9fad3ec3a53c9ef5a8a3d59845676edc7c; scope 608b5449e since 343cb32fe; fresh claude -p Opus from policy-base 59ba7bf64; review budget for this task exhausted
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-27 · douwebot: agent skill still advises unshielded wrap_run try/finally -> valid, fixed; concurrency.md ScopedTask bullet -> valid, split · iter -
- Decision: CAPABILITIES-AND-HOOKS.md now says to run awaited cleanup that must finish inside anyio.CancelScope(shield=True) and bound I/O cleanup with anyio.move_on_after(..., shield=True); the concurrency.md bullet is two bullets, each citing its own tests, and names ScopedTask.wait()/result() as the outcome readers
- Why: root AGENTS.md: update agent skills when they need to reflect the correct mechanics, and the skill contradicted this PR's custom.md note; the old bullet put the ScopedTask tests after the cancel_and_drain sentence, and its 'Both read the task's outcome' meant wait()/result(), since cancel_and_drain's gather(..., return_exceptions=True) does not read it
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4394625493
2026-10-27 · douwebot on 608b5449e: CHANGES_REQUESTED, 1 finding (react: str -> Literal) -> held for David · iter -
- Decision: not fixed; reported verbatim to the manager per dispatch 20261027T220501Z; David decides whether to take another cycle; his alias question (_wrap_task = _wrap.task) is answered on the thread and left open
- Why: pre-push review budget for this task is spent; finding verified: test_native_cancel_after_anyio_scope_cancel_reaches_shielded_wrap_run_cleanup types react as str while the PR's other parametrized tests use Literal
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4394915444
2026-10-27 · _wrap_task alias -> inline _wrap.task (David) · iter -
- Decision: replace _wrap_task with _wrap.task at all six sites in _run_lifecycle_hooks and drop the alias; held unpushed because douwebot's verdict on 608b5449e has a comment (dispatch 20261027T224912Z)
- Why: David's call on the thread: inline it
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4394841577
2026-10-27 · pre-push gate at ca1c41845c6497c880c95cf25957f2e9d98d4cbe: local budget exhausted · iter -
- Decision: no local pre-push review; push the _wrap.task inline (David) and douwebot's react Literal fix together (dispatch 20261027T225314Z)
- Why: tree 53877ba9a022be8c80a4558ee37fbcbd783da373; budget 3 of 3 used for the douwebot-remediation task (last reviewed 608b5449e, tree b9305d9fad3ec3a53c9ef5a8a3d59845676edc7c); delta: _wrap_task alias removed and its six uses plus three comments read _wrap.task, three tests/test_agent.py docstrings follow, react typed Literal['raise', 'return']; pyright and ruff clean; tests/test_run_cancellation.py, test_run_reference_cycles.py, test_streaming.py, test_agent.py and realtime/test_capabilities.py pass on 3.13.3 and 3.11.17 except test_unsupported_native_tool_falls_back_to_local and test_supported_native_tool_drops_local_fallback, which fail the same way on main 45eb9d0d9 (blockbuster BlockingError on os.listdir in the ddgs import; CI's all-extras lane disables blockbuster)
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-27 · douwebot on ca1c41845: clean APPROVE · iter -
- Decision: douwebot merge-bar gate met on ca1c41845: APPROVE, 'No blocking findings.', no douwebot comments on that head, run 40602763215 succeeded; CI green (run 40599913340); no open review threads
- Why: remaining for the L merge bar: one human approval; pydanty's CHANGES_REQUESTED review 5669833284 on 3eabffae6 is David's to clear
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-27 · final metadata check at ca1c41845: 4 of 4 corrections kept · iter -
- Decision: mirrored the last decision entry, aligned the compatibility checklist line with the template, added the sandbox and hooks labels
- Why: fresh claude -p Haiku from policy-base ca2e78a9c; each correction cites a rule the metadata broke: the skill's decisions-mirror sync, the PR template's checklist text, and 'Add existing topic labels for every subject materially covered' (eight sandbox docs/README files change; capability-hook PRs such as #8978 carry hooks)
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-27 · pydanty review 5669833284 dismissal (David) -> blocked by local permission classifier, not done · iter -
- Decision: dismissal not sent; the PUT .../reviews/5669833284/dismissals call was denied by the Claude Code auto-mode classifier as an external system write; reported to the manager with the prepared message, no workaround attempted
- Why: David's call via dispatch 20261027T234053Z: F1 resolved by merging #10258 (90936e910), F2 answered with evidence the line is unchanged from main
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#issuecomment-6445300993
2026-10-28 · wrap_task alias in ModelRequestNode._stream -> inline prepared, held for David · iter -
- Decision: inlined wrap.task in _agent_graph.py (12 uses and comments) plus four test docstrings, local commit 839dfe780, not pushed; thread answered and left open
- Why: David asked why _agent_graph.py wasn't inlined like agent/init.py; the earlier inline was scoped to the thread's file; pushing restarts CI and douwebot after the clean APPROVE on ca1c41845, so the extra cycle is David's call
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4395708227
2026-10-28 · pydanty review 5669833284 dismissed by the manager · iter -
- Decision: dismissed from the manager session with local-notes/pydanty-dismissal-message.md; GraphQL shows reviewDecision APPROVED and the pydanty review DISMISSED
- Why: David's call (dispatch 20261027T234053Z); this lane's call was denied by the local permission classifier; F1 resolved by merging #10258 (90936e910), F2 answered with evidence the line is unchanged from main
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#issuecomment-6445300993
- Supersedes: pydanty review 5669833284 dismissal (David) -> blocked by local permission classifier, not done
2026-10-28 · 839dfe780 push held for cleanup-review proposals · iter -
- Decision: David approved pushing 839dfe780; hold it until the manager sends the accepted proposals from the fresh-context cleanup review of _utils.py, then push both together for one CI and douwebot round; no _utils.py edits until then
- Why: dispatch 20261028T003446Z
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4395708227
2026-10-28 · cleanup review 1: result() return-path del gets its real reason and a pinning case · iter -
- Decision: the comment on the del before 'return self.task.result()' says the cancellation's traceback keeps wait_passing_on_cancellation()'s frame linked to result()'s through f_back on some CPython versions; test_scoped_task_releases_itself_after_reraising_cancellation becomes test_scoped_task_is_released_without_gc_after_its_awaiter_is_cancelled with a result/native/body-returns case
- Why: David accepted the fresh-context reviewer's proposal; the old comment named the raise path, where the object stays alive with or without the del as with a plain await; the new case fails without the del on 3.13.3 (reviewer also reproduced on 3.12.15; not on 3.11.17, 3.13.16, 3.14.10) and passes on 3.11
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-28 · cleanup review 2: ScopedTask run() comment no longer names only wait() · iter -
- Decision: 'The scope caught the cancellation passed on to it: end cancelled, as a native cancellation would.'
- Why: David accepted the reviewer's proposal; wait() and result() both pass the cancellation on; comment-only
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-28 · cleanup review 3: _wait_passing_on_cancellation -> wait_passing_on_cancellation · iter -
- Decision: renamed at its three sites; its docstring states the contract: it returns the cancellation instead of raising it, and a caller must del it in the frame that raises it or returns
- Why: David accepted the reviewer's proposal, per 'Avoid private methods in private modules'; the docstring carries what the underscore signalled; no agent_docs mention it
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-28 · cleanup review 4: direct ScopedTask test for the outcome-read shape · iter -
- Decision: tests/test_utils.py::test_scoped_task_result_raises_task_error_without_awaiter_cancellation_as_context: the body absorbs a native cancel, then raises ValueError outside its except; asserts exc.context is None
- Why: David accepted the reviewer's proposal; with result() reading the task inside the except block the test fails (CancelledError('stop') becomes the ValueError's context)
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-28 · pre-push gate at 9f1a1c520deb26467581106e1904959917ebe4bb: local budget exhausted · iter -
- Decision: no local pre-push review; push 839dfe780 (_agent_graph.py wrap.task inline) and 9f1a1c520 (the four accepted cleanup-review proposals) together (dispatch 20261028T010114Z)
- Why: tree 092032b44834ab801c27116d8ab06cb10b727437; budget 3 of 3 used for the douwebot-remediation task (last reviewed 608b5449e); the fresh-context cleanup review that produced the proposals ran from the manager; tests/test_run_cancellation.py, test_run_reference_cycles.py, test_streaming.py, test_utils.py, test_capability_hooks.py pass on 3.13.3 and 3.11.17 (640 each), and test_agent.py passed on 839dfe780; pyright and ruff clean
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
2026-10-28 · douwebot on 9f1a1c520: APPROVE with 1 optional comment -> held for the manager · iter -
- Decision: not fixed, no reply, thread left open; reported verbatim per dispatch 20261028T011054Z; classified net-negative -> skip: reverting to _wait_passing_on_cancellation undoes cleanup review 3
- Why: run 40615759619 succeeded; APPROVE 5676723904 'No blocking findings.' on the head; the comment asks to re-underscore a rename David accepted under 'Avoid private methods in private modules' (_utils is private); the del contract lives in its docstring; its 'decision log refers to the underscored name' cites entries older than the rename entry the PR body already mirrors; CI green on 9f1a1c520
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4396054261
2026-10-28 · douwebot underscore comment on 9f1a1c520 -> skip, resolved (David) · iter -
- Decision: wait_passing_on_cancellation keeps its public name; replied, reacted 👎, resolved; douwebot not re-run, its APPROVE 5676723904 on 9f1a1c520 stands
- Why: David's call (dispatch 20261028T014754Z): 'Avoid private methods in private modules' (_utils is private); the docstring states the del contract
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4396113872
- Supersedes: douwebot on 9f1a1c520: APPROVE with 1 optional comment -> held for the manager
2026-10-29 · pre-push review 1 of 3 at ebc8b89283e2cd8e6fcbc5bab1a6b2ec1c63e8f5 (task: main merge 446cb61ad) · iter -
- Decision: reserved; dispatching
- Why: tree 0d6c7ed35072307755edb0b976f99147e477a1bb; new task: dispatch 20261029T192104Z (bring current with main), budget counted per task as on 2026-10-22 and 2026-10-27; policy-base and merge-base 446cb61ad; scope: the merge's conflict resolution in ModelRequestNode._stream (remerge-diff) and the PR's _stream, ScopedTask and _run_lifecycle_hooks against main's changes since be15123e1, incl. #9348; not exempt: conflict resolution inside a merge
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
- Session: fb395664-431b-455b-b5b9-e9fd16490c56
2026-10-29 · pre-push review 1 of 3 at ebc8b89284dbb57609014de192ea6007a1b1a477 (task: main merge 446cb61ad) · iter -
- Decision: remediated: agent_docs/concurrency.md cites test_scoped_task_is_released_without_gc_after_its_awaiter_is_cancelled; the readiness-wait test docstring and comment in tests/test_streaming.py name _serve_stream_offers(handoff, ready_waiter, wrap.task)
- Why: reviewed tree 0d6c7ed35072307755edb0b976f99147e477a1bb; the reserved entry's SHA ebc8b89283e2cd8e6fcbc5bab1a6b2ec1c63e8f5 was mistyped, the reviewer resolved and reviewed ebc8b8928 = ebc8b89284dbb57609014de192ea6007a1b1a477; conflict resolution found correct (ScopedTask(_outside_attempts(...)) nests like main, #9348's offers loop and priming commit kept whole, the _stream cancel branch still mirrors main's success path); both findings valid: the test was renamed in 9f1a1c520, and #9348 replaced the asyncio.wait those lines named; fresh claude -p Opus from policy-base 446cb61ad
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
- Session: fb395664-431b-455b-b5b9-e9fd16490c56
2026-10-29 · pre-push gate exempt at ab404fd0ba62fe5fdcd54b5d0082c21b39b07d9c: review-1 remediation · iter -
- Decision: no second review; push the merge and the remediation together
- Why: chained from reviewed ebc8b89284dbb57609014de192ea6007a1b1a477 (tree 0d6c7ed35072307755edb0b976f99147e477a1bb); delta: tests/test_streaming.py docstring and comment only (exempt row 'Comments or docstrings only, no docs/** page'), and agent_docs/concurrency.md swaps one test-name reference for the existing test's name, a mechanical text refresh that touches no rubric rung (no code, behavior, API or policy), as on 2026-10-27 at 674626045
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
- Session: fb395664-431b-455b-b5b9-e9fd16490c56
2026-10-29 · douwebot on ab404fd0b: APPROVE with 1 optional comment (bare timeout) -> valid, fix prepared, held · iter -
- Decision: test_scoped_task_result_raises_task_error_without_awaiter_cancellation_as_context waits with a module-level READINESS_WAIT_TIMEOUT = 5 in tests/test_utils.py; local commit 6f09bf016, not pushed; no reply, thread open; reported to the manager
- Why: run 40971295254 succeeded, APPROVE 5706161282 'No blocking findings.' on ab404fd0b; valid: agent_docs/concurrency.md asks for a module-level READINESS_WAIT_TIMEOUT and the test came in with 9f1a1c520; held like 839dfe780 because pushing restarts CI and douwebot, the manager's call; the test passes; exempt test-only delta from reviewed ebc8b8928 if pushed
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4418860197
- Session: fb395664-431b-455b-b5b9-e9fd16490c56
2026-10-29 · pre-push gate exempt at 6f09bf0167ea24c73f8d244fccf84e209d11f72d: douwebot timeout-constant fix · iter -
- Decision: no review dispatch; push 6f09bf016 (David's call, dispatch 20261029T232324Z)
- Why: exempt row 'Missing coverage, test-harness repairs': git diff ab404fd0b..6f09bf0167ea24c73f8d244fccf84e209d11f72d touches only tests/test_utils.py (module-level READINESS_WAIT_TIMEOUT and its one use); established expectation: agent_docs/concurrency.md asks shield-waiting tests to bound waits with a module-level READINESS_WAIT_TIMEOUT; the test passes; chained from reviewed ebc8b89284dbb57609014de192ea6007a1b1a477 via exempt ab404fd0b
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4418860197
- Session: fb395664-431b-455b-b5b9-e9fd16490c56
2026-10-29 · douwebot timeout-constant comment -> fixed and pushed (David), thread resolved · iter -
- Decision: pushed 6f09bf016; replied with the commit link, reacted 👍, resolved; douwebot owed on the new head once CI is green
- Why: David's call (dispatch 20261029T232324Z): test-only, agent_docs/concurrency.md asks for it, and no human approval existed to invalidate
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#discussion_r4418930130
- Session: fb395664-431b-455b-b5b9-e9fd16490c56
- Supersedes: douwebot on ab404fd0b: APPROVE with 1 optional comment (bare timeout) -> valid, fix prepared, held
2026-10-29 · douwebot on 6f09bf016: clean APPROVE · iter -
- Decision: douwebot merge-bar gate met on 6f09bf016: APPROVE 5706446055 'No blocking findings.', no douwebot comments on that head, run 40975735839 succeeded; CI green apart from the approval gates; 0 open threads
- Why: remaining for the L merge bar: one human approval with write access ('Gate: human approval'), David's call
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
- Session: fb395664-431b-455b-b5b9-e9fd16490c56
2026-10-30 · human-approval gate removed upstream by #11933 · iter -
- Decision: the PR no longer needs a second approver; the L merge bar is CI green and a clean douwebot approval on the current head; 'Gate: clean douwebot approval' stays
- Why: #11933 (merged as 79e157e8b7) removes the size-based 'Gate: human approval' from review_gates.py and pr-review-gates.yml and rewrites the pushing-commits-to-the-repo merge bar to match; recorded per dispatch 20261030T021501Z
- Source: https://github.com/pydantic/pydantic-ai/pull/11933
- Session: fb395664-431b-455b-b5b9-e9fd16490c56
- Supersedes: douwebot on 6f09bf016: clean APPROVE
2026-10-30 · pre-push gate exempt at 860f5004e0fca013c9530d0cc4f07f0e42fe41c3: no-conflict main merge · iter -
- Decision: no review dispatch; push the merge of upstream/main 79e157e8b (dispatch 20261030T021501Z)
- Why: exempt row 'Target-branch merge with no conflict resolution': remerge-diff empty; git diff 446cb61ad...6f09bf016 and git diff 79e157e8b...860f5004e have the same patch-id and identical bodies, only hunk offsets differ; no pyproject.toml or uv.lock change, so no make install; main's edits to _agent_graph.py and agent/init.py are #11807 (ModelResponse.model_id) and #11893 (banner), outside the teardown paths; chained from reviewed ebc8b89284dbb57609014de192ea6007a1b1a477 via exempt ab404fd0b and 6f09bf016
- Source: https://github.com/pydantic/pydantic-ai/pull/10479
- Session: fb395664-431b-455b-b5b9-e9fd16490c56
2026-10-30 · CI: elevenlabs keep-alive task-snapshot flake at 860f5004e -> rerun · iter -
- Decision: no code change; reran the failed jobs of run 40991693301
- Why: only failure: tests/realtime/test_elevenlabs.py::test_keep_alive_sends_an_empty_append_when_idle on 3.14 all-extras shard 2/2 (18550 passed); its tasks_before snapshot held two google-genai AsyncClient.aclose tasks that conftest's patch_google_genai_gc_crash scheduled on GC of an earlier test's client, and they finished during the test; this PR touches neither realtime, conftest, nor cancel_and_drain (the keep-alive's drain)
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/40991693301/job/123855405929
- Session: fb395664-431b-455b-b5b9-e9fd16490c56
2026-10-30 · douwebot on 860f5004e: clean APPROVE, merge bar met · iter -
- Decision: APPROVE 5707652802 'No blocking findings.' on 860f5004e, no douwebot comments on that head, run 40995732320 succeeded; every check passes (CI run 40991693301 attempt 2), 'Gate: clean douwebot approval' passes, no 'Gate: human approval' check exists on the head, 0 open threads, mergeStateStatus CLEAN
- Why: the label-event gate run 40995732423 evaluated before douwebot posted and failed on the douwebot gate; rerunning its failed job re-read the live state and passed; with #11933 the L merge bar is CI green plus a clean douwebot approval
- Source: https://github.com/pydantic/pydantic-ai/pull/10479#pullrequestreview-5707652802
- Session: fb395664-431b-455b-b5b9-e9fd16490c56
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.