fix: optimistic cancellation [LET-6273] (#166)

This commit is contained in:
Christina Tong
2025-12-08 23:46:18 -08:00
committed by GitHub
parent 38b532e8ba
commit e8bd2e6537
2 changed files with 85 additions and 19 deletions

View File

@@ -53,7 +53,6 @@ export async function drainStream(
// Check if stream was aborted
if (abortSignal?.aborted) {
stopReason = "cancelled";
// Mark incomplete tool calls as cancelled to prevent stuck blinking UI
markIncompleteToolsAsCancelled(buffers);
queueMicrotask(refresh);
break;
@@ -130,6 +129,14 @@ export async function drainStream(
onChunk(buffers, chunk);
queueMicrotask(refresh);
// Check abort signal again after processing chunk (for eager cancellation)
if (abortSignal?.aborted) {
stopReason = "cancelled";
markIncompleteToolsAsCancelled(buffers);
queueMicrotask(refresh);
break;
}
if (chunk.message_type === "stop_reason") {
stopReason = chunk.stop_reason;
// Continue reading stream to get usage_statistics that may come after