Deadlines and Outboxes for Agent Work
Lesson 1 of 4
One Budget for the Whole Run
Estimated time: 10 minutes
One budget for the whole run
A run that calls three services and gives each call its own thirty second timeout has, in practice, given the caller ninety seconds of waiting. Every hop is comfortable on its own and the sum is not.
The fix is to set one budget when the run starts and pass the remainder down the chain. Each hop measures the time it spent and hands the next hop what is left.
import time
def start_budget(total_ms):
return {"deadline": time.monotonic() + total_ms / 1000.0}
def remaining(budget):
return max(0.0, budget["deadline"] - time.monotonic())
An absolute deadline travels better than a bare duration, because a duration has to be restarted by every participant and each restart forgives time already spent.
Reserve a slice for each hop. A hop that spends the whole remainder leaves nothing for writing its own result.