@@ -109,6 +109,23 @@ describe('_session/steering', () => {
109109 } ) ;
110110 } ) ;
111111
112+ it ( 'leaves idle input unconsumed when the host requests an owned prompt fallback' , async ( ) => {
113+ const mockFixture = createCodexMockTestFixture ( ) ;
114+ const sessionState = createTestSessionState ( ) ;
115+ vi . spyOn ( mockFixture . getCodexAcpAgent ( ) , "getSessionState" ) . mockReturnValue ( sessionState ) ;
116+ const turnStartSpy = vi . spyOn ( mockFixture . getCodexAppServerClient ( ) , "turnStart" ) ;
117+ const turnSteerSpy = vi . spyOn ( mockFixture . getCodexAppServerClient ( ) , "turnSteer" ) ;
118+
119+ await expect ( mockFixture . getCodexAcpAgent ( ) . extMethod ( SESSION_STEERING_METHOD , {
120+ sessionId : "session-id" ,
121+ prompt : [ { type : "text" , text : "host-owned follow-up" } ] ,
122+ _meta : { steering : { idleBehavior : "promptRequired" } } ,
123+ } ) ) . resolves . toEqual ( { outcome : "promptRequired" , reason : "noRunningTurn" } ) ;
124+
125+ expect ( turnStartSpy ) . not . toHaveBeenCalled ( ) ;
126+ expect ( turnSteerSpy ) . not . toHaveBeenCalled ( ) ;
127+ } ) ;
128+
112129 it ( 'starts a new turn when Codex reports that the tracked turn is no longer active' , async ( ) => {
113130 const { mockFixture, sessionState, turnCompleted} = startActiveTurn ( ) ;
114131 const nextTurnCompleted = deferred < TurnCompletedNotification > ( ) ;
@@ -152,6 +169,38 @@ describe('_session/steering', () => {
152169 } ) ;
153170 } ) ;
154171
172+ it ( 'returns the host-owned fallback when the tracked turn wins the idle race' , async ( ) => {
173+ const { mockFixture, sessionState, turnCompleted} = startActiveTurn ( ) ;
174+ const turnStartSpy = vi . spyOn ( mockFixture . getCodexAppServerClient ( ) , "turnStart" ) ;
175+ vi . spyOn ( mockFixture . getCodexAppServerClient ( ) , "turnSteer" ) . mockImplementation ( async ( ) => {
176+ turnCompleted . resolve ( {
177+ threadId : "session-id" ,
178+ turn : createTurn ( "turn-id" , "completed" ) ,
179+ } ) ;
180+ throw Object . assign ( new Error ( "Internal error" ) , {
181+ data : { details : "no active turn to steer" } ,
182+ } ) ;
183+ } ) ;
184+
185+ const promptPromise = mockFixture . getCodexAcpAgent ( ) . prompt ( {
186+ sessionId : "session-id" ,
187+ prompt : [ { type : "text" , text : "long running prompt" } ] ,
188+ } ) ;
189+ await vi . waitFor ( ( ) => {
190+ expect ( sessionState . currentTurnId ) . toBe ( "turn-id" ) ;
191+ } ) ;
192+
193+ await expect ( mockFixture . getCodexAcpAgent ( ) . extMethod ( SESSION_STEERING_METHOD , {
194+ sessionId : "session-id" ,
195+ prompt : [ { type : "text" , text : "racing follow-up" } ] ,
196+ _meta : { steering : { idleBehavior : "promptRequired" } } ,
197+ } ) ) . resolves . toEqual ( { outcome : "promptRequired" , reason : "noRunningTurn" } ) ;
198+
199+ await expect ( promptPromise ) . resolves . toMatchObject ( { stopReason : "end_turn" } ) ;
200+ expect ( turnStartSpy ) . toHaveBeenCalledTimes ( 1 ) ;
201+ expect ( sessionState . currentTurnId ) . toBeNull ( ) ;
202+ } ) ;
203+
155204 it ( 'serializes concurrent late steering requests without dropping either prompt' , async ( ) => {
156205 const mockFixture = createCodexMockTestFixture ( ) ;
157206 const sessionState = createTestSessionState ( ) ;
@@ -212,6 +261,16 @@ describe('_session/steering', () => {
212261 } ) ) . rejects . toThrow ( RequestError ) ;
213262 } ) ;
214263
264+ it ( 'rejects an unsupported idle behavior' , async ( ) => {
265+ const mockFixture = createCodexMockTestFixture ( ) ;
266+
267+ await expect ( mockFixture . getCodexAcpAgent ( ) . extMethod ( SESSION_STEERING_METHOD , {
268+ sessionId : "session-id" ,
269+ prompt : [ { type : "text" , text : "follow-up" } ] ,
270+ _meta : { steering : { idleBehavior : "startDetachedTurn" } } ,
271+ } ) ) . rejects . toThrow ( "unsupported steering idleBehavior" ) ;
272+ } ) ;
273+
215274 it ( 'rejects image input when the model does not support it' , async ( ) => {
216275 const { mockFixture} = startActiveTurn ( { supportedInputModalities : [ "text" ] } ) ;
217276 const turnSteerSpy = vi . spyOn ( mockFixture . getCodexAppServerClient ( ) , "turnSteer" ) ;
0 commit comments