@@ -274,6 +274,7 @@ import {
274274 resolveSendEnvMode ,
275275 revokeBlobPreviewUrl ,
276276 revokeUserMessagePreviewUrls ,
277+ shouldWriteThreadErrorToCurrentServerThread ,
277278 startNewThreadForProject ,
278279 waitForStartedServerThread ,
279280} from "./ChatView.logic" ;
@@ -1204,6 +1205,7 @@ function ChatViewContent(props: ChatViewProps) {
12041205 : null ,
12051206 [ routeServerThreadShell , threadDetailLoading ] ,
12061207 ) ;
1208+ const activeServerThread = serverThread ?? loadingServerThread ;
12071209 const markThreadVisited = useUiStateStore ( ( store ) => store . markThreadVisited ) ;
12081210 const activeThreadLastVisitedAt = useUiStateStore (
12091211 ( store ) => store . threadLastVisitedAtById [ routeThreadKey ] ,
@@ -1383,7 +1385,7 @@ function ChatViewContent(props: ChatViewProps) {
13831385 ? scopeProjectRef ( draftThread . environmentId , draftThread . projectId )
13841386 : null ;
13851387 const fallbackDraftProject = useProject ( fallbackDraftProjectRef ) ;
1386- const localDraftError = serverThread
1388+ const localDraftError = activeServerThread
13871389 ? null
13881390 : ( ( draftId ? localDraftErrorsByDraftId [ draftId ] ?. message : null ) ?? null ) ;
13891391 const localServerError = localServerErrorsByThreadKey [ routeThreadKey ] ?. message ?? null ;
@@ -1392,7 +1394,7 @@ function ChatViewContent(props: ChatViewProps) {
13921394 // a failed send would silently disappear on promotion. When both keys hold
13931395 // an entry, the most recent write wins.
13941396 useEffect ( ( ) => {
1395- if ( ! serverThread || ! draftId ) {
1397+ if ( ! activeServerThread || ! draftId ) {
13961398 return ;
13971399 }
13981400 const pendingDraftEntry = localDraftErrorsByDraftId [ draftId ] ;
@@ -1421,7 +1423,7 @@ function ChatViewContent(props: ChatViewProps) {
14211423 [ routeThreadKey ] : pendingDraftEntry ,
14221424 } ;
14231425 } ) ;
1424- } , [ draftId , localDraftErrorsByDraftId , routeThreadKey , serverThread ] ) ;
1426+ } , [ activeServerThread , draftId , localDraftErrorsByDraftId , routeThreadKey ] ) ;
14251427 const localDraftThread = useMemo (
14261428 ( ) =>
14271429 draftThread
@@ -1436,7 +1438,6 @@ function ChatViewContent(props: ChatViewProps) {
14361438 // Promotion is data-driven: the draft route keeps rendering while the
14371439 // server thread (same pre-allocated ref) starts, so live state must not
14381440 // depend on which route is mounted.
1439- const activeServerThread = serverThread ?? loadingServerThread ;
14401441 const isServerThread = activeServerThread !== null ;
14411442 const activeThread = activeServerThread ?? localDraftThread ;
14421443 const threadError = isServerThread
@@ -2506,10 +2507,11 @@ function ChatViewContent(props: ChatViewProps) {
25062507 const nextError = sanitizeThreadErrorMessage ( error ) ;
25072508 const nextEntry : LocalThreadErrorEntry = { message : nextError , at : Date . now ( ) } ;
25082509 if (
2509- serverThread &&
2510- targetThreadId === routeThreadRef . threadId &&
2511- serverThread . environmentId === routeThreadRef . environmentId &&
2512- serverThread . id === targetThreadId
2510+ shouldWriteThreadErrorToCurrentServerThread ( {
2511+ activeServerThread,
2512+ routeThreadRef,
2513+ targetThreadId,
2514+ } )
25132515 ) {
25142516 setLocalServerErrorsByThreadKey ( ( existing ) => {
25152517 if ( ( existing [ routeThreadKey ] ?. message ?? null ) === nextError ) {
@@ -2533,7 +2535,7 @@ function ChatViewContent(props: ChatViewProps) {
25332535 } ;
25342536 } ) ;
25352537 } ,
2536- [ draftId , routeThreadKey , routeThreadRef , serverThread ] ,
2538+ [ activeServerThread , draftId , routeThreadKey , routeThreadRef ] ,
25372539 ) ;
25382540
25392541 const focusComposer = useCallback ( ( ) => {
0 commit comments