feat(env): MYAGENT_IDLE_TIMEOUT_MS to override stream watchdog#10
Merged
Conversation
The AnthropicModelClient streams responses with a 90-second idle watchdog: if the model emits no events for that long the stream is aborted. That's the right default on Anthropic's official endpoint, but some proxies route requests through extended-thinking models (e.g. claude-sonnet-4-6 on claude.proai.love) where thinking phases can pause for minutes between visible deltas. The watchdog fires mid-thinking and the agent sees "Connection error". Add an optional `MYAGENT_IDLE_TIMEOUT_MS` env var that bumps the watchdog ceiling per session, threaded through `createAnthropicModelClientFromEnv` → `AnthropicModelClient.options .idleTimeoutMs`. Existing default and behavior unchanged. # Example for slow proxies routing through extended-thinking sonnet: $env:MYAGENT_IDLE_TIMEOUT_MS = "300000" # 5 minutes npm.cmd run myagent -- agent "<long task>" Tests added in anthropic.test.ts: `parseIdleTimeoutMs` happy path + negatives (empty / non-numeric / zero / negative), plus a smoke that `createAnthropicModelClientFromEnv` accepts valid + malformed values without throwing (malformed silently falls back to the default). Threaded through `loadEnvironment` allow-list in cli/src/index.ts so the value is picked up from `.env` too. Help text updated. CLAUDE.md note added. Local: 171 tests, 3/3 green. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The AnthropicModelClient streams responses with a 90-second idle watchdog: if the model emits no events for that long the stream is aborted. That's the right default on Anthropic's official endpoint, but some proxies route requests through extended-thinking models (e.g. claude-sonnet-4-6 on claude.proai.love) where thinking phases can pause for minutes between visible deltas. The watchdog fires mid-thinking and the agent sees "Connection error".
Add an optional
MYAGENT_IDLE_TIMEOUT_MSenv var that bumps the watchdog ceiling per session, threaded throughcreateAnthropicModelClientFromEnv→AnthropicModelClient.options .idleTimeoutMs. Existing default and behavior unchanged.Example for slow proxies routing through extended-thinking sonnet:
$env:MYAGENT_IDLE_TIMEOUT_MS = "300000" # 5 minutes
npm.cmd run myagent -- agent ""
Tests added in anthropic.test.ts:
parseIdleTimeoutMshappy path + negatives (empty / non-numeric / zero / negative), plus a smoke thatcreateAnthropicModelClientFromEnvaccepts valid + malformed values without throwing (malformed silently falls back to the default).Threaded through
loadEnvironmentallow-list in cli/src/index.ts so the value is picked up from.envtoo. Help text updated. CLAUDE.md note added.Local: 171 tests, 3/3 green.