feat: add connection-phase timeout for agent calls#1
Open
baochipham942-eng wants to merge 1 commit intoeLeanwang:mainfrom
Open
feat: add connection-phase timeout for agent calls#1baochipham942-eng wants to merge 1 commit intoeLeanwang:mainfrom
baochipham942-eng wants to merge 1 commit intoeLeanwang:mainfrom
Conversation
Add AbortController to Claude Runner (matching Codex Runner's pattern) and wrap the runQuery() call in MessageProcessor with a connection-phase timeout (default 30s, configurable via idleMonitor.connectionTimeout). This prevents permanent session blocking when the API connection hangs before the stream starts — a gap the existing StreamIdleMonitor cannot cover. Co-Authored-By: Claude Opus 4.6 (1M context) <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.
Problem
When an agent's
query()call hangs during the connection/handshake phase (before the event stream starts), the session's message queue is permanently blocked. The existingStreamIdleMonitoronly protects the event iteration phase — it relies onrecordEvent()calls that never fire if the stream never starts.This means:
Solution
Two-layer protection:
1. AbortController for Claude Runner (
claude-runner.ts)Added an
AbortControllerper query (matching the pattern already used in Codex Runner):runQuery(), passed toquery()viaabortControlleroptioninterrupt()callscontroller.abort()first (covers connection phase), then falls through to SDK's stream interruptcleanupStream()andcloseSession()2. Connection-phase timeout (
message-processor.ts)Wrapped
agent.runQuery()withPromise.raceagainst a configurable timeout:agent.interrupt()to abort, rejects with clear error messagerunQuery()succeeds (no false kills)config.idleMonitor.connectionTimeout(seconds)Changes
src/agents/claude-runner.tssrc/core/message/message-processor.tsPromise.raceconnection timeout aroundrunQuery()src/types.tsconnectionTimeoutfield inidleMonitorconfigWhat's NOT changed