@@ -23,7 +23,8 @@ import {
2323 type TerminalPanelSessionControllerState ,
2424 type TerminalPanelSessionTab ,
2525} from "./terminal-panel-session-types.ts" ;
26- import { terminalIntentQueue , type TerminalIntentHost } from "./terminal-pending-actions.ts" ;
26+ import { TerminalOpenRetry , terminalIntentQueue } from "./terminal-pending-actions.ts" ;
27+ import type { TerminalIntentHost } from "./terminal-pending-actions.ts" ;
2728import {
2829 loadPersistedTerminalSessionIds ,
2930 persistLiveTerminalSessions ,
@@ -33,8 +34,6 @@ import { TerminalTabReadinessController } from "./terminal-tab-readiness.ts";
3334import { TerminalTaskQueue } from "./terminal-task-queue.ts" ;
3435import { terminalDynamicColors , terminalTheme } from "./terminal-theme.ts" ;
3536
36- type TerminalSessionSink = Parameters < TerminalConnection [ "open" ] > [ 1 ] ;
37-
3837/** Owns gateway PTY sessions and the Ghostty controllers bound to them. */
3938export class TerminalPanelSessionController
4039 implements ReactiveController , TerminalPanelSessionControllerState
@@ -52,6 +51,7 @@ export class TerminalPanelSessionController
5251 private lifecycleAbortController = new AbortController ( ) ;
5352 private lifecycleSyncToken = 0 ;
5453 private tabSequence = 0 ;
54+ readonly openRetry = new TerminalOpenRetry ( ) ;
5555 private readonly bootQueue = new TerminalTaskQueue ( ) ;
5656 private readonly intentHost : TerminalIntentHost ;
5757 private readonly readiness : TerminalTabReadinessController < TerminalPanelSessionTab > ;
@@ -70,17 +70,14 @@ export class TerminalPanelSessionController
7070 requestUpdate : ( ) => this . host . requestUpdate ( ) ,
7171 setBooting : ( booting ) => this . updateControllerState ( "booting" , booting ) ,
7272 timeoutMs : ( ) => this . host . catalogReadyTimeoutMs ,
73- showTimeout : ( ) => {
74- this . host . terminalPanelErrorText = t ( "terminal.refreshRequired" ) ;
75- } ,
76- clearTimeout : ( ) => {
77- this . host . terminalPanelErrorText = null ;
78- } ,
73+ showTimeout : ( ) => ( this . host . terminalPanelErrorText = t ( "terminal.refreshRequired" ) ) ,
74+ clearTimeout : ( ) => ( this . host . terminalPanelErrorText = null ) ,
7975 } ;
8076 this . readiness = new TerminalTabReadinessController < TerminalPanelSessionTab > ( {
8177 timeoutMs : ( ) => this . host . catalogReadyTimeoutMs ,
8278 isCurrent : ( tab ) => this . tabs . includes ( tab ) ,
8379 onReady : ( ) => {
80+ this . openRetry . clear ( ) ;
8481 this . updateControllerState ( "tabs" , [ ...this . tabs ] ) ;
8582 persistLiveTerminalSessions ( this . tabs ) ;
8683 } ,
@@ -318,6 +315,7 @@ export class TerminalPanelSessionController
318315 return false ;
319316 }
320317 this . updateControllerState ( "booting" , true ) ;
318+ this . openRetry . clear ( ) ;
321319 this . host . terminalPanelErrorText = null ;
322320 try {
323321 const attached = await this . attachSession ( sessionId , operation , agentOwned ) ;
@@ -413,7 +411,7 @@ export class TerminalPanelSessionController
413411 readyTimer : null ,
414412 } ;
415413 tabReference . current = tab ;
416- const sink : TerminalSessionSink = {
414+ const sink : Parameters < TerminalConnection [ "open" ] > [ 1 ] = {
417415 // The cancelled guard also protects the buffered-event replay inside
418416 // connection.open/attach from writing to an already-disposed terminal.
419417 onData : ( data : string ) => {
@@ -520,6 +518,7 @@ export class TerminalPanelSessionController
520518 return false ;
521519 }
522520 this . updateControllerState ( "booting" , true ) ;
521+ this . openRetry . remember ( catalog , agentId ) ;
523522 this . host . terminalPanelErrorText = null ;
524523 // Freeze the selection for this tab; later agent changes affect only new tabs.
525524 const ownerAgentId = agentId ?? undefined ;
@@ -561,6 +560,7 @@ export class TerminalPanelSessionController
561560 if ( ! this . isTerminalOperationCurrent ( operation ) ) {
562561 return false ;
563562 }
563+ this . openRetry . clearUnlessRetryable ( error ) ;
564564 this . host . terminalPanelErrorText = terminalOpenErrorText ( error ) ;
565565 return true ;
566566 } finally {
@@ -766,6 +766,7 @@ export class TerminalPanelSessionController
766766 this . lifecycleAbortController . abort ( ) ;
767767 this . lifecycleAbortController = new AbortController ( ) ;
768768 this . bootQueue . reset ( ) ;
769+ this . openRetry . clear ( ) ;
769770 this . updateControllerState ( "booting" , false ) ;
770771 this . host . terminalPanelUploadController . dispose ( ) ;
771772 this . host . clearTerminalPanelResizeListeners ( ) ;
0 commit comments