fix: race condition in new_task tool for native protocol #9655
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
The
new_tasktool for native protocol was broken - it was not returning atool_result, which broke the conversation history structure.Root Cause
In
NewTaskTool.ts, thependingNewTaskToolCallIdwas being set afterstartSubtask()returned. However,startSubtask()contains a 500ms delay during which the subtask could complete. If the subtask completed during this window,completeSubtask()would be called beforependingNewTaskToolCallIdwas set, causing it to fall through to the XML protocol path and add a text message instead of a propertool_resultblock.This race condition would break the API conversation structure because the native protocol API expects a
tool_resultblock for everytool_useblock.Fix
Move the
pendingNewTaskToolCallIdassignment to happen before callingstartSubtask(), ensuring the ID is set before the subtask starts. If the subtask creation fails, the pending ID is cleared.Changes
src/core/tools/NewTaskTool.ts: Reordered the logic to setpendingNewTaskToolCallIdbeforestartSubtask()and clear it if subtask creation fails.Testing
All 4325 tests pass.
Important
Fixes race condition in
NewTaskTool.tsby settingpendingNewTaskToolCallIdbeforestartSubtask()for native protocol.NewTaskTool.tsby settingpendingNewTaskToolCallIdbeforestartSubtask()for native protocol.pendingNewTaskToolCallIdif subtask creation fails.This description was created by
for 224935c. You can customize this summary. It will automatically update as commits are pushed.