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.
This commit is contained in:
Hannes Rudolph 2025-12-15 13:11:29 -07:00
parent 9f29251b8a
commit 59a8b38203
2 changed files with 12 additions and 1 deletions

View file

@ -866,9 +866,18 @@ export class Task extends EventEmitter<TaskEvents> 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

View file

@ -240,6 +240,7 @@ describe("mergeExtensionState", () => {
runSlashCommand: false,
nativeToolCalling: false,
multipleNativeToolCalls: false,
smartContextTracking: false,
} as Record<ExperimentId, boolean>,
checkpointTimeout: DEFAULT_CHECKPOINT_TIMEOUT_SECONDS + 5,
}
@ -263,6 +264,7 @@ describe("mergeExtensionState", () => {
runSlashCommand: false,
nativeToolCalling: false,
multipleNativeToolCalls: false,
smartContextTracking: false,
})
})
})