Fix external MCP bridge timeouts with keepalive heartbeats#399
Open
Fix external MCP bridge timeouts with keepalive heartbeats#399
Conversation
…397) External MCP bridges impose their own timeout (~60s). Long-running agent tools (run_explorer, run_task, run_reviewer, run_swarm) produce no output during execution, causing the bridge to kill the connection with MCP error -32001 even though the agent is still working. Fix: run agent dispatch on a worker thread and send periodic notifications/message heartbeats every 15s from the calling thread. No timeouts are imposed — agents run as long as they need. - Add src/notify.zig: thread-safe MCP notification sender - Modify runChainStep to spawn heartbeat alongside agent dispatch - Wire notify.init() in main loop to pick up framing mode Closes #396, closes #397 Generated with AI Co-Authored-By: AI <ai@example.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.
Summary
run_explorer,run_task,run_reviewer,run_swarm) produce no stdout during execution, so the bridge kills the connection withMCP error -32001even though the agent is still working fine.notifications/messageheartbeats every 15s during agent execution. No timeouts imposed — agents run as long as they need.src/notify.zig(thread-safe MCP notification sender), modifiesrunChainStepto run dispatch on a worker thread with heartbeat loop alongside it.Closes #396, closes #397
Changes
src/notify.zig(new): Thread-safenotifications/messagesender with mutex-protected stdout writes. Supports both line-delimited and Content-Length framing.src/tools.zig:runChainStepnow spawns agent dispatch on a worker thread and loops ontimedWait(15s)sending heartbeat notifications until the agent completes.src/main.zig: Wirenotify.init(g_use_headers)in the message loop so the notifier picks up the framing mode.Test plan
zig build— cleanzig build test— all pass (including newnotify: init sets ready flagtest)run_explorervia external MCP bridge, verify heartbeat messages appear every 15s and no -32001 timeoutrun_taskwith a long-running preset, confirm it completes without bridge timeout