@@ -32,6 +32,7 @@ import { assert, describe, it } from "@effect/vitest";
3232import { HostProcessEnvironment , HostProcessPlatform } from "@t3tools/shared/hostProcess" ;
3333import { SpawnExecutableResolution } from "@t3tools/shared/shell" ;
3434import * as CodexClient from "effect-codex-app-server/client" ;
35+ import * as CodexError from "effect-codex-app-server/errors" ;
3536import * as CodexReplay from "effect-codex-app-server/replay" ;
3637import * as DateTime from "effect/DateTime" ;
3738import * as Deferred from "effect/Deferred" ;
@@ -1870,7 +1871,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
18701871 transcript : CodexReplay . CodexAppServerReplayTranscript ,
18711872 onEvent : ( event : ProviderAdapterV2Event ) => Effect . Effect < unknown > = ( ) => Effect . void ,
18721873 onRequest : ( method : string , params : unknown ) => Effect . Effect < void > = ( ) => Effect . void ,
1873- readChildMetadata ?: ( threadId : string ) => Effect . Effect < unknown > ,
1874+ readChildMetadata ?: Parameters < typeof withCodexReplayChildMetadata > [ 2 ] ,
18741875 ) =>
18751876 Effect . gen ( function * ( ) {
18761877 const fileSystem = yield * FileSystem . FileSystem ;
@@ -6708,6 +6709,8 @@ describe("CodexAdapterV2 post-settle continuation", () => {
67086709 } ) ;
67096710
67106711 it . effect . each ( [
6712+ { name : "current Codex Sol" , model : "gpt-6-sol" } ,
6713+ { name : "current Codex wrong child" , model : null } ,
67116714 { name : "Sol" , model : "gpt-5.6-sol" } ,
67126715 { name : "Fable" , model : "gpt-5.6-fable" } ,
67136716 { name : "Astra" , model : "gpt-6-astra" } ,
@@ -6719,6 +6722,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
67196722 Effect . gen ( function * ( ) {
67206723 const metadataRead = yield * Deferred . make < void > ( ) ;
67216724 const modelReported = yield * Deferred . make < void > ( ) ;
6725+ let metadataRequests = 0 ;
67226726 const harness = yield * makeCodexReplayHarness (
67236727 resumeSubagentTranscript ,
67246728 ( event ) =>
@@ -6727,14 +6731,22 @@ describe("CodexAdapterV2 post-settle continuation", () => {
67276731 : Effect . void ,
67286732 undefined ,
67296733 ( threadId ) => {
6734+ metadataRequests ++ ;
67306735 assert . equal ( threadId , RESUME_CHILD_THREAD ) ;
67316736 return Deferred . succeed ( metadataRead , undefined ) . pipe (
67326737 Effect . as (
67336738 name === "invalid"
67346739 ? { }
67356740 : {
6736- thread : { id : name === "wrong child" ? "other-child" : threadId } ,
6737- model : name === "wrong child" ? "gpt-5.6-sol" : model ,
6741+ thread : {
6742+ id : name . includes ( "wrong child" ) ? "other-child" : threadId ,
6743+ ...( name . startsWith ( "current Codex" ) ? { model : "gpt-6-sol" } : { } ) ,
6744+ } ,
6745+ model : name . startsWith ( "current Codex" )
6746+ ? null
6747+ : name === "wrong child"
6748+ ? "gpt-5.6-sol"
6749+ : model ,
67386750 } ,
67396751 ) ,
67406752 ) ;
@@ -6754,10 +6766,68 @@ describe("CodexAdapterV2 post-settle continuation", () => {
67546766 yield * TestClock . adjust ( "100 millis" ) ;
67556767 yield * harness . firstTerminal ;
67566768 assert . equal ( harness . subagentUpdates ( ) . at ( - 1 ) ?. subagent . model , model ) ;
6769+ assert . equal ( metadataRequests , name === "current Codex Sol" ? 1 : 2 ) ;
67576770 } ) . pipe ( Effect . provide ( Layer . merge ( IdAllocator . layer , NodeServices . layer ) ) ) ,
67586771 ) ,
67596772 ) ;
67606773
6774+ it . effect . each ( [ "failed" , "malformed" , "wrong child" , "blank model" ] as const ) (
6775+ "resumes child metadata after a %s read" ,
6776+ ( readResult ) =>
6777+ Effect . scoped (
6778+ Effect . gen ( function * ( ) {
6779+ const modelReported = yield * Deferred . make < void > ( ) ;
6780+ const model = "gpt-6-sol" ;
6781+ const metadataRequests : Array < string > = [ ] ;
6782+ const harness = yield * makeCodexReplayHarness (
6783+ resumeSubagentTranscript ,
6784+ ( event ) =>
6785+ event . type === "subagent.updated" && event . subagent . model === model
6786+ ? Deferred . succeed ( modelReported , undefined )
6787+ : Effect . void ,
6788+ undefined ,
6789+ ( threadId , method ) => {
6790+ assert . equal ( threadId , RESUME_CHILD_THREAD ) ;
6791+ metadataRequests . push ( method ) ;
6792+ if ( method === "thread/resume" ) {
6793+ return Effect . succeed ( { thread : { id : threadId } , model } ) ;
6794+ }
6795+ switch ( readResult ) {
6796+ case "failed" :
6797+ return Effect . fail (
6798+ new CodexError . CodexAppServerRequestError ( {
6799+ code : - 32000 ,
6800+ errorMessage : "Child metadata unavailable" ,
6801+ method,
6802+ } ) ,
6803+ ) ;
6804+ case "malformed" :
6805+ return Effect . succeed ( { } ) ;
6806+ case "wrong child" :
6807+ return Effect . succeed ( { thread : { id : "other-child" , model : "gpt-6-astra" } } ) ;
6808+ case "blank model" :
6809+ return Effect . succeed ( { thread : { id : threadId , model : " \t " } } ) ;
6810+ }
6811+ } ,
6812+ ) ;
6813+ yield * harness . runtime . startTurn (
6814+ makeCodexTestTurnInput ( {
6815+ threadId : harness . threadId ,
6816+ providerThread : harness . providerThread ,
6817+ now : yield * DateTime . now ,
6818+ attemptId : RunAttemptId . make ( "attempt-child-model-fallback" ) ,
6819+ text : RESUME_PROMPT ,
6820+ } ) ,
6821+ ) ;
6822+ yield * Deferred . await ( modelReported ) ;
6823+ yield * TestClock . adjust ( "100 millis" ) ;
6824+ yield * harness . firstTerminal ;
6825+ assert . equal ( harness . subagentUpdates ( ) . at ( - 1 ) ?. subagent . model , model ) ;
6826+ assert . deepEqual ( metadataRequests , [ "thread/read" , "thread/resume" ] ) ;
6827+ } ) . pipe ( Effect . provide ( Layer . merge ( IdAllocator . layer , NodeServices . layer ) ) ) ,
6828+ ) ,
6829+ ) ;
6830+
67616831 it . effect . each ( [ "thread/settings/updated" , "model/rerouted" ] as const ) (
67626832 "keeps %s child metadata when an older lookup finishes later" ,
67636833 ( method ) =>
0 commit comments