Skip to content

Commit 0afd696

Browse files
committed
fix(ai-client): reset live yield on ignored terminals and clear()
Clear hidden-burst accounting when cleared-stream RUN_FINISHED/RUN_ERROR is ignored, and when clear() drops remote active runs without canceling a local stream, so mid-burst state cannot leak into the next live run.
1 parent 4090eaf commit 0afd696

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

packages/ai-client/src/chat-client.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,11 @@ export class ChatClient<
15611561
}
15621562
this.retireIgnoredClearedTerminalChunk(chunk)
15631563
this.resolveJoinedRun(chunk)
1564+
// Cleared-stream terminals skip the live yield/reset path below.
1565+
// Still clear hidden-burst accounting so a mid-burst counter cannot
1566+
// leak into the next real live stream (e.g. clear() while only
1567+
// observing a remote run, which may not call cancelInFlightStream).
1568+
this.liveChunkYield.reset()
15641569
}
15651570
return
15661571
}
@@ -2291,6 +2296,9 @@ export class ChatClient<
22912296
this.cancelInFlightStream({ setReadyStatus: true })
22922297
this.resetSessionGenerating({ preserveClearedStreamTracking: true })
22932298
} else if (this.activeRunIds.size > 0) {
2299+
// Remote/observe-only: no local abortController, so cancelInFlightStream
2300+
// did not run — still drop hidden-burst accounting for the next stream.
2301+
this.liveChunkYield.reset()
22942302
this.resetSessionGenerating({ preserveClearedStreamTracking: true })
22952303
}
22962304
// Suppress persisting the empty snapshot that clearMessages emits, then

0 commit comments

Comments
 (0)