@@ -8088,7 +8088,7 @@ describe("AcpAdapterV2", () => {
80888088 ) ;
80898089
80908090 it . effect (
8091- "staggered pre-settle completion keeps midTurn marks until last background task ends post-finalize " ,
8091+ "staggered pre-settle completion waits for native wake output after the last background task ends" ,
80928092 ( ) =>
80938093 Effect . gen ( function * ( ) {
80948094 const childProcessSpawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
@@ -8284,12 +8284,19 @@ describe("AcpAdapterV2", () => {
82848284 "mutation-only end-notice must not count as post-settle wake evidence" ,
82858285 ) ;
82868286 yield * sessionUpdateHandler ! ( bEndNotice ) ;
8287- yield * Effect . yieldNow ;
8288- yield * Effect . yieldNow ;
8287+ assert . lengthOf ( continuationRequests , 0 , "a task end notice alone cannot start a wake" ) ;
8288+ assert . isTrue ( yield * runtime . hasPendingBackgroundWork ! ) ;
8289+ yield * sessionUpdateHandler ! ( {
8290+ sessionId : "mock-session-1" ,
8291+ update : {
8292+ sessionUpdate : "agent_message_chunk" ,
8293+ content : { type : "text" , text : "Both background tasks finished." } ,
8294+ } ,
8295+ } ) ;
82898296 assert . lengthOf (
82908297 continuationRequests ,
82918298 1 ,
8292- "exactly one continuation when the last running task ends post-finalize with kept midTurn marks " ,
8299+ "the native report must start exactly one continuation " ,
82938300 ) ;
82948301 } ) . pipe ( Effect . provide ( layerTest ) , Effect . scoped ) ,
82958302 ) ;
@@ -8953,6 +8960,11 @@ describe("AcpAdapterV2", () => {
89538960 yield * complete ( "early" ) ;
89548961 assert . lengthOf ( continuationRequests , 0 ) ;
89558962
8963+ yield * update ( {
8964+ sessionUpdate : "agent_message_chunk" ,
8965+ content : { type : "text" , text : "EARLY_SUCCESS_DONE" } ,
8966+ } ) ;
8967+
89568968 let backgroundItem : ProviderAdapter . ProviderAdapterV2Event | undefined ;
89578969 let checkpoint = 0 ;
89588970 const assertCommand = Effect . fnUntraced ( function * ( expectedStatus : string , output : string ) {
@@ -9015,14 +9027,55 @@ describe("AcpAdapterV2", () => {
90159027 assert . equal ( event . status , "completed" ) ;
90169028 break ;
90179029 }
9018- yield * Deferred . await ( continuationOffered ) ;
90199030 yield * complete ( "early" ) ;
90209031 yield * complete ( "blocker" ) ;
9032+ assert . lengthOf (
9033+ continuationRequests ,
9034+ 0 ,
9035+ "a task completion without native wake output must not replace the root answer" ,
9036+ ) ;
9037+ assert . isTrue ( yield * runtime . hasPendingBackgroundWork ! ) ;
9038+
9039+ yield * update ( {
9040+ sessionUpdate : "agent_thought_chunk" ,
9041+ content : { type : "text" , text : "Preparing the background report" } ,
9042+ } ) ;
9043+ yield * complete ( "early" ) ;
9044+ assert . lengthOf ( continuationRequests , 0 , "reasoning alone is not a result-bearing wake" ) ;
9045+ yield * update ( {
9046+ sessionUpdate : "agent_message_chunk" ,
9047+ content : { type : "text" , text : "LATE_NATIVE_ANSWER" } ,
9048+ } ) ;
9049+ yield * Deferred . await ( continuationOffered ) ;
90219050 assert . lengthOf (
90229051 continuationRequests ,
90239052 1 ,
90249053 "duplicate completions must not offer another continuation" ,
90259054 ) ;
9055+ yield * runtime . startTurn (
9056+ makeTurnInput ( {
9057+ threadId,
9058+ providerThread,
9059+ instanceId,
9060+ runtimePolicy,
9061+ now : yield * DateTime . now ,
9062+ ordinal : 2 ,
9063+ messageCreatedBy : "agent" ,
9064+ messageCreationSource : "provider" ,
9065+ messageText : "Background task completed." ,
9066+ } ) ,
9067+ ) ;
9068+ yield * TestClock . adjust ( yield * Deferred . await ( finalizeScheduled ) ) ;
9069+ let nativeAnswerSeen = false ;
9070+ while ( true ) {
9071+ const event = yield * Queue . take ( events ) ;
9072+ if ( event . type === "message.updated" && event . message . text === "LATE_NATIVE_ANSWER" ) {
9073+ nativeAnswerSeen = true ;
9074+ }
9075+ if ( event . type === "turn.terminal" ) break ;
9076+ }
9077+ assert . isTrue ( nativeAnswerSeen ) ;
9078+ assert . isFalse ( yield * runtime . hasPendingBackgroundWork ! ) ;
90269079 } ) . pipe ( Effect . provide ( layerTest ) , Effect . scoped ) ,
90279080 ) ;
90289081
0 commit comments