@@ -1496,6 +1496,42 @@ describe("agentLoop tool termination", () => {
14961496 expect ( getSteeringMessages ) . toHaveBeenCalled ( ) ;
14971497 } ) ;
14981498
1499+ it ( "delivers steering admitted while the final follow-up drain is pending" , async ( ) => {
1500+ const followUpDrainStarted = createDeferred ( ) ;
1501+ const releaseFollowUpDrain = createDeferred ( ) ;
1502+ const steer = { role : "user" as const , content : "one more thing" , timestamp : 2 } ;
1503+ const queued : AgentMessage [ ] = [ ] ;
1504+ const requestMessages : Message [ ] [ ] = [ ] ;
1505+ const run = runAgentLoop (
1506+ [ { role : "user" , content : "start" , timestamp : 1 } ] ,
1507+ { systemPrompt : "" , messages : [ ] } ,
1508+ {
1509+ ...config ,
1510+ getSteeringMessages : async ( ) => queued . splice ( 0 , 1 ) ,
1511+ getFollowUpMessages : async ( ) => {
1512+ followUpDrainStarted . resolve ( ) ;
1513+ await releaseFollowUpDrain . promise ;
1514+ return [ ] ;
1515+ } ,
1516+ } ,
1517+ ( ) => { } ,
1518+ undefined ,
1519+ createTurnSequenceStream (
1520+ [ [ { type : "text" , text : "initial response" } ] , [ { type : "text" , text : "steer response" } ] ] ,
1521+ requestMessages ,
1522+ ) ,
1523+ ) ;
1524+
1525+ await followUpDrainStarted . promise ;
1526+ queued . push ( steer ) ;
1527+ releaseFollowUpDrain . resolve ( ) ;
1528+ await run ;
1529+
1530+ expect ( requestMessages ) . toHaveLength ( 2 ) ;
1531+ expect ( requestMessages [ 1 ] ?. at ( - 1 ) ) . toBe ( steer ) ;
1532+ expect ( queued ) . toEqual ( [ ] ) ;
1533+ } ) ;
1534+
14991535 it ( "suppresses sequential tools when steering arrives from awaited message_end" , async ( ) => {
15001536 const execute = vi . fn ( async ( ) => ( { content : [ ] , details : { } } ) ) ;
15011537 const requestMessages : Message [ ] [ ] = [ ] ;
0 commit comments