From 5a9c9f099f5ea4dbf321128042e012ccde8b867d Mon Sep 17 00:00:00 2001 From: Roo Code Date: Mon, 30 Jun 2025 07:49:37 +0000 Subject: [PATCH] Fix #5173: Save checkpoints before tool execution instead of after - Move checkpoint saving logic to occur before file-modifying tools are executed - This ensures checkpoints capture the workspace state before changes are made - Remove old logic that saved checkpoints after tool execution - Fixes issue where checkpoints were not being created before code modifications - Restores ability to compare versions and roll back changes as expected --- .../assistant-message/presentAssistantMessage.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/core/assistant-message/presentAssistantMessage.ts b/src/core/assistant-message/presentAssistantMessage.ts index 21c973ab507..0a320d8e8fa 100644 --- a/src/core/assistant-message/presentAssistantMessage.ts +++ b/src/core/assistant-message/presentAssistantMessage.ts @@ -406,6 +406,12 @@ export async function presentAssistantMessage(cline: Task) { } } + // Save checkpoint before any file-modifying tool is executed + const fileModifyingTools = ["write_to_file", "apply_diff", "insert_content", "search_and_replace"] + if (fileModifyingTools.includes(block.name)) { + await checkpointSave(cline) + } + switch (block.name) { case "write_to_file": await writeToFileTool(cline, block, askApproval, handleError, pushToolResult, removeClosingTag) @@ -521,13 +527,8 @@ export async function presentAssistantMessage(cline: Task) { break } - const recentlyModifiedFiles = cline.fileContextTracker.getAndClearCheckpointPossibleFile() - - if (recentlyModifiedFiles.length > 0) { - // TODO: We can track what file changes were made and only - // checkpoint those files, this will be save storage. - await checkpointSave(cline) - } + // Clear the checkpoint possible files since we now save checkpoints before tool execution + cline.fileContextTracker.getAndClearCheckpointPossibleFile() // Seeing out of bounds is fine, it means that the next too call is being // built up and ready to add to assistantMessageContent to present.