Stop offering a safe output to the gh-aw shim's model once gh-aw rejects it as past its per-run limit
This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.
Why we make these changes
Related to #12735 (an incident, closed only after a recovery check, so this PR does not close it).
UI Security Review run 42258988219 posted no review. Inside the shim's time reserve, GLM called noop once (its per-run max is 1), then 89 more times. gh-aw rejected each call with E002, and _AnswerSafeOutputLimit answered "do not call this tool again", but noop stayed in every later request. The loop ran 286 s, until the run's 1,680 s cap. submit_pull_request_review was offered on every one of those requests and never called. No request was rate-limited.
Once gh-aw rejects a safe output as past its limit, _RecoverMCPToolErrors now leaves it out of every later request. It stays one of the run's tools, so a call from memory is still answered with the E002 result instead of spending the model's single tool retry, as _CIReviewToolPolicy already does for the tools it withholds.
New public surface
None. The shim is internal CI tooling.
User-visible behavior
.github/scripts/pydantic_ai_gh_aw_shim/cli.py :: run()
└─ pydantic_ai_slim/pydantic_ai/agent/__init__.py :: Agent.run() … unchanged machinery …
├─ .github/scripts/pydantic_ai_gh_aw_shim/cli.py :: _AnswerSafeOutputLimit.call_tool('mcp__safeoutputs__noop')
│ ├─ → 'error: … E002: noop limit reached …'
+ │ └─ adds 'mcp__safeoutputs__noop' to past_limit
- └─ next request → function_tools include 'mcp__safeoutputs__noop'
+ └─ .github/scripts/pydantic_ai_gh_aw_shim/cli.py :: _RecoverMCPToolErrors.before_model_request()
+ └─ → function_tools without 'mcp__safeoutputs__noop'
Verification
test_safe_output_past_its_limit_is_no_longer_offeredreproduces the incident: UI Security Review, inside the reserve,noopmax 1. It fails onmainwithnoopstill offered after itsE002.test_safe_output_past_its_limit_does_not_spend_the_tool_retrystill passes: the model calls the withheldnoopfrom memory and gets theE002result.- Logfire baseline (project
pydantic-ai, trace01a1b1d9d72d233d06d1eb6243c7d11e): over 30 days, 49 runs got a safe-outputE002, 39 called the same tool again, and no later call of anE002'd tool ever succeeded.
What changes for existing users
Nothing, except that a gh-aw run that already hit a safe output's per-run limit is no longer offered that tool in later requests.
PR decisions
2026-11-07 · lead A only: withhold E002-exhausted safe outputs from later requests · iter -
- Decision: Withhold a safe output from every later request once gh-aw returns E002 for it; skip lead B (extend CI Review policy to UI Security Review) and lead C (notice text)
- Why: A alone stops the reproduced loop and changes only runs that already hit E002; B changes runs that never hit E002, C changes model-facing text needing sign-off
- Source: https://github.com/pydantic/pydantic-ai/issues/12735
- Session: 9cb8889d-46d2-4898-8af6-06df34a7166a
2026-11-07 · skip lead B whole-run noop withholding for UI Security Review · iter -
- Decision: Do not extend _CIReviewToolPolicy's whole-run noop withholding to UI Security Review
- Why: shared/security-findings.md tells UI Security to end with noop 'One finding was reported privately.'; withholding after E002 keeps that first call
- Source: https://github.com/pydantic/pydantic-ai/blob/bbd5327dcf/.github/workflows/shared/security-findings.md
- Session: 9cb8889d-46d2-4898-8af6-06df34a7166a
2026-11-07 · reserve loop on unlimited safe outputs reported, not folded · iter -
- Decision: Report the reserve loop on missing_tool/missing_data/report_incomplete (no per-run max, never E002) to the manager instead of restricting UI Security's reserve tool set in this PR
- Why: Separate defect seen in Bug Hunter and pre-policy CI Review, not in the incident run; restricting the set needs an owner call on report_security_finding
- Source: https://github.com/pydantic/pydantic-ai/issues/12735
- Session: 9cb8889d-46d2-4898-8af6-06df34a7166a
2026-11-07 · pre-push review 1 of 3 at a601c1dc62081753ff4a0073bbb4a00340f3b048 · iter -
- Decision: Reserved: fresh light-tier (Haiku) reviewer via claude -p from a detached policy-base checkout at bbd5327dcf, read-only tools, no fan-out
- Why: tree 4398ddf2acac6f2126ca2fafa0176da0ec107d6a; scope full branch bbd5327dcfff884a6626bef3ebf32beac265b749..a601c1dc62081753ff4a0073bbb4a00340f3b048; first review
- Source: https://github.com/pydantic/pydantic-ai/tree/fix/gh-aw-shim-safe-output-loop
- Session: 9cb8889d-46d2-4898-8af6-06df34a7166a
2026-11-07 · pre-push review 1 outcome at a601c1dc62081753ff4a0073bbb4a00340f3b048 · iter -
- Decision: remediated: reworded _RecoverMCPToolErrors docstring without the workflow name; dismissed test-docstring narration finding (file convention: test_ci_review_withholds_noop_and_non_publishing_outputs_in_the_reserve and test_safe_output_past_its_limit_does_not_spend_the_tool_retry use incident docstrings)
- Why: No correctness findings; remediation 024b9df12bc215393bc8f31625e6c88a84e301e8 is docstring-only, an exempt delta chained from reviewed a601c1dc62
- Source: https://github.com/pydantic/pydantic-ai/tree/fix/gh-aw-shim-safe-output-loop
- Session: 9cb8889d-46d2-4898-8af6-06df34a7166a
2026-11-07 · leave UI Security reserve tool set unrestricted · iter -
- Decision: Do not restrict UI Security Review's reserve tool set; watch the next UI Security runs that reach the reserve after this PR ships
- Why: David chose option 3 of the reported reserve-loop risk
- Source: https://github.com/pydantic/pydantic-ai/pull/12768
- Session: 9cb8889d-46d2-4898-8af6-06df34a7166a
2026-11-07 · keep #12768 separate from the engine migration · iter -
- Decision: Keep driving #12768 on the shim; #10347 picks the fix up when it merges main (its RecoverMCPToolErrors rename conflicts)
- Why: David chose to keep it: shim runs need the fix before #10347 lands, and the engine agent reuses the same capability
- Source: https://github.com/pydantic/pydantic-ai/pull/10347
- Session: 9cb8889d-46d2-4898-8af6-06df34a7166a
2026-11-07 · main merge ca54224291 exempt from review · iter -
- Decision: Merged upstream/main without conflicts to restart CI, which never ran on 024b9df12b
- Why: Exempt: git diff main...024b9df12b equals git diff main...ca54224291; chains from reviewed a601c1dc62 via docstring-only 024b9df12b
- Source: https://github.com/pydantic/pydantic-ai/pull/12768
- Session: 9cb8889d-46d2-4898-8af6-06df34a7166a
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.