Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai-client): preserve client tool results on failed follow-up reload #2275

Openaloneangel45(GitHub profile, opens in a new tab)wants to merge 6 commits intomain fromrefs/pull/2275/headopened View on GitHub

Showing 3 changed files with 103 additions and 4 deletions (loading 1).

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/reload-preserve-tool-result.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/ai-client': patch
+---
+​
+Preserve completed client tool results in `ChatClient.reload()` when retrying a failed `addToolResult` follow-up run instead of truncating back to the last user message.
98 additions and 4 deletionspackages/ai-client/src/chat-client.tsModified
View file
@@ -938,6 +938,8 @@
// Tracks whether a queued checkForContinuation was skipped because
// continuationPending was true (chained approval scenario)
private continuationSkipped = false
+ private failedToolContinuationAnchorId: string | null = null
+ private inFlightToolContinuationAnchorId: string | null = null
private draining = false
private readonly activeRunIds = new Set<string>()
/** Latched by `dispose()`; stops any late async callback starting new work. */
@@ -2560,6 +2562,10 @@
this.setConnectionStatus('error')
this.resetSessionGenerating()
this.setIsSubscribed(false)
+ if (this.inFlightToolContinuationAnchorId !== null) {
+ this.failedToolContinuationAnchorId =
+ this.inFlightToolContinuationAnchorId
+ }
this.reportStreamError(err)
// Resolve pending processing so streamResponse doesn't hang