Stop offering a safe output to the gh-aw shim's model once gh-aw rejects it as past its per-run limit

Merged
DS
1mo ago
+47-2

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_offered reproduces the incident: UI Security Review, inside the reserve, noop max 1. It fails on main with noop still offered after its E002.
  • test_safe_output_past_its_limit_does_not_spend_the_tool_retry still passes: the model calls the withheld noop from memory and gets the E002 result.
  • Logfire baseline (project pydantic-ai, trace 01a1b1d9d72d233d06d1eb6243c7d11e): over 30 days, 49 runs got a safe-output E002, 39 called the same tool again, and no later call of an E002'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 -

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 -

2026-11-07 · pre-push review 1 outcome at a601c1dc62081753ff4a0073bbb4a00340f3b048 · iter -

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 -

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.