Durable and Asynchronous Agent Work › Deadlines
Language AI HandbookAll chapters A claim can expire after admission. The worker tests the deadline in the same transaction as each state transition. The demo sets the persisted deadline to the past after claiming the task, then checks that no tool executes.
The SQLite runner only checks whether the persisted deadline has elapsed. It does not forecast a step’s duration or pass a timeout to the stub. The separate cost illustration asks whether a proposed step would fit in a hypothetical remaining budget. A production executor needs its own timeout or cancellation contract for work that has already started.
PythonIn [31]Expand
EXECUTED.clear()
tid4 = submit("draft_report", {"topic": "deadline"}, deadline_seconds=60)
task4 = claim_task("D")
# Inject deadline expiry after admission without waiting for the wall clock.
expired_at = time.time() - 1
with tx() as con:
con.execute(
"UPDATE tasks SET deadline = ? WHERE id = ?", (expired_at, tid4)
)
task4["deadline"] = expired_at
deadline_exceeded = time.time() > task4["deadline"]
res = run_task("D", task4)ConsoleOut [32]Expand
deadline already exceeded: True result: failed:deadline tools executed: [] final status: failed
The result reports a deadline failure and the stub call list stays empty. If the deadline instead passes during a stub, its cache row can already exist when the guarded completion rejects the result event. Later reconciliation can then see a cached but unrecorded call. This demo does not cancel work that had already started.
This separate example schedules hypothetical steps using their known toy costs. The 20-second budget and step costs 1, 8, 9, and 6 seconds leave 20, 19, 11, and 2 seconds before the respective steps. Only the first three fit.
PythonIn [33]Expand
budget_seconds = 20.0
step_costs = np.array([1.0, 8.0, 9.0, 6.0])
cumulative_cost = np.cumsum(step_costs)
remaining_before = budget_seconds - np.concatenate(
([0.0], cumulative_cost[:-1])
)
would_fit = remaining_before >= step_costsVisualizationOut [34]Expand

The hard deadline blocks further guarded transitions and causes the runner to record failure when a valid owner next reaches a deadline check. A soft deadline can leave time to return partial work. The service executing a call needs its own timeout or cancellation to bound work already underway.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!