From 0f81b096252674f3324c19748af9a91ef679253b Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Sat, 3 Jan 2026 04:23:59 +0100 Subject: [PATCH] Fix edit tool diff not showing in TUI The async diff preview computation could race with tool execution, causing editDiffPreview to contain an error (file already modified) while the actual tool result had the correct diff in details.diff. Fix: prioritize result.details.diff over editDiffPreview when the tool has executed successfully. The preview is only used before tool execution completes. --- .../src/modes/interactive/components/tool-execution.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/coding-agent/src/modes/interactive/components/tool-execution.ts b/packages/coding-agent/src/modes/interactive/components/tool-execution.ts index 5e77e974..7df4baf4 100644 --- a/packages/coding-agent/src/modes/interactive/components/tool-execution.ts +++ b/packages/coding-agent/src/modes/interactive/components/tool-execution.ts @@ -479,8 +479,13 @@ export class ToolExecutionComponent extends Container { if (errorText) { text += `\n\n${theme.fg("error", errorText)}`; } + } else if (this.result?.details?.diff) { + // Tool executed successfully - use the diff from result + // This takes priority over editDiffPreview which may have a stale error + // due to race condition (async preview computed after file was modified) + text += `\n\n${renderDiff(this.result.details.diff, { filePath: rawPath })}`; } else if (this.editDiffPreview) { - // Use cached diff preview (works both before and after execution) + // Use cached diff preview (before tool executes) if ("error" in this.editDiffPreview) { text += `\n\n${theme.fg("error", this.editDiffPreview.error)}`; } else if (this.editDiffPreview.diff) {