Practical technical guides

Agent Activity Timeouts Must Include Queue Waits and Retries

Separate queue wait, attempt duration and total retry time with a deterministic timeline and explicit failure outcomes.

By Sandeep Belgavi · Published 2026-12-04

Flow from Queue wait, to Attempt + backoff, to Total deadline.
Original conceptual diagram by Sandeep Belgavi.

The queue is part of the operation

An agent asks a worker to inspect a synthetic build artifact. The operation normally takes six seconds. A developer gives the activity a ten-second execution timeout and expects a prompt failure when the system is unhealthy. During a worker outage, however, the activity waits forty seconds before it starts. Its six-second execution still succeeds. The timeout did exactly what it promised; the promise covered execution, while the caller cared about elapsed time from scheduling.

Adding a model to this architecture makes that distinction more consequential. A model may choose an expensive inspection, request several attempts, or consume most of the request budget before scheduling the activity. The application must decide how long the remaining work is useful. An instruction asking the agent to finish quickly cannot define that boundary. The queue, retry policy and worker need explicit contracts that remain deterministic when the model changes its plan.

This guide separates two scheduling clocks from the familiar per-attempt execution clock. The existing heartbeat guide covers detecting a worker that stops reporting progress. Here the central question is different: how long may work wait, and how much total elapsed time may all attempts consume? The companion simulator uses a virtual clock. Its numbers describe constructed timelines, not measurements of a workflow service.

Four clocks with different starting points

Temporal documents Schedule-To-Start as the wait between scheduling an activity task and a worker picking it up. It applies to each attempt. Start-To-Close covers one attempt after pickup. Schedule-To-Close covers the entire logical activity, including queue waits, executions and retries. A heartbeat timeout concerns gaps in worker progress reports. These are different intervals, even if an application initially assigns the same numeric duration to several of them.

Schedule-To-Start also has a special retry consequence: Temporal treats that timeout as non-retryable because putting the task back into the same queue does not repair unavailable workers. Its documentation recommends observing queue latency in most cases and using this timeout when there is a concrete response, such as routing to an alternative queue. Do not generalize the retry behavior of execution failures to queue-wait failures.

Draw the timeline before choosing values. In a synthetic run, the first queue wait is four seconds, attempt one runs for eight seconds and fails, backoff consumes three seconds, and the next queue wait takes four seconds. Attempt two starts at nineteen seconds. If it needs eight more seconds, a twenty-five-second total budget expires before completion even though both attempts individually fit a ten-second execution limit.

Keep deadline authority outside the agent

The model proposes which inspection to perform. A deterministic adapter validates the operation name, payload size, capability and remaining time. The workflow records the selected operation and schedules the activity. A worker executes the inspection and reports a typed result. The agent may interpret that result, but cannot extend the activity deadline by generating a different explanation.

The adapter should distinguish an exhausted request budget from an invalid operation. The former may produce a partial response; the latter is a contract violation. Preserve that distinction in the trace and client response. A generic failure string invites the agent to retry both conditions. An enum such as budget_exhausted, worker_unavailable or inspection_failed gives the deterministic orchestrator a concrete branch to follow.

Keep authoritative elapsed time in the execution engine. Do not compare a worker wall clock with a timestamp invented by the model. In the offline example, integers represent seconds and the simulator advances them explicitly. That makes boundary cases reproducible. A deployed workflow must use the engine's supported timing facilities and account for its scheduling semantics rather than copying the simulator's arithmetic into production orchestration.

A worked retry budget

Consider a twenty-five-second Schedule-To-Close limit, ten seconds per attempt, four seconds of queue wait before each attempt, and three seconds of fixed backoff. Attempt one is configured to fail after eight seconds. The trace is: scheduled at zero, started at four, failed at twelve, retry scheduled at fifteen, started at nineteen, total deadline at twenty-five. There is no successful result to accept at twenty-seven.

Changing only the total limit to thirty seconds permits the second eight-second attempt to finish at twenty-seven. Changing only the queue limit to three seconds instead causes a queue timeout at three, before a worker starts. Increasing maximum attempts cannot fix that queue timeout. Reducing execution duration to two seconds also cannot fix it because the worker has not yet picked up the task.

These comparisons explain why timeout tuning should begin with a hypothesis. If queue latency consumes the budget, faster model inference inside a worker is not the first remedy. If attempts run and fail repeatedly, increasing worker count may only create more repeated side effects. Use the trace to identify the interval that dominates, then change the capacity, deadline or failure policy associated with that interval.

# Author: Sandeep Belgavi. Arithmetic illustration, not a Temporal SDK call.
queue_wait = 4
attempt_time = 8
backoff = 3
second_finish = queue_wait + attempt_time + backoff + queue_wait + attempt_time
assert second_finish == 27
assert second_finish > 25
assert second_finish < 30

A timeout does not undo a side effect

Suppose the inspection writes a derived artifact before its acknowledgement is lost. The engine can time out the activity while the worker or remote service continues running. A retry may repeat the write. Put an idempotency key around the external effect and store its outcome somewhere the retry can query. The total deadline controls how long the workflow accepts progress; it does not prove that all remote computation has stopped.

Cancellation has a similar boundary. A cooperative worker can notice cancellation and stop, but a remote operation may have already committed. Avoid reporting a definitive cancellation merely because the waiting client has closed its connection. Record whether the action was never started, cancellation was requested, or completion is unknown. That distinction determines whether reconciliation is necessary.

An agent can help summarize an uncertain outcome, but it should not resolve uncertainty by guessing. A deterministic recovery step queries the durable operation record. If that record is unavailable, return an explicit unresolved state. Preserve the correlation key so a later repair can connect the workflow attempt, remote request and eventual result without launching a second unrelated operation.

Migrate an existing synchronous endpoint

Start by measuring queue wait separately from execution and retry delay. A single endpoint-duration histogram cannot identify which budget is failing. Add timestamps at admission, scheduling, worker pickup and terminal outcome. Record the configured limits with the run so a later policy change does not make an old trace ambiguous. Use bounded labels for timeout types rather than one metric label per task identifier.

Next, define the maximum useful total duration from the caller's requirements. Reserve time for serialization and the final response. Choose the per-attempt bound from the actual operation contract, then decide which failures are retryable. Introduce a queue-wait timeout only with a documented action for it. Validate migration in shadow mode using synthetic workloads before placing a model in charge of proposing operations.

Finally, version the policy. Existing durable executions may resume under recorded decisions while newly admitted runs use new limits. Test the engine's supported upgrade path before changing workflow code or retry configuration. A deadline policy is part of the service contract: clients need to know whether they receive a partial result, a terminal failure or an asynchronous operation reference when time runs out.

Verification and when an agent is unnecessary

The companion lab should reproduce three outcomes: a queue timeout before any attempt starts, a total timeout during a retry, and completion after increasing the total budget. Test equality at a boundary deliberately; the teaching model gives deadline expiry priority when events share a timestamp. That tie rule is documented for the simulator and should not be mistaken for a measured ordering guarantee from a real engine.

Also test impossible configuration, nonnumeric input and reset behavior. Export should include inputs, the outcome and every trace event so a result can be reproduced. These tests validate the teaching mechanism. Production readiness additionally requires an actual worker crash, lost acknowledgement, service cancellation and durable replay test in the chosen engine.

If the operation and recovery sequence are known in advance, use a deterministic workflow directly. An agent is useful when selecting an inspection requires interpreting unstructured context. It is unnecessary for enforcing a clock, counting attempts or deciding whether a recorded deadline has elapsed. Keeping those responsibilities ordinary makes failures explainable and gives the agent a smaller, better-defined job.

Interactive experiment

Activity timeout timeline: queue waits, retries and total deadlines. Adjustable synthetic fixtures, decision traces, reset and JSON export.

Primary references and authorship

Sources read December 4, 2026. Original explanations and synthetic examples by Sandeep Belgavi. Companion code: Sandeep-BA/agent-decision-lab/examples/python/agent_activity_timeouts. Views are my own and do not represent any employer, past or present.