Skip to content

Commit aa53c02

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

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
@@ -200,7 +200,8 @@ export function ChatScreen({
200200
const [saveError, setSaveError] = useState("");
201201
const [historyError, setHistoryError] = useState("");
202202
const [historyAttempt, setHistoryAttempt] = useState(0);
203-
const replaying = useRef(false);
203+
// Loads still replaying history. A count, so an old load finishing does not end a newer one.
204+
const replaying = useRef(0);
204205
useEffect(() => {
205206
if (!isReady) return;
206207
let active = true;
@@ -216,7 +217,7 @@ export function ChatScreen({
216217
if (richThreads) {
217218
if (selection.existing) {
218219
// Replaying history re-emits past RUN_ERROR events; only connection failures block loading.
219-
replaying.current = true;
220+
replaying.current += 1;
220221
try {
221222
await runConversationTurn(
222223
agentId,
@@ -225,7 +226,7 @@ export function ChatScreen({
225226
[replayedRunError],
226227
);
227228
} finally {
228-
replaying.current = false;
229+
replaying.current -= 1;
229230
}
230231
}
231232
} else {
@@ -309,7 +310,7 @@ export function ChatScreen({
309310
onError: (event) => {
310311
if (event.context?.agentId && event.context.agentId !== agentId) return;
311312
// A failed turn saved in history is already over; it is not a failure of this session.
312-
if (replaying.current && event.code === replayedRunError) return;
313+
if (replaying.current > 0 && event.code === replayedRunError) return;
313314
const failure = event.error instanceof Error ? event.error : new Error(String(event.error));
314315
setError(failure.message);
315316
},

0 commit comments

Comments
 (0)