From 59a8b38203daf84fe8db93ecc9cdfff0fb77b2a0 Mon Sep 17 00:00:00 2001 From: Hannes Rudolph Date: Mon, 15 Dec 2025 13:11:29 -0700 Subject: [PATCH] fix: timestamp coordination in flushPendingToolResultsToHistory and add smartContextTracking to test mock - Use pendingUserMessageTs in flushPendingToolResultsToHistory() instead of Date.now() to ensure the message timestamp matches what was set during tool execution via setCurrentMessageContext(). This fixes the issue where containingMessageTs could point to a non-existent message and cause redundant re-reads. - Add smartContextTracking property to the experiments mock object in ExtensionStateContext.spec.tsx to fix TypeScript error. --- src/core/task/Task.ts | 11 ++++++++++- .../context/__tests__/ExtensionStateContext.spec.tsx | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/task/Task.ts b/src/core/task/Task.ts index e7104d1832..bf94f40a0d 100644 --- a/src/core/task/Task.ts +++ b/src/core/task/Task.ts @@ -866,9 +866,18 @@ export class Task extends EventEmitter implements TaskLike { // Validate and fix tool_result IDs against the previous assistant message const validatedMessage = validateAndFixToolResultIds(userMessage, this.apiConversationHistory) - const userMessageWithTs = { ...validatedMessage, ts: Date.now() } + // Use pendingUserMessageTs if set (for file context tracking coordination) + // This ensures the message timestamp matches what was set during tool execution + const messageTs = this.pendingUserMessageTs ?? Date.now() + const userMessageWithTs = { ...validatedMessage, ts: messageTs } this.apiConversationHistory.push(userMessageWithTs as ApiMessage) + // Clear the pending timestamp and message context after use + if (this.pendingUserMessageTs) { + this.pendingUserMessageTs = null + this.fileContextTracker.clearCurrentMessageContext() + } + await this.saveApiConversationHistory() // Clear the pending content since it's now saved diff --git a/webview-ui/src/context/__tests__/ExtensionStateContext.spec.tsx b/webview-ui/src/context/__tests__/ExtensionStateContext.spec.tsx index 15c87d03c4..c3dfe3796e 100644 --- a/webview-ui/src/context/__tests__/ExtensionStateContext.spec.tsx +++ b/webview-ui/src/context/__tests__/ExtensionStateContext.spec.tsx @@ -240,6 +240,7 @@ describe("mergeExtensionState", () => { runSlashCommand: false, nativeToolCalling: false, multipleNativeToolCalls: false, + smartContextTracking: false, } as Record, checkpointTimeout: DEFAULT_CHECKPOINT_TIMEOUT_SECONDS + 5, } @@ -263,6 +264,7 @@ describe("mergeExtensionState", () => { runSlashCommand: false, nativeToolCalling: false, multipleNativeToolCalls: false, + smartContextTracking: false, }) }) })