fix(runtime): decouple tool dispatch from permission to prevent duplicate tool_result#96
Merged
yishuiliunian merged 1 commit intomainfrom Apr 11, 2026
Merged
Conversation
…cate tool_result (#96) ReadOnly permission was conflated with "safe to early-start" execution strategy. Runner-direct tools (AskUser, EnterPlanMode, ExitPlanMode) were both early-started by feed_tool AND intercepted by the runner, producing duplicate ToolResult blocks with the same tool_use_id. This caused Anthropic API 400 errors. Introduce ToolDispatch enum (Pipeline | RunnerDirect) on the Tool trait to separate execution strategy from permission level. feed_tool now checks dispatch() before early-starting, and Phase 3 adds a defensive filter for intercepted indices.
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
ToolDispatchenum (Pipeline|RunnerDirect) on theTooltrait to separate execution strategy from permission levelfeed_toolAND intercepted by the runner, producing duplicateToolResultblocks with the sametool_use_id— causing Anthropic API 400 errorsfeed_toolnow checksdispatch()before early-starting, with a defensive filter in Phase 3Changes
crates/loopal-tool-api/src/tool.rs— newToolDispatchenum +dispatch()trait method (default:Pipeline)crates/tools/agent/ask-user/src/lib.rs,plan-mode/src/lib.rs— overridedispatch()→RunnerDirectcrates/loopal-runtime/src/agent_loop/streaming_tool_exec.rs—feed_toolskipsRunnerDirecttoolscrates/loopal-runtime/src/agent_loop/tools.rs— Phase 3 defensive filter onintercepted_indicesdispatch_test.rs(unit),turn_test.rs(E2E),registry_test.rs(contract)Test plan
bazel test //...— 51 tests passbazel build //... --config=clippy— zero warnings