@@ -28,6 +28,8 @@ const runtimeMock = {
2828 sessionCreateSignals : [ ] as Array < AbortSignal | undefined > ,
2929 promptSignals : [ ] as Array < AbortSignal | undefined > ,
3030 sessionAbortIds : [ ] as string [ ] ,
31+ sessionAbortSignals : [ ] as Array < AbortSignal | undefined > ,
32+ abortStall : false ,
3133 abortFailure : undefined as Error | undefined ,
3234 connectionError : undefined as Error | undefined ,
3335 sessionCreateError : undefined as unknown ,
@@ -47,6 +49,8 @@ const runtimeMock = {
4749 this . state . sessionCreateSignals . length = 0 ;
4850 this . state . promptSignals . length = 0 ;
4951 this . state . sessionAbortIds . length = 0 ;
52+ this . state . sessionAbortSignals . length = 0 ;
53+ this . state . abortStall = false ;
5054 this . state . abortFailure = undefined ;
5155 this . state . connectionError = undefined ;
5256 this . state . sessionCreateError = undefined ;
@@ -112,8 +116,13 @@ const OpenCodeRuntimeTestDouble: OpenCodeRuntime.OpenCodeRuntime["Service"] = {
112116 }
113117 return runtimeMock . state . sessionResult ?? { data : { id : `${ baseUrl } /session` } } ;
114118 } ,
115- abort : async ( input : { readonly sessionID : string } ) => {
119+ abort : async (
120+ input : { readonly sessionID : string } ,
121+ options ?: { readonly signal ?: AbortSignal } ,
122+ ) => {
116123 runtimeMock . state . sessionAbortIds . push ( input . sessionID ) ;
124+ runtimeMock . state . sessionAbortSignals . push ( options ?. signal ) ;
125+ if ( runtimeMock . state . abortStall ) return new Promise < never > ( ( ) => { } ) ;
117126 if ( runtimeMock . state . abortFailure ) throw runtimeMock . state . abortFailure ;
118127 return { data : true } ;
119128 } ,
@@ -604,6 +613,38 @@ it.layer(layerOpenCodeTextGenerationTest)("OpenCodeTextGeneration", (it) => {
604613 ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
605614 ) ;
606615
616+ it . effect ( "bounds a stalled server-side abort without masking the prompt timeout" , ( ) =>
617+ withOpenCodeTextGeneration ( EXISTING_SERVER_OPENCODE_SETTINGS , ( textGeneration ) =>
618+ Effect . gen ( function * ( ) {
619+ runtimeMock . state . abortStall = true ;
620+ runtimeMock . state . promptResult = new Promise ( ( ) => { } ) as unknown as NonNullable <
621+ typeof runtimeMock . state . promptResult
622+ > ;
623+
624+ const child = yield * textGeneration
625+ . generateCommitMessage ( DEFAULT_COMMIT_MESSAGE_INPUT )
626+ . pipe ( Effect . forkChild ) ;
627+ while ( runtimeMock . state . promptUrls . length === 0 ) {
628+ yield * Effect . yieldNow ;
629+ }
630+ yield * TestClock . adjust ( Duration . seconds ( 181 ) ) ;
631+ // An already-interrupted prompt must still enter session-abort cleanup.
632+ while ( runtimeMock . state . sessionAbortIds . length === 0 ) {
633+ yield * Effect . yieldNow ;
634+ }
635+ expect ( runtimeMock . state . sessionAbortIds ) . toEqual ( [ "http://127.0.0.1:9999/session" ] ) ;
636+ expect ( runtimeMock . state . sessionAbortSignals . at ( - 1 ) ?. aborted ) . toBe ( false ) ;
637+ yield * TestClock . adjust ( Duration . seconds ( 10 ) ) ;
638+
639+ const error = yield * Fiber . join ( child ) . pipe ( Effect . flip ) ;
640+ expect ( error ) . toBeInstanceOf ( TextGenerationError ) ;
641+ expect ( error . detail ) . toContain ( "timed out" ) ;
642+ expect ( runtimeMock . state . sessionAbortSignals . at ( - 1 ) ?. aborted ) . toBe ( true ) ;
643+ expect ( runtimeMock . state . sessionAbortIds ) . toHaveLength ( 1 ) ;
644+ } ) ,
645+ ) . pipe ( Effect . provide ( TestClock . layer ( ) ) ) ,
646+ ) ;
647+
607648 it . effect ( "does not mask a timed-out prompt when its session abort fails" , ( ) =>
608649 withOpenCodeTextGeneration ( EXISTING_SERVER_OPENCODE_SETTINGS , ( textGeneration ) =>
609650 Effect . gen ( function * ( ) {
0 commit comments