Skip to content

Commit 25a468d

Browse files
committed
fix: count history replays so an old load cannot end a newer one
1 parent a325a8f commit 25a468d

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎apps/mobile/src/chat.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ export function ChatScreen({
217217
const [saveError, setSaveError] = useState("");
218218
const [historyError, setHistoryError] = useState("");
219219
const [historyAttempt, setHistoryAttempt] = useState(0);
220-
const replaying = useRef(false);
220+
// Loads still replaying history. A count, so an old load finishing does not end a newer one.
221+
const replaying = useRef(0);
221222
useEffect(() => {
222223
if (!isReady) return;
223224
let active = true;
@@ -233,7 +234,7 @@ export function ChatScreen({
233234
if (richThreads) {
234235
if (selection.existing) {
235236
// Replaying history re-emits past RUN_ERROR events; only connection failures block loading.
236-
replaying.current = true;
237+
replaying.current += 1;
237238
try {
238239
await runConversationTurn(
239240
agentId,
@@ -242,7 +243,7 @@ export function ChatScreen({
242243
[replayedRunError],
243244
);
244245
} finally {
245-
replaying.current = false;
246+
replaying.current -= 1;
246247
}
247248
}
248249
} else {
@@ -362,7 +363,7 @@ export function ChatScreen({
362363
onError: (event) => {
363364
if (event.context?.agentId && event.context.agentId !== agentId) return;
364365
// A failed turn saved in history is already over; it is not a failure of this session.
365-
if (replaying.current && event.code === replayedRunError) return;
366+
if (replaying.current > 0 && event.code === replayedRunError) return;
366367
const failure = event.error instanceof Error ? event.error : new Error(String(event.error));
367368
setError(failure.message);
368369
},

0 commit comments

Comments
 (0)