Let `HandleDeferredToolCalls` token handlers and `AskUser` wait durably in an Absurd task
- Part of #12975
Inside an Absurd task, a HandleDeferredToolCalls handler that takes a resume token, and AskUser, now wait for the answer durably instead of being refused with a UserError. While it waits, the task is suspended on an Absurd event, so no worker holds it.
AbsurdDurability.wrap_runinstalls anExternalEventWaiterfor runs inside a task. One step draws the wait's event key (a UUID). Another step callsaskwith the token<queue name>:<event key>, so a woken or retried task doesn't ask again. The task then callsAsyncTaskContext.await_eventonpydantic_ai__external_event:<event key>.resolve_external_event(client, token, payload)andfail_external_event(client, token, reason)frompydantic_ai_harness.absurdemit that event with anAsyncAbsurdclient. The payload is wrapped in an envelope that a strict union validates, so an event emitted any other way ends the wait with anExternalEventErrorand is never treated as an answer. Absurd keeps the first event emitted under a name, so the first resolution wins.- A
timeoutbecomes Absurd's event timeout, rounded up to whole seconds. When it expires, the wait raisesExternalEventError, andHandleDeferredToolCallsdenies the pending calls. - Docs:
- The Absurd page and README get a "Waiting for approvals and answers" section.
- The lists of engines that support durable waits now include Absurd.
THREAT_MODEL.mdnotes that anyone who can write to the Absurd database can resolve a wait.
Tests (tests/harness/absurd/test_external_events.py) run against Absurd's real schema on PostgreSQL. They cover:
- approve-and-resume without asking again;
- a failure that denies;
- first resolution wins;
- timeout;
- an answer in place that doesn't suspend;
- an event emitted without the envelope;
- a sub-second timeout rounded up to whole seconds;
- a token resolved through a client on another queue;
- a payload that isn't JSON, rejected without waking the task;
AskUserwith a token answerer: the answer arrives through the token and the woken task doesn't ask again;- bad tokens.
Threat model changes:
- Narrows: on Absurd, whoever can write to the Absurd database can resolve a wait, through
resolve_external_eventor by emitting the event directly. This adds Absurd to the existing list of who can resolve a token. - Adds: none.
The DBOS waiter in #14522 edits the same engine lists in the docs. Whichever PR merges second takes the other's entries.
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
Summary by cubic
HandleDeferredToolCalls handlers that take a resume token, and AskUser, now wait durably for an answer inside an Absurd task instead of being refused with a UserError. While waiting, the task suspends on an Absurd event, so no worker holds it.
AbsurdDurabilityinstalls anExternalEventWaiter: a step draws the wait's event key, another callsaskwith a<queue>:<event key>token, and the task awaits the event, so a woken or retried task doesn't ask again. Each wait's event step is named after its key, so a replay that skips a timed-out wait doesn't hand a later wait the earlier one's event.pydantic_ai_harness.absurd.resolve_external_eventandfail_external_eventemit the event with anAsyncAbsurdclient; payloads are wrapped in an envelope, so an event emitted any other way ends the wait withExternalEventError, and the first resolution wins. A client on another queue resolves the token too (the event goes to the queue the token names), and a non-JSON payload is rejected with aUserErrorwithout waking the task.- A
timeoutbecomes Absurd's event timeout, rounded up to whole seconds, with a test pinning that a sub-second timeout waits at least the full time; on expiry the wait raisesExternalEventError, atimed_outstep records it so a retried task doesn't wait again or take a late resolution, and pending calls are denied. - Tests cover approve-and-resume, failures that deny, first resolution wins, timeouts and replays of timed-out waits, cross-queue resolution, non-envelope and non-JSON payloads, and
AskUserwaiting on the same envelope. - Docs list Absurd among the durable-wait engines, including
Permissions'approval_ask, which now works on Temporal, AWS Lambda and Absurd alike, and the Absurd page gains a "Waiting for approvals and answers" section. THREAT_MODEL.mdnotes that anyone who can write to the Absurd database can resolve a wait.
The DBOS waiter in #14522 edits the same engine lists in the docs; whichever PR merges second takes the other's entries.