Skip to content

feat(env): MYAGENT_IDLE_TIMEOUT_MS to override stream watchdog#10

Merged
wusijian007 merged 1 commit into
mainfrom
feat/idle-timeout-env
May 15, 2026
Merged

feat(env): MYAGENT_IDLE_TIMEOUT_MS to override stream watchdog#10
wusijian007 merged 1 commit into
mainfrom
feat/idle-timeout-env

Conversation

@wusijian007

Copy link
Copy Markdown
Owner

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
createAnthropicModelClientFromEnvAnthropicModelClient.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: 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.

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>
@wusijian007 wusijian007 merged commit 0185834 into main May 15, 2026
3 checks passed
@wusijian007 wusijian007 deleted the feat/idle-timeout-env branch May 15, 2026 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant