defaultAiStallTimeout top-level constant
How long a completion may go without hearing anything at all before it is declared stalled.
A gap, not a total budget — see boundedAiRun for why that
distinction is the whole design. The bound is reset by any
AgentSdkCompletionEvent: a delta, or the liveness a transport reports
for system/init, a partial message, a tool call or an announced retry.
Measured, 2026-09-28. The largest silence between two consecutive
messages of a real completion was 8.3 s: a pause between
thinking_delta bursts of Opus 4.5 (Agent SDK 0.1.77, which the
standalone server pinned at the time) thinking on a 32k budget over a
170k-token context — the size the context assembler is allowed to
reach. The other long silence is prefill, before message_start: 1.8 s at
50k tokens, 7.8 s at 170k. Over the hosted path (Agent SDK 0.3.282, Opus
5.5, 223k tokens, 16k thinking budget) the largest gap was 2.2 s, because
that SDK also emits system/thinking_tokens progress events while the
model thinks. A 188-second completion arrived with no gap above 8.3 s —
which is why this is a gap and not a budget: a one-minute budget would have
killed it.
Re-measured, 2026-10-01, with Agent SDK 0.3.286 and Opus 5.5 over a
~170k-token context and a 32k thinking budget: largest gap 1.9 s over the
standalone server and 4.5 s over the hosted one (the prefill, before
message_start); prefill 4.7 s and 7.6 s. Well inside the margin below.
Why 120 s. Ten times the measured maximum is the floor (a test pins it): the bound has to sit far enough above ordinary silence that API load and larger thinking budgets do not read as death. The cost of the margin is only how long a genuinely dead far end takes to be reported.
Rechecking it. The figure has to be re-measured whenever the SDK, the
model or a transport changes, and one command does it for both transports:
AGENT_SDK_LIVE_MEASURE=1 AGENT_SDK_LIVE_HOSTED=1 dart test test/agent_sdk/stall_gap_measure_live_test.dart
(about 170k input tokens per transport; drop AGENT_SDK_LIVE_HOSTED to
measure the standalone server alone). It prints the largest gap and the
prefill, and fails when the largest gap exceeds a tenth of this bound.
All of that holds only because the CLI-server query sets
includePartialMessages — without it a thinking model is silent until its
answer is complete, and this constant would be a cap on model latency
wearing the name of a liveness bound.
Implementation
const defaultAiStallTimeout = Duration(seconds: 120);