@@ -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