fix(heartbeat): isolate heartbeat API client from main streaming session#247
Merged
fix(heartbeat): isolate heartbeat API client from main streaming session#247
Conversation
HeartbeatRunner shared the same AgentRunner (and its httpx connection pool of 5) as the main chat streaming session. When heartbeat cognitive triage fired during active tool execution, both competed for connections — causing pool timeout. Changes: - Add AgentRunner.fork(api_client) to create sibling runners with isolated connection pools but shared cognitive layer and dispatcher - HeartbeatRunner accepts optional api_client parameter and creates a dedicated forked runner for cognitive triage - main.py creates a second AnthropicClient for heartbeat - Proper cleanup: try/finally in stop() ensures api_client is closed even if dedicated runner cleanup fails - Warning log when api_client provided but start() not called Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
Summary
AnthropicClient(httpx pool of 5 connections) as the main chat streaming session. When heartbeat cognitive triage fired during active tool execution, both competed for connections — causing pool timeout.AnthropicClientwith an isolated connection pool via a newAgentRunner.fork()method.Changes
nous/api/runner.pyfork(api_client)method — creates sibling runner with shared cognitive/dispatcher but isolated API clientnous/heartbeat/runner.pyapi_clientparam, create dedicated runner viafork(), route triage through it, cleanup with try/finallynous/main.pyAnthropicClientfor heartbeattests/test_runner_fork.pytests/test_heartbeat_isolation.pyKey Design Decisions
fork()sets_api_shared=Trueso the forked runner doesn't close the client —HeartbeatRunner.stop()owns that lifecycletry/finallyblocks instop()ensureapi_clientis closed even if dedicated runner cleanup fails_get_triage_runner()falls back to shared runner with warning log ifstart()wasn't calledapi_clientparam work unchangedTest plan
AgentRunner.fork()creates isolated runner, shares cognitive/dispatcher, doesn't close client on close()🤖 Generated with Claude Code