Resume timed-out CI Review delegates and enforce the parent's time reserve

Merged
DS
1mo ago
+369-24

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

Why we make these changes

In the two CI Review runs on current source since #10501 (39358200683, 39360027162), delegates that hit the 15-minute Task timeout had gathered most of their evidence, but task discarded their history and the parent re-reviewed their files: 11 and 6.4 minutes on the critical path. In the first run the parent kept investigating through the time-budget notice, and nothing was posted. In the second, the parent approved after reading the full source of only 2 of the 9 modified files it took over.

What changes

  1. Resume a timed-out delegate (cli.py task). capture_run_messages keeps the delegate's history. On timeout the partial response is dropped, repair_messages closes out tool calls the cut left unanswered, and one streamed request without tools asks for the report and for anything unfinished. The parent receives it prefixed note: the sub-agent timed out …. The resume runs only within the delegate's unspent request grant and before the parent's time reserve. Otherwise, or if the request fails, task returns the same timeout error as before. Its usage is charged to the parent.
  2. Enforce the parent's time reserve (cli.py run). Once the time_budget_notice condition holds, a PrepareTools capability offers only the mcp__safeoutputs__* tools. The request in flight is not cancelled, and the notice stays.
  3. Review prompt (shared/prompts/pydantic-ai-pr-review.md). A resumed report counts like any other delegate report. A file the parent reviews itself counts as reviewed only after its diff and full source (a new file's diff is enough); otherwise it is unreviewed, which rules out APPROVE. Once only safe-output tools remain, unverified findings go into the review body, marked unverified.
Design decisions
  • Unanswered tool calls get pydantic-ai's synthesized interrupted returns instead of being deleted: deleting a call can leave a thinking-only response whose signature covered it (pydantic_ai_slim/pydantic_ai/messages.py _repair_dangling_tool_calls).
  • The resume spends from the delegate's own grant, which stays in _subagent_requests_in_flight until task returns, so shared request accounting is unchanged.
  • The resume is streamed like the delegate. A non-streamed request sends nothing until it finishes, so the client's 120 s read timeout would cut a long report.
  • The resume runs under the shim's _wall_clock_cap with _MarkTimedOutSpans, like the delegate (#10687), as the delegate-resume agent. The execute_tool Task span keeps its timeout mark after a resume, because the delegate's cap did fire.
  • error: results keep "Do not dispatch it again"; re-dispatching never fits the time left.
  • No model, limit, timeout, retry or concurrency changes.
  • The shared prompt is fetched at run time (run 39360027162 logged using the committed default prompt), so no lock recompile.
  • #10347 also edits task's timeout path; whichever lands second rebases.
Verification
  • .github/scripts/test_pydantic_ai_runner.py, in-process with scripted models and an injected cut, no real waits: resume from history with the partial response dropped; unanswered calls closed out; no resume without time, request headroom, or a completed response; resume failure returns the timeout error; tool filter across the reserve boundary, with the in-flight call still run.
  • test_subagent_is_resumed_after_its_cap_cuts_it_off expires the real cap on a clock-skipping loop and pins the Task result and every span's outcome.
  • GLM via Z.ai (glm-5.3-flash) and Anthropic (claude-sonnet-5-5) both accept the streamed, tool-less resume request on a history with tool_use blocks; the GLM run went end to end through cli.task (result).
  • test_run_timeout_marks_the_spans_it_cuts_off (from #10687) now uses a 6-minute run budget: its 1-minute budget sat wholly inside the 5-minute reserve, where its hang tool is no longer offered.
  • Comparing matched runs after deployment needs the shim telemetry fixes first.

Related: #10259, #10309, #10570. This PR closes none of them.

New public surface

None.

User-visible behavior

Only the gh-aw workflows that run on this shim change. Each is offered only its safe-output tools during its final five minutes, and those that use Task resume timed-out delegates.

What changes for existing users

Nothing. Only .github/ changes.

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver (not applicable).
  • PR title is fit for the release changelog.