Repository navigation
fix(platform): stop Claude Code re-sending a turn on a slow prefill - #3387
Conversation
The claude-code harness set no CLAUDE_STREAM_IDLE_TIMEOUT_MS, so the
pinned CLI (2.1.173) gave up on a stream after 300 s without a chunk and
sent the request again while the LLM gateway, which waits
SANDBOX_LLM_GATEWAY_STREAM_IDLE_TIMEOUT_SECONDS (default 600 s) for a
silent upstream, was still serving the first one. A local model whose
prefill outlasts 300 s got the same turn twice.
The gateway budget now has one reader, gatewayStreamIdleTimeoutSeconds()
in llm_gateway_admin.ts, used by the provider config push and by the
managed harness credential (gateway.streamIdleTimeoutMs). The exec builder
exposes it as the ${gateway.streamIdleTimeoutMs} placeholder, and the
claude-code env.managed sets CLAUDE_STREAM_IDLE_TIMEOUT_MS from it. The
CLI keeps its 300 s floor and derives its byte watchdog from the same
value; byo runs keep the CLI default.
SANDBOX_LLM_GATEWAY_STREAM_IDLE_TIMEOUT_SECONDS bounds how long the sandbox LLM gateway waits for the next byte of a silent upstream, and since the claude-code harness now follows the same budget, raising it for a slow local model no longer makes the agent send a turn twice. It was documented nowhere: .env.example and the environment reference in all three languages carry it now.
Codex runs its own per-stream idle watchdog and resends the request when it
fires, exactly like the Claude Code CLI in the commit before this one. Its
budget is a provider config key rather than an environment variable, so the
managed provider block now pins model_providers.tale.stream_idle_timeout_ms
to ${gateway.streamIdleTimeoutMs} — a TOML integer, unquoted, verified as a
ModelProviderInfo field of the pinned CLI (0.142.5). byo runs keep the CLI
default, since they talk to OpenAI rather than the gateway.
The fourteen managed golden execs are re-frozen deliberately, and the
exec-builder suite asserts the pin (and its absence under byo) rather than
leaving the bytes to speak for themselves. .env.example and the environment
reference in all three languages now name both CLIs.
|
Extended to Codex in f8e3ac1: the same watchdog, the same resend, but its knob is a provider config key rather than an env var — the managed block now pins |
|
Live data point from the VAT plus test environment (runtime b26ddbc, without this PR), 2026-09-16: during an invoice-reader turn on a two-invoice PDF, the sandbox LLM gateway logged |
What
The
claude-codeharness set noCLAUDE_STREAM_IDLE_TIMEOUT_MS, so the pinned CLI (2.1.173) gave up on a stream after its 300 s default without a chunk and re-sent the same request while the LLM gateway — which waitsSANDBOX_LLM_GATEWAY_STREAM_IDLE_TIMEOUT_SECONDS(default 600 s) for a silent upstream — was still serving the first one. Any model whose prefill outlasts 300 s runs the turn twice.How
gatewayStreamIdleTimeoutSeconds()inllm_gateway_admin.tsis now the single reader of the budget, used by both the provider config push and the managed harness credential (gateway.streamIdleTimeoutMs).${gateway.streamIdleTimeoutMs}placeholder;claude-code'senv.managedsetsCLAUDE_STREAM_IDLE_TIMEOUT_MSfrom it, so the two ends share one number.Why it matters here
Found while running VAT plus against the on-prem Mac Studios: a local model's prefill regularly passes 300 s, and the duplicate turn was visible as two identical desk runs.
Tests
exec-builder.test.tscovers the placeholder and the managed/BYO split; the gateway admin keeps its own suite. Docs:.env.exampleand the environment reference in all three locales.