Add `DenyUnanswered` harness capability to answer deferred calls
Merged
PY
17d ago+710+710+012345678901234567890123456789-58-58-01234567890123456789
- Closes #12289
Posted by Claude Code on Douwe's behalf.
Harness runs could pause forever on a held tool approval or an unanswered question. clai2 solved this locally, but harness users had no equivalent.
Changes:
- Add
pydantic_ai_harness.DenyUnanswered: it denies every held approval withToolDenied(message)and answers deferredask_user_questioncalls withquestion_message("No one is available to answer in this run; continue without the answer."), so the run finishes instead of pausing onDeferredToolRequests. Other deferred calls stay deferred. Exported lazily from the package root. SubAgentsandDynamicWorkflowforward the parent run'sDenyUnansweredto child runs by default, including durable children run inside the parent's workflow (DenyUnansweredis marked safe to add at runtime). This per-capability forwarding is interim: the general "inherit into child runs" hook in #13135 will replace it.- A delegation that a durable engine runs as a tool activity (a named sub-agent under
TemporalDurability) gets no forwarded instance, because the activity's run context does not carry the parent's capabilities.find_deny_unansweredreturnsNonethere, so such delegations behave exactly as without the capability. A remote sub-agent run by aSubAgentWorker(TaskControl(remote_agents=...)) likewise gets no forwarded instance, since the worker runs the child with its own capabilities. Both limitations are documented; closing them belongs to #13135. - clai2 session permissions use the harness capability (through a small subclass that keeps the
/permissions fullhint for callsPermissionsheld) and drop their local class (no re-export shim). - Docs:
README.mdnext to the code,docs/harness/deny-unanswered.md(its examples run intest_examples), capability tables, navigation, and the harness skill reference.
Headless clai2 behaviour change
clai2 sessions where nobody can be asked (no terminal picker or web approval cards bound, such as clai2 -p) now:
- deny calls
Permissionsheld with only the clai2 text ("No one could be asked to approve it here; /permissions full lets such calls run."), instead of "The user denied this command, so it did not run." followed by that text; - also deny held approvals
Permissionsdid not hold (for example MCP tools orrequires_approval=Truetools), with the harness default message instead of leaving them deferred, since/permissionsdoesn't change them; - answer
AskUserquestions with the "no one is available to answer" text instead of leaving them deferred.
Attended terminal and web sessions don't bind DenyUnanswered and behave as on main.
Decisions on the open review questions
- clai2 import path: no re-export shim for the old class.
- Child forwarding:
SubAgentsandDynamicWorkflowforward the parent'sDenyUnansweredby default, as interim until #13135. Noroot_capabilityfallback for durable activities. AskUserplumbing: unanswered questions get their own configurablequestion_messageinstead ofAskUser's "The user declined to answer" text.- Wording: approvals say no one was available to approve; questions say no one is available to answer.
Takeover
Taken over to finish: merged the latest main into the branch (no force pushes) and resolved the conflicts by keeping both sides (capability lists, imports, docs-example lists). Review follow-ups:
DenyUnanswerednow findsAskUserquestions byrequests.kind(...) == 'question'plusAskUser's ownership metadata instead of the tool name, so aPrefixTools-renamedAskUseris answered and an unrelated tool that happens to be calledask_user_questionand defers as an external call stays deferred. Both have regression tests.
No core pydantic_ai code changes.
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.
š¤ Generated with Claude Code