@@ -4775,45 +4775,60 @@ describe("runCodexAppServerAttempt", () => {
47754775 } ) ;
47764776 } ) ;
47774777
4778- it . each ( [
4779- { label : "completed turn" , failure : undefined , expectedContext : true } ,
4780- {
4781- label : "provider overload after the tool result" ,
4782- failure : {
4783- message : "Selected model is at capacity. Please try a different model." ,
4784- codexErrorInfo : "serverOverloaded" ,
4778+ it . each (
4779+ [
4780+ { label : "completed turn" , failure : undefined , expectedContext : true } ,
4781+ {
4782+ label : "provider overload after the tool result" ,
4783+ failure : {
4784+ message : "Selected model is at capacity. Please try a different model." ,
4785+ codexErrorInfo : "serverOverloaded" ,
4786+ } ,
4787+ expectedContext : true ,
47854788 } ,
4786- expectedContext : true ,
4787- } ,
4788- {
4789- label : "usage limit after the tool result ",
4790- failure : {
4791- message : "Usage limit exceeded." ,
4792- codexErrorInfo : "usageLimitExceeded" ,
4789+ {
4790+ label : "usage limit after the tool result" ,
4791+ failure : {
4792+ message : "Usage limit exceeded. ",
4793+ codexErrorInfo : "usageLimitExceeded" ,
4794+ } ,
4795+ expectedContext : false ,
47934796 } ,
4794- expectedContext : false ,
4795- } ,
4796- {
4797- label : "unauthorized response after the tool result ",
4798- failure : {
4799- message : "Unauthorized." ,
4800- codexErrorInfo : "unauthorized" ,
4797+ {
4798+ label : "unauthorized response after the tool result" ,
4799+ failure : {
4800+ message : "Unauthorized. ",
4801+ codexErrorInfo : "unauthorized" ,
4802+ } ,
4803+ expectedContext : false ,
48014804 } ,
4802- expectedContext : false ,
4803- } ,
4804- ] ) (
4805- "captures the complete mirrored branch through a settled tool-result boundary for a $label" ,
4806- async ( { failure, expectedContext } ) => {
4805+ ] . flatMap ( ( scenario ) =>
4806+ [ false , true ] . map ( ( oversizedHistory ) => ( { scenario, oversizedHistory } ) ) ,
4807+ ) ,
4808+ ) (
4809+ "preserves settled finalization eligibility for a $scenario.label (oversized history: $oversizedHistory)" ,
4810+ async ( { scenario : { failure, expectedContext } , oversizedHistory } ) => {
48074811 const storePath = path . join ( tempDir , "settled-finalization-context.sqlite" ) ;
48084812 const sessionId = "session-settled-finalization-context" ;
48094813 const sessionFile = `agent:main:${ sessionId } ` ;
48104814 const workspaceDir = path . join ( tempDir , "workspace-settled-finalization-context" ) ;
48114815 const harness = createStartedThreadHarness ( ) ;
48124816 const params = createParams ( sessionFile , workspaceDir ) ;
48134817 await attachSqliteSessionTarget ( params , storePath , sessionId ) ;
4818+ if ( oversizedHistory ) {
4819+ for ( let index = 0 ; index < 201 ; index += 1 ) {
4820+ await appendSqliteHistoryMessage (
4821+ params ,
4822+ userMessage ( `Prior message ${ index } ` , index + 1 ) ,
4823+ ) ;
4824+ }
4825+ }
48144826 params . prompt = "Send the update to Alice." ;
48154827 const run = runCodexAppServerAttempt ( params ) ;
48164828 await harness . waitForMethod ( "turn/start" ) ;
4829+ const emptyAssistant = { type : "agentMessage" , id : "empty-assistant" , text : "" } ;
4830+ await harness . notify ( itemNotification ( "item/started" , emptyAssistant ) ) ;
4831+ await harness . notify ( itemNotification ( "item/completed" , emptyAssistant ) ) ;
48174832 await harness . notify (
48184833 itemNotification ( "item/started" , {
48194834 type : "commandExecution" ,
@@ -4852,7 +4867,20 @@ describe("runCodexAppServerAttempt", () => {
48524867 const result = await run ;
48534868 expect ( Boolean ( readAttemptTerminal ( result ) . promptError ) ) . toBe ( Boolean ( failure ) ) ;
48544869 expect ( Boolean ( result . settledTurnFinalizationContext ) ) . toBe ( expectedContext ) ;
4855- if ( result . settledTurnFinalizationContext ) {
4870+ expect ( result . currentAttemptAssistant ) . toBeDefined ( ) ;
4871+ expect ( result . replayMetadata ) . toMatchObject ( {
4872+ hadPotentialSideEffects : true ,
4873+ replaySafe : false ,
4874+ } ) ;
4875+ expect ( result . itemLifecycle ) . toMatchObject ( {
4876+ startedCount : 2 ,
4877+ completedCount : 2 ,
4878+ activeCount : 0 ,
4879+ } ) ;
4880+ if ( expectedContext && oversizedHistory ) {
4881+ expect ( result . settledTurnFinalizationContext ) . toEqual ( { source : "unavailable" } ) ;
4882+ expect ( Object . isFrozen ( result . settledTurnFinalizationContext ) ) . toBe ( true ) ;
4883+ } else if ( result . settledTurnFinalizationContext ) {
48564884 expect ( result . settledTurnFinalizationContext ) . toMatchObject ( {
48574885 source : "harness" ,
48584886 data : [
0 commit comments