@@ -37,6 +37,8 @@ import * as Queue from "effect/Queue";
3737import * as Ref from "effect/Ref" ;
3838import * as Schema from "effect/Schema" ;
3939import * as Stream from "effect/Stream" ;
40+ import * as TestClock from "effect/testing/TestClock" ;
41+ import * as ProviderSessionManager from "../orchestration-v2/ProviderSessionManager.ts" ;
4042
4143import { CodexProviderCapabilitiesV2 } from "../orchestration-v2/Adapters/CodexAdapterV2.ts" ;
4244import * as CommandReceiptStore from "../orchestration-v2/CommandReceiptStore.ts" ;
@@ -3655,6 +3657,94 @@ describe("OrchestratorMcpService thread lookup", () => {
36553657 } ) ,
36563658 ) ;
36573659
3660+ it . effect . each ( [
3661+ { name : "legacy client" , returnOnInput : undefined , agent : false , pending : false } ,
3662+ { name : "updated client" , returnOnInput : true , agent : false , pending : true } ,
3663+ { name : "thread caller" , returnOnInput : undefined , agent : true , pending : true } ,
3664+ { name : "terminal-only thread caller" , returnOnInput : false , agent : true , pending : false } ,
3665+ ] ) ( "preserves wait semantics for $name" , ( scenario ) =>
3666+ Effect . gen ( function * ( ) {
3667+ const runId = RunId . make ( "run:compat-wait" ) ;
3668+ const projection = {
3669+ ...idleThreadProjection ( launched ) ,
3670+ runs : [ { id : runId , ordinal : 1 , status : "running" } ] ,
3671+ nodes : [ { id : "node:compat-wait" , runId } ] ,
3672+ runtimeRequests : [
3673+ {
3674+ id : "request:compat-wait" ,
3675+ nodeId : "node:compat-wait" ,
3676+ kind : "command" ,
3677+ status : "pending" ,
3678+ responseCapability : { type : "live" } ,
3679+ createdAt : DateTime . makeUnsafe ( 0 ) ,
3680+ } ,
3681+ ] ,
3682+ } as unknown as OrchestrationV2ThreadProjection ;
3683+ const management = yield * ThreadManagementService . ThreadManagementService . pipe (
3684+ Effect . provide (
3685+ ThreadManagementService . layer . pipe (
3686+ Layer . provide (
3687+ Layer . mergeAll (
3688+ Layer . mock ( ProviderSessionManager . ProviderSessionManagerV2 ) ( { } ) ,
3689+ Layer . mock ( CommandReceiptStore . CommandReceiptStoreV2 ) ( { } ) ,
3690+ ServerSettings . layerTest ( ) ,
3691+ Layer . mock ( Orchestrator . OrchestratorV2 ) ( {
3692+ getThreadEventSequence : ( ) => Effect . succeed ( 0 ) ,
3693+ getThreadRecords : ( ) => Effect . succeed ( projection ) ,
3694+ streamStoredEventsFrom : ( ) => Stream . never ,
3695+ } ) ,
3696+ ) ,
3697+ ) ,
3698+ ) ,
3699+ ) ,
3700+ ) ;
3701+ const sent = yield * Ref . make ( 0 ) ;
3702+ yield * Effect . gen ( function * ( ) {
3703+ const mcp = yield * OrchestratorMcpService . OrchestratorMcpService ;
3704+ const waiting = yield * mcp
3705+ . waitForThread (
3706+ {
3707+ ...client ,
3708+ ...( scenario . agent
3709+ ? {
3710+ thread : {
3711+ threadId : launched . id ,
3712+ providerSessionId : "session:compat-wait" ,
3713+ providerInstanceId : ProviderInstanceId . make ( "codex" ) ,
3714+ } ,
3715+ }
3716+ : { } ) ,
3717+ } ,
3718+ {
3719+ threadId : launched . id ,
3720+ runId,
3721+ timeoutMs : 60_000 ,
3722+ ...( scenario . returnOnInput === undefined
3723+ ? { }
3724+ : { returnOnInput : scenario . returnOnInput } ) ,
3725+ } ,
3726+ )
3727+ . pipe ( Effect . forkChild ) ;
3728+ yield * TestClock . adjust ( "1 minute" ) ;
3729+ const result = yield * Fiber . join ( waiting ) ;
3730+ assert . equal ( result . timedOut , ! scenario . pending ) ;
3731+ assert . equal ( result . status , "running" ) ;
3732+ assert . equal (
3733+ result . pendingApproval ?. requestId ?? null ,
3734+ scenario . pending ? "request:compat-wait" : null ,
3735+ ) ;
3736+ } ) . pipe (
3737+ Effect . provide (
3738+ service ( [ launched ] , sent , {
3739+ getThreadRecords : ( ) => Effect . succeed ( projection ) ,
3740+ getProjectThreadRecords : ( ) => Effect . succeed ( projection ) ,
3741+ waitForThread : management . waitForThread ,
3742+ } ) ,
3743+ ) ,
3744+ ) ;
3745+ } ) ,
3746+ ) ;
3747+
36583748 it . effect ( "waits on the caller's own thread without a separate shell lookup" , ( ) =>
36593749 Effect . gen ( function * ( ) {
36603750 const sent = yield * Ref . make ( 0 ) ;
0 commit comments