@@ -151,7 +151,7 @@ import {
151151 useProjects ,
152152 useServerConfigs ,
153153 useQuietThreadShells ,
154- waitForTitleRegenerationFailure ,
154+ watchThreadTitleRegeneration ,
155155} from "../state/entities" ;
156156import { environmentPresentations } from "../state/presentation" ;
157157import { primaryServerKeybindingsAtom } from "../state/server" ;
@@ -2442,22 +2442,30 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
24422442 return ;
24432443 }
24442444 if ( clicked . value === "regenerate-title" ) {
2445- const failures : Array < Promise < string | null > > = [ ] ;
24462445 for ( const thread of regeneratableTitleThreads ) {
24472446 const commandId = CommandId . make ( randomUUID ( ) ) ;
2447+ const watch = watchThreadTitleRegeneration (
2448+ scopeThreadRef ( thread . environmentId , thread . id ) ,
2449+ commandId ,
2450+ ) ;
24482451 const result = await updateThreadMetadata ( {
24492452 environmentId : thread . environmentId ,
24502453 input : { threadId : thread . id , regenerateTitle : true , commandId } ,
24512454 } ) ;
24522455 if ( result . _tag === "Success" ) {
2453- failures . push (
2454- waitForTitleRegenerationFailure (
2455- scopeThreadRef ( thread . environmentId , thread . id ) ,
2456- commandId ,
2457- ) ,
2458- ) ;
2456+ void watch . failure . then ( ( failure ) => {
2457+ if ( failure === null ) return ;
2458+ toastManager . add (
2459+ stackedThreadToast ( {
2460+ type : "error" ,
2461+ title : "Failed to regenerate thread title" ,
2462+ description : `${ thread . title } : ${ failure } ` ,
2463+ } ) ,
2464+ ) ;
2465+ } ) ;
24592466 continue ;
24602467 }
2468+ watch . cancel ( ) ;
24612469 if ( ! isAtomCommandInterrupted ( result ) ) {
24622470 const error = squashAtomCommandFailure ( result ) ;
24632471 toastManager . add (
@@ -2471,20 +2479,6 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
24712479 return ;
24722480 }
24732481 clearSelection ( ) ;
2474- void Promise . all ( failures ) . then ( ( outcomes ) => {
2475- const messages = outcomes . filter ( ( message ) => message !== null ) ;
2476- if ( messages . length === 0 ) return ;
2477- toastManager . add (
2478- stackedThreadToast ( {
2479- type : "error" ,
2480- title :
2481- messages . length === 1
2482- ? "Failed to regenerate a thread title"
2483- : `Failed to regenerate ${ messages . length } thread titles` ,
2484- description : messages [ 0 ] ,
2485- } ) ,
2486- ) ;
2487- } ) ;
24882482 return ;
24892483 }
24902484 if ( clicked . value === "settle" ) {
@@ -2798,11 +2792,13 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
27982792 case "regenerate-title" : {
27992793 if ( isRegeneratingTitle ) return ;
28002794 const commandId = CommandId . make ( randomUUID ( ) ) ;
2795+ const watch = watchThreadTitleRegeneration ( threadRef , commandId ) ;
28012796 const result = await updateThreadMetadata ( {
28022797 environmentId : threadRef . environmentId ,
28032798 input : { threadId : threadRef . threadId , regenerateTitle : true , commandId } ,
28042799 } ) ;
28052800 if ( result . _tag === "Failure" ) {
2801+ watch . cancel ( ) ;
28062802 if ( ! isAtomCommandInterrupted ( result ) ) {
28072803 const error = squashAtomCommandFailure ( result ) ;
28082804 toastManager . add (
@@ -2815,7 +2811,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
28152811 }
28162812 return ;
28172813 }
2818- void waitForTitleRegenerationFailure ( threadRef , commandId ) . then ( ( failure ) => {
2814+ void watch . failure . then ( ( failure ) => {
28192815 if ( failure === null ) return ;
28202816 toastManager . add (
28212817 stackedThreadToast ( {
0 commit comments