@@ -1016,115 +1016,119 @@ it.effect("fails the run when its ownership check cannot be read before calling
10161016 } ) ,
10171017) ;
10181018
1019- it . effect ( "preserves native command routing before marking cross-thread message origins" , ( ) =>
1020- Effect . gen ( function * ( ) {
1021- const runExecution = yield * RunExecutionService . RunExecutionServiceV2 ;
1022- const calls : Array < string > = [ ] ;
1023- const attachment = ChatFileAttachment . make ( {
1024- type : "file" ,
1025- id : ChatAttachmentId . make ( "compact-file-12345678-1234-1234-1234-123456789abc" ) ,
1026- name : "notes.txt" ,
1027- mimeType : "text/plain" ,
1028- sizeBytes : 1 ,
1029- } ) ;
1030- const cases = [
1031- { text : " /compact " , attachments : [ ] , expected : "compact" } ,
1032- { text : "/compact" , attachments : [ attachment ] , expected : "prompt" } ,
1033- { text : "/goal finish the work" , attachments : [ ] , expected : "goal" } ,
1034- { text : "/goal finish the work" , attachments : [ attachment ] , expected : "prompt" } ,
1035- { text : "Continue the work" , attachments : [ ] , expected : "prompt" } ,
1036- ] . flatMap ( ( testCase ) =>
1037- [
1038- { createdBy : "user" , senderThreadId : ThreadId . make ( "thread:sender" ) } ,
1039- { createdBy : "agent" , senderThreadId : ThreadId . make ( "thread:sender" ) } ,
1040- { createdBy : "agent" } ,
1041- ] . map ( ( origin ) => ( { ...testCase , ...origin } ) ) ,
1042- ) ;
1043- for ( const [ index , testCase ] of cases . entries ( ) ) {
1044- const prompts : Array < ProviderAdapter . ProviderAdapterV2TurnInput > = [ ] ;
1045- const threadId = ThreadId . make ( `thread:compact-routing:${ index } ` ) ;
1046- const attemptId = RunAttemptId . make ( `attempt:compact-routing:${ index } ` ) ;
1047- yield * runExecution . startRootRun ( {
1048- commandId : CommandId . make ( `command:compact-routing:${ index } ` ) ,
1049- appThread : rootAppThread ( threadId ) ,
1050- providerSessionId : ProviderSessionId . make ( `session:compact-routing:${ index } ` ) ,
1051- session : {
1052- driver,
1053- events : Stream . never ,
1054- startTurn : ( input : ProviderAdapter . ProviderAdapterV2TurnInput ) =>
1055- Effect . sync ( ( ) => {
1056- prompts . push ( input ) ;
1057- calls . push ( testCase . expected === "goal" ? "goal" : "prompt" ) ;
1058- } ) ,
1059- compactThread : ( input : ProviderAdapter . ProviderAdapterV2TurnInput ) =>
1060- Effect . sync ( ( ) => {
1061- assert . equal ( input . message . text , testCase . text ) ;
1062- calls . push ( "compact" ) ;
1063- } ) ,
1064- } as unknown as ProviderAdapter . ProviderAdapterV2SessionRuntime ,
1065- run : {
1066- id : RunId . make ( `run:compact-routing:${ index } ` ) ,
1067- threadId,
1068- ordinal : 1 ,
1069- providerInstanceId : ProviderInstanceId . make ( "codex" ) ,
1070- } as OrchestrationV2Run ,
1071- rootNode : {
1072- id : NodeId . make ( `node:compact-routing:${ index } ` ) ,
1073- } as OrchestrationV2ExecutionNode ,
1074- checkpointScope : {
1075- id : CheckpointScopeId . make ( `checkpoint:compact-routing:${ index } ` ) ,
1076- } as OrchestrationV2CheckpointScope ,
1077- providerThread : {
1078- id : ProviderThreadId . make ( `provider-thread:compact-routing:${ index } ` ) ,
1079- driver,
1080- } as OrchestrationV2ProviderThread ,
1081- attempt : { id : attemptId , providerTurnId : null } as OrchestrationV2RunAttempt ,
1082- attemptId,
1083- providerTurnOrdinal : 1 ,
1084- message : {
1085- messageId : MessageId . make ( `message:compact-routing:${ index } ` ) ,
1086- text : testCase . text ,
1087- attachments : testCase . attachments ,
1088- createdBy : testCase . createdBy as "user" | "agent" ,
1089- creationSource : "web" ,
1090- ...( testCase . senderThreadId === undefined
1091- ? { }
1092- : { senderThreadId : testCase . senderThreadId } ) ,
1093- } ,
1094- modelSelection : { instanceId : ProviderInstanceId . make ( "codex" ) , model : "gpt-5.4" } ,
1095- runtimePolicy : {
1096- runtimeMode : "full-access" ,
1097- interactionMode : "default" ,
1098- cwd : process . cwd ( ) ,
1099- approvalPolicy : "never" ,
1100- sandboxPolicy : {
1101- type : "readOnly" ,
1102- access : { type : "fullAccess" } ,
1103- networkAccess : false ,
1104- } ,
1105- } ,
1019+ it . effect (
1020+ "dispatches only attachment-free compact commands through the native compaction path" ,
1021+ ( ) =>
1022+ Effect . gen ( function * ( ) {
1023+ const runExecution = yield * RunExecutionService . RunExecutionServiceV2 ;
1024+ const calls : Array < string > = [ ] ;
1025+ const attachment = ChatFileAttachment . make ( {
1026+ type : "file" ,
1027+ id : ChatAttachmentId . make ( "compact-file-12345678-1234-1234-1234-123456789abc" ) ,
1028+ name : "notes.txt" ,
1029+ mimeType : "text/plain" ,
1030+ sizeBytes : 1 ,
11061031 } ) ;
1107- const prompt = prompts [ 0 ] ;
1108- if ( prompt !== undefined ) {
1109- if (
1110- testCase . expected !== "goal" &&
1111- testCase . createdBy === "agent" &&
1112- testCase . senderThreadId !== undefined
1113- ) {
1114- assert . include ( prompt . message . text , 'thread "thread:sender"' ) ;
1115- assert . include ( prompt . message . text , "not a message from the human user" ) ;
1116- assert . isTrue ( prompt . message . text . endsWith ( `\n\n${ testCase . text } ` ) ) ;
1117- } else {
1118- assert . equal ( prompt . message . text , testCase . text ) ;
1032+ const cases = [
1033+ { text : " /compact " , attachments : [ ] , expected : "compact" } ,
1034+ { text : "/compact" , attachments : [ attachment ] , expected : "prompt" } ,
1035+ { text : "/goal finish the work" , attachments : [ ] , expected : "goal" } ,
1036+ { text : "/goal finish the work" , attachments : [ attachment ] , expected : "prompt" } ,
1037+ { text : "Continue the work" , attachments : [ ] , expected : "prompt" } ,
1038+ ] . flatMap ( ( testCase ) =>
1039+ (
1040+ [
1041+ { createdBy : "user" , senderThreadId : ThreadId . make ( "thread:sender" ) } ,
1042+ { createdBy : "agent" , senderThreadId : ThreadId . make ( "thread:sender" ) } ,
1043+ { createdBy : "agent" , senderThreadId : undefined } ,
1044+ ] as const
1045+ ) . map ( ( origin ) => ( { ...testCase , ...origin } ) ) ,
1046+ ) ;
1047+ for ( const [ index , testCase ] of cases . entries ( ) ) {
1048+ const prompts : Array < ProviderAdapter . ProviderAdapterV2TurnInput > = [ ] ;
1049+ const threadId = ThreadId . make ( `thread:compact-routing:${ index } ` ) ;
1050+ const attemptId = RunAttemptId . make ( `attempt:compact-routing:${ index } ` ) ;
1051+ yield * runExecution . startRootRun ( {
1052+ commandId : CommandId . make ( `command:compact-routing:${ index } ` ) ,
1053+ appThread : rootAppThread ( threadId ) ,
1054+ providerSessionId : ProviderSessionId . make ( `session:compact-routing:${ index } ` ) ,
1055+ session : {
1056+ driver,
1057+ events : Stream . never ,
1058+ startTurn : ( input : ProviderAdapter . ProviderAdapterV2TurnInput ) =>
1059+ Effect . sync ( ( ) => {
1060+ prompts . push ( input ) ;
1061+ calls . push ( "prompt" ) ;
1062+ } ) ,
1063+ compactThread : ( input : ProviderAdapter . ProviderAdapterV2TurnInput ) =>
1064+ Effect . sync ( ( ) => {
1065+ assert . equal ( input . message . text , testCase . text ) ;
1066+ calls . push ( "compact" ) ;
1067+ } ) ,
1068+ } as unknown as ProviderAdapter . ProviderAdapterV2SessionRuntime ,
1069+ run : {
1070+ id : RunId . make ( `run:compact-routing:${ index } ` ) ,
1071+ threadId,
1072+ ordinal : 1 ,
1073+ providerInstanceId : ProviderInstanceId . make ( "codex" ) ,
1074+ } as OrchestrationV2Run ,
1075+ rootNode : {
1076+ id : NodeId . make ( `node:compact-routing:${ index } ` ) ,
1077+ } as OrchestrationV2ExecutionNode ,
1078+ checkpointScope : {
1079+ id : CheckpointScopeId . make ( `checkpoint:compact-routing:${ index } ` ) ,
1080+ } as OrchestrationV2CheckpointScope ,
1081+ providerThread : {
1082+ id : ProviderThreadId . make ( `provider-thread:compact-routing:${ index } ` ) ,
1083+ driver,
1084+ } as OrchestrationV2ProviderThread ,
1085+ attempt : { id : attemptId , providerTurnId : null } as OrchestrationV2RunAttempt ,
1086+ attemptId,
1087+ providerTurnOrdinal : 1 ,
1088+ message : {
1089+ messageId : MessageId . make ( `message:compact-routing:${ index } ` ) ,
1090+ text : testCase . text ,
1091+ attachments : testCase . attachments ,
1092+ createdBy : testCase . createdBy ,
1093+ creationSource : "web" ,
1094+ ...( testCase . senderThreadId === undefined
1095+ ? { }
1096+ : { senderThreadId : testCase . senderThreadId } ) ,
1097+ } ,
1098+ modelSelection : { instanceId : ProviderInstanceId . make ( "codex" ) , model : "gpt-5.4" } ,
1099+ runtimePolicy : {
1100+ runtimeMode : "full-access" ,
1101+ interactionMode : "default" ,
1102+ cwd : process . cwd ( ) ,
1103+ approvalPolicy : "never" ,
1104+ sandboxPolicy : {
1105+ type : "readOnly" ,
1106+ access : { type : "fullAccess" } ,
1107+ networkAccess : false ,
1108+ } ,
1109+ } ,
1110+ } ) ;
1111+ const prompt = prompts [ 0 ] ;
1112+ if ( prompt !== undefined ) {
1113+ if (
1114+ testCase . expected !== "goal" &&
1115+ testCase . createdBy === "agent" &&
1116+ testCase . senderThreadId !== undefined
1117+ ) {
1118+ assert . include ( prompt . message . text , 'thread "thread:sender"' ) ;
1119+ assert . include ( prompt . message . text , "not a message from the human user" ) ;
1120+ assert . isTrue ( prompt . message . text . endsWith ( `\n\n${ testCase . text } ` ) ) ;
1121+ } else {
1122+ assert . equal ( prompt . message . text , testCase . text ) ;
1123+ }
1124+ assert . deepEqual ( prompt . message . attachments , testCase . attachments ) ;
11191125 }
1120- assert . deepEqual ( prompt . message . attachments , testCase . attachments ) ;
11211126 }
1122- }
1123- assert . deepEqual (
1124- calls ,
1125- cases . map ( ( testCase ) => testCase . expected ) ,
1126- ) ;
1127- } ) . pipe ( Effect . provide ( layerRunExecutionTest ) ) ,
1127+ assert . deepEqual (
1128+ calls ,
1129+ cases . map ( ( testCase ) => ( testCase . expected === "compact" ? "compact" : "prompt" ) ) ,
1130+ ) ;
1131+ } ) . pipe ( Effect . provide ( layerRunExecutionTest ) ) ,
11281132) ;
11291133
11301134it . effect ( "starts the provider when checkpoint baseline capture fails" , ( ) =>
0 commit comments