fix: route embedded tool calls through in-process dispatch (#40237)#394
Open
BingqingLyu wants to merge 2 commits intomainfrom
Open
fix: route embedded tool calls through in-process dispatch (#40237)#394BingqingLyu wants to merge 2 commits intomainfrom
BingqingLyu wants to merge 2 commits intomainfrom
Conversation
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
Fixes openclaw#40237 (also resolves openclaw#5703 and openclaw#6508 which were circular-duped shut).
When agent tools like
cron.run,cron.list,cron.addare called from within an active LLM session,callGatewayToolopens a new WebSocket connection to the same gateway. Because the gateway's Node.js event loop is busy processing the current LLM turn, the second WS connection sits in queue and times out after 10s.This PR routes embedded tool calls through the existing in-process dispatch path (
dispatchGatewayMethod) when running inside the gateway process, bypassing WS entirely. External CLI tool calls continue to use WS unchanged.Changes
src/gateway/local-dispatch.ts(new): lightweight registry that the gateway server populates at startup. ExposestryLocalGatewayDispatchwhich returns a promise when in-process dispatch is available, orundefinedwhen running outside the gateway (e.g. CLI).src/gateway/server-plugins.ts: registersdispatchGatewayMethodas the local dispatcher whensetFallbackGatewayContextis called during gateway startup.src/agents/tools/gateway.ts:callGatewayToolnow checkstryLocalGatewayDispatchfirst. If available (inside gateway), dispatches in-process with zero WS overhead. Otherwise falls through to the existing WS path.How it works
The
dispatchGatewayMethodfunction already exists and is battle-tested — it's used by plugin subagent runtime for sessions, agent dispatch, etc. This PR simply makes it available to agent tools via the registry pattern.Test plan
local-dispatch.ts(registry behavior, reset, error propagation)gateway.test.tsverifying:callGatewaymock called)undefinedparams correctly normalized to{}server-plugins.test.tstests pass (5/5)pnpm tsgo)pnpm check)