-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: preserve tool_use_id when editing tool_result messages #9835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
When editing a user_feedback message that corresponds to a tool_result in the API conversation history, we now edit the message in place rather than creating a new one. This preserves the tool_use_id, preventing the mismatch between tool_call and tool_result that was causing errors with native tool protocols. Changes: - Add resumeAfterMessageEdit() method to Task.ts that properly resets state and resumes the task loop without creating a new user message - Update webviewMessageHandler.ts to detect tool_result messages and edit them in place, preserving the tool_use_id while updating the content - Handle the case where timestamps don't match between clineMessages and apiConversationHistory by using position-based matching
All previously flagged issues have been resolved. No new issues found.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
- Remove empty debug if-block (leftover code) - Only update first tool_result block to avoid overwriting multiple blocks with identical content - Add cleanup of orphaned condenseParent/truncationParent references using cleanupAfterTruncation
mrubens
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all just feels really complicated... is it because of choices we made in how we implemented message editing?
Problem
When editing a user_feedback message that corresponds to a
tool_resultin the API conversation history, the previous behavior would delete the message and create a new one. This caused thetool_use_idto be lost, creating a mismatch between thetool_callandtool_resultthat caused errors with native tool protocols.Solution
This PR implements in-place editing for
tool_resultmessages:Changes to
Task.tsresumeAfterMessageEdit()method that properly resets task state and resumes the task loop without creating a new user messageChanges to
webviewMessageHandler.tstool_resultmessage in the API historyclineMessagesandapiConversationHistoryusing position-based matchingtool_resultcontent in place while preserving thetool_use_idresumeAfterMessageEdit()instead of creating a new messageTesting
Manual testing confirmed that editing a tool result message now:
tool_use_idImportant
Implements in-place editing for
tool_resultmessages to preservetool_use_id, ensuring task loop resumes correctly without creating new messages.tool_resultmessages inTask.tsandwebviewMessageHandler.tsto preservetool_use_id.resumeAfterMessageEdit()inTask.tsresets task state and resumes task loop without creating a new user message.tool_resultmessages inwebviewMessageHandler.ts.resumeAfterMessageEdit()to clear pending states, reset flags, update environment details, and ensure full context in next API call.tool_resultmessages and edits content in place while preservingtool_use_id.resumeAfterMessageEdit().tool_use_id, correct content update, and task loop resumption without errors.This description was created by
for fb3c2be. You can customize this summary. It will automatically update as commits are pushed.