@@ -3679,6 +3679,94 @@ describe("CodexAdapterV2 post-settle continuation", () => {
36793679 ) ,
36803680 ) ;
36813681
3682+ it . effect ( "streams a proposed plan a few times a second instead of once per delta" , ( ) =>
3683+ Effect . scoped (
3684+ Effect . gen ( function * ( ) {
3685+ const scenario = "codex-plan-delta-coalescing" ;
3686+ const nativeThreadId = `native-${ scenario } -thread` ;
3687+ const nativeTurnId = `native-${ scenario } -turn` ;
3688+ const prompt = "Plan the change." ;
3689+ // 100 deltas, 20 ms apart: a two second stream.
3690+ const deltas = Array . from ( { length : 100 } , ( _ , index ) => `step ${ index } \n` ) ;
3691+ const transcript = makeCodexReplayTranscript ( {
3692+ scenario,
3693+ entries : [
3694+ ...codexReplayPreamble ( { nativeThreadId, nativeTurnId, prompt } ) ,
3695+ ...deltas . map ( ( delta , index ) : CodexReplay . CodexAppServerReplayEntry => ( {
3696+ type : "emit_inbound" ,
3697+ label : `item/plan/delta/${ index } ` ,
3698+ afterMs : 20 ,
3699+ frame : {
3700+ method : "item/plan/delta" ,
3701+ params : { threadId : nativeThreadId , turnId : nativeTurnId , itemId : "plan" , delta } ,
3702+ } ,
3703+ } ) ) ,
3704+ {
3705+ type : "emit_inbound" ,
3706+ label : "item/completed/plan" ,
3707+ frame : {
3708+ method : "item/completed" ,
3709+ params : {
3710+ threadId : nativeThreadId ,
3711+ turnId : nativeTurnId ,
3712+ item : { type : "plan" , id : "plan" , text : "" } ,
3713+ } ,
3714+ } ,
3715+ } ,
3716+ {
3717+ type : "emit_inbound" ,
3718+ label : "turn/completed" ,
3719+ frame : {
3720+ method : "turn/completed" ,
3721+ params : {
3722+ threadId : nativeThreadId ,
3723+ turn : makeCodexReplayTurn ( { id : nativeTurnId , status : "completed" } ) ,
3724+ } ,
3725+ } ,
3726+ } ,
3727+ ] ,
3728+ } ) ;
3729+ const harness = yield * makeCodexReplayHarness ( transcript ) ;
3730+ yield * harness . runtime . startTurn (
3731+ makeCodexTestTurnInput ( {
3732+ threadId : harness . threadId ,
3733+ providerThread : harness . providerThread ,
3734+ now : yield * DateTime . now ,
3735+ attemptId : RunAttemptId . make ( `attempt-${ scenario } ` ) ,
3736+ text : prompt ,
3737+ } ) ,
3738+ ) ;
3739+ for ( let step = 0 ; step < 200 && harness . terminalEvents ( ) . length === 0 ; step += 1 ) {
3740+ yield * Effect . yieldNow ;
3741+ yield * TestClock . adjust ( "20 millis" ) ;
3742+ }
3743+ yield * harness . firstTerminal ;
3744+
3745+ const plans = harness . events . flatMap ( ( event ) =>
3746+ event . type === "plan.updated" && event . plan . kind === "proposed_plan" ? [ event . plan ] : [ ] ,
3747+ ) ;
3748+ const planItems = harness . events . flatMap ( ( event ) =>
3749+ event . type === "turn_item.updated" && event . turnItem . type === "proposed_plan"
3750+ ? [ event . turnItem ]
3751+ : [ ] ,
3752+ ) ;
3753+ // One update per 400 ms of the stream, plus the completion.
3754+ assert . isAtLeast ( plans . length , 2 ) ;
3755+ assert . isAtMost ( plans . length , 7 ) ;
3756+ assert . equal ( planItems . length , plans . length ) ;
3757+ assert . equal ( plans . at ( - 1 ) ?. markdown , deltas . join ( "" ) ) ;
3758+ assert . deepEqual (
3759+ planItems . map ( ( item ) => item . streaming ) ,
3760+ [ ...Array . from ( { length : planItems . length - 1 } , ( ) => true ) , false ] ,
3761+ ) ;
3762+ } ) . pipe (
3763+ Effect . provide (
3764+ Layer . mergeAll ( IdAllocator . layer , McpProviderSessions . layer , NodeServices . layer ) ,
3765+ ) ,
3766+ ) ,
3767+ ) ,
3768+ ) ;
3769+
36823770 const finalAnswerTranscript = (
36833771 scenario : string ,
36843772 answers : ReadonlyArray < {
0 commit comments