@@ -28,7 +28,14 @@ export abstract class ChatPaneSessionMenu extends ChatPaneContext {
2828 private headerSessionOperationsLoad : Promise <
2929 typeof import ( "../../components/session-organizer-operations.runtime.ts" )
3030 > | null = null ;
31-
31+ private headerPresentationGeneration = 0 ;
32+ protected override presentedChanged ( presented : boolean ) : void {
33+ this . headerPresentationGeneration += 1 ;
34+ super . presentedChanged ( presented ) ;
35+ }
36+ private get headerOutcomeOwner ( ) {
37+ return `${ this . connectionGeneration } :${ this . headerPresentationGeneration } ` ;
38+ }
3239 protected async loadHeaderPlatform (
3340 client : GatewayBrowserClient ,
3441 generation : number ,
@@ -72,6 +79,7 @@ export abstract class ChatPaneSessionMenu extends ChatPaneContext {
7279 this . publishHeaderError ( t ( "sessionsView.actionRequiresConnection" ) ) ;
7380 return ;
7481 }
82+ const owner = this . headerOutcomeOwner ;
7583 const session = {
7684 key : row . key ,
7785 sessionId : row . sessionId ,
@@ -89,10 +97,10 @@ export abstract class ChatPaneSessionMenu extends ChatPaneContext {
8997 const host : SessionActionHost = {
9098 sessionData : {
9199 isSessionMutationScopeCurrent : ( candidate ) =>
92- this . isHeaderSessionActionScopeCurrent ( candidate ) ,
100+ this . isHeaderSessionActionCurrent ( candidate , owner ) ,
93101 publishSessionMutationError : ( candidate , error ) => {
94- if ( this . isHeaderSessionActionScopeCurrent ( candidate ) ) {
95- this . publishHeaderError ( error ) ;
102+ if ( this . isHeaderSessionActionCurrent ( candidate , owner ) ) {
103+ this . publishHeaderError ( error , owner ) ;
96104 }
97105 } ,
98106 refreshSidebarSessions : async ( agentId ) => {
@@ -126,8 +134,8 @@ export abstract class ChatPaneSessionMenu extends ChatPaneContext {
126134 break ;
127135 }
128136 } catch ( error ) {
129- if ( this . isHeaderSessionActionScopeCurrent ( scope ) ) {
130- this . publishHeaderError ( error ) ;
137+ if ( this . isHeaderSessionActionCurrent ( scope , owner ) ) {
138+ this . publishHeaderError ( error , owner ) ;
131139 }
132140 }
133141 }
@@ -221,10 +229,10 @@ export abstract class ChatPaneSessionMenu extends ChatPaneContext {
221229 } ;
222230 }
223231
224- private isHeaderSessionActionScopeCurrent ( scope : SidebarSessionMutationScope ) : boolean {
232+ private isHeaderSessionActionCurrent ( scope : SidebarSessionMutationScope , owner : string ) : boolean {
225233 return (
234+ owner === this . headerOutcomeOwner &&
226235 this . isConnected &&
227- this . connectionGeneration === scope . epoch &&
228236 this . context === scope . context &&
229237 this . context . gateway === scope . gateway &&
230238 this . context . sessions === scope . sessions &&
@@ -284,8 +292,9 @@ export abstract class ChatPaneSessionMenu extends ChatPaneContext {
284292 this . publishHeaderError ( access . reason ) ;
285293 return ;
286294 }
295+ const owner = this . headerOutcomeOwner ;
287296 void patchChatSessionLabel ( state , this . context . sessions , key , label ) . catch ( ( error : unknown ) =>
288- this . publishHeaderError ( error ) ,
297+ this . publishHeaderError ( error , owner ) ,
289298 ) ;
290299 }
291300
@@ -387,11 +396,15 @@ export abstract class ChatPaneSessionMenu extends ChatPaneContext {
387396 const copiedValue =
388397 action === "copy-path" ? workspaceRoot : action === "copy-branch" ? branch : null ;
389398 if ( copiedValue ) {
399+ const owner = this . headerOutcomeOwner ;
390400 void copy ( copiedValue ) . then ( ( copied ) => {
401+ if ( ! this . presented || owner !== this . headerOutcomeOwner ) {
402+ return ;
403+ }
391404 if ( copied ) {
392405 this . showHeaderCopied ( action ) ;
393406 } else {
394- this . publishHeaderError ( t ( "common.copyFailed" ) ) ;
407+ this . publishHeaderError ( t ( "common.copyFailed" ) , owner ) ;
395408 }
396409 } ) ;
397410 return ;
@@ -401,12 +414,12 @@ export abstract class ChatPaneSessionMenu extends ChatPaneContext {
401414 }
402415 }
403416
404- protected publishHeaderError ( error : unknown ) : void {
405- if ( ! this . state ) {
417+ protected publishHeaderError ( error : unknown , owner = this . headerOutcomeOwner ) : void {
418+ if ( ! this . state || ! this . presented || owner !== this . headerOutcomeOwner ) {
406419 return ;
407420 }
408- this . state . lastError = error instanceof Error ? error . message : String ( error ) ;
409- this . state . chatError = this . state . lastError ;
421+ this . state . chatError = this . state . lastError =
422+ error instanceof Error ? error . message : String ( error ) ;
410423 this . state . requestUpdate ?.( ) ;
411424 }
412425
@@ -415,17 +428,19 @@ export abstract class ChatPaneSessionMenu extends ChatPaneContext {
415428 if ( ! client ) {
416429 return ;
417430 }
431+ const owner = this . headerOutcomeOwner ;
418432 const agentId = parseAgentSessionKey ( row . key ) ?. agentId ;
419433 try {
420434 const result = await client . request < SessionsFilesRevealResult > ( "sessions.files.reveal" , {
421435 key : row . key ,
422436 ...( agentId ? { agentId } : { } ) ,
423437 } ) ;
424438 if ( ! result . ok ) {
425- this . publishHeaderError ( result . error ?? "Failed to reveal session workspace." ) ;
439+ const error = result . error ?? "Failed to reveal session workspace." ;
440+ this . publishHeaderError ( error , owner ) ;
426441 }
427442 } catch ( error ) {
428- this . publishHeaderError ( error ) ;
443+ this . publishHeaderError ( error , owner ) ;
429444 }
430445 }
431446}
0 commit comments