Skip to content

Commit 9a9ecd8

Browse files
committed
fix: add latestTurn regression guard to thread.message-sent handler
Add the same defensive guard that thread.turn-diff-completed uses to prevent a late-arriving assistant message from an older turn from overwriting latestTurn, which could regress the current turn's progress.
1 parent 0e1dfe5 commit 9a9ecd8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

apps/web/src/store.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,9 @@ export function applyOrchestrationEvent(state: AppState, event: OrchestrationEve
608608
: [...thread.messages, message];
609609
const cappedMessages = messages.slice(-MAX_THREAD_MESSAGES);
610610
const latestTurn: Thread["latestTurn"] =
611-
event.payload.role === "assistant" && event.payload.turnId !== null
611+
event.payload.role === "assistant" &&
612+
event.payload.turnId !== null &&
613+
(thread.latestTurn === null || thread.latestTurn.turnId === event.payload.turnId)
612614
? buildLatestTurn({
613615
previous: thread.latestTurn,
614616
turnId: event.payload.turnId,

0 commit comments

Comments
 (0)