@@ -486,6 +486,11 @@ const CODEX_TEST_RUNTIME_POLICY = ProviderAdapter.ProviderAdapterV2RuntimePolicy
486486 interactionMode : "default" ,
487487 cwd : "/workspace" ,
488488} ) ;
489+ const T3_THREAD_ENV_KEY = "shell_environment_policy.set.T3CODE_THREAD_ID" ;
490+ const threadEnvOf = ( params : unknown ) =>
491+ Predicate . hasProperty ( params , "config" ) && Predicate . hasProperty ( params . config , T3_THREAD_ENV_KEY )
492+ ? params . config [ T3_THREAD_ENV_KEY ]
493+ : undefined ;
489494
490495function makeCodexTestAppThread ( input : {
491496 readonly threadId : ThreadId ;
@@ -1180,6 +1185,13 @@ describe("CodexAdapterV2 post-settle continuation", () => {
11801185 onRequest ( method , params ) . pipe (
11811186 Effect . andThen ( client . request ( method , params ) ) ,
11821187 ) ,
1188+ raw : {
1189+ ...client . raw ,
1190+ request : ( method , params ) =>
1191+ onRequest ( method , params ) . pipe (
1192+ Effect . andThen ( client . raw . request ( method , params ) ) ,
1193+ ) ,
1194+ } ,
11831195 } ) satisfies CodexClient . CodexAppServerClient [ "Service" ] ,
11841196 ) ,
11851197 Effect . provide ( context ) ,
@@ -1513,6 +1525,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
15131525 config : {
15141526 "tools.update_plan.enabled" : true ,
15151527 mcp_optional_startup_grace_ms : 10_000 ,
1528+ "shell_environment_policy.set.T3CODE_THREAD_ID" : `thread-${ scenario } ` ,
15161529 "mcp_servers.t3-code" : {
15171530 url : "http://127.0.0.1:43123/mcp" ,
15181531 tool_timeout_sec : 3_900 ,
@@ -2508,18 +2521,75 @@ describe("CodexAdapterV2 post-settle continuation", () => {
25082521 label : "thread/resume" ,
25092522 frame : { id : 3 , result : { thread : { id : nativeThreadId , updatedAt : 1782622450 } } } ,
25102523 } ,
2524+ {
2525+ type : "expect_outbound" ,
2526+ label : "thread/resume without an app thread" ,
2527+ frame : {
2528+ id : 4 ,
2529+ method : "thread/resume" ,
2530+ params : {
2531+ threadId : nativeThreadId ,
2532+ excludeTurns : true ,
2533+ config : CodexAdapterV2 . CODEX_THREAD_CONFIG ,
2534+ } ,
2535+ } ,
2536+ } ,
2537+ {
2538+ type : "emit_inbound" ,
2539+ label : "thread/resume without an app thread" ,
2540+ frame : { id : 4 , result : { thread : { id : nativeThreadId , updatedAt : 1782622450 } } } ,
2541+ } ,
2542+ {
2543+ type : "expect_outbound" ,
2544+ label : "thread/resume with an explicit app thread" ,
2545+ frame : {
2546+ id : 5 ,
2547+ method : "thread/resume" ,
2548+ params : {
2549+ threadId : nativeThreadId ,
2550+ excludeTurns : true ,
2551+ config : CodexAdapterV2 . CODEX_THREAD_CONFIG ,
2552+ } ,
2553+ } ,
2554+ } ,
2555+ {
2556+ type : "emit_inbound" ,
2557+ label : "thread/resume with an explicit app thread" ,
2558+ frame : { id : 5 , result : { thread : { id : nativeThreadId , updatedAt : 1782622450 } } } ,
2559+ } ,
25112560 ] ,
25122561 } ) ;
2513- const harness = yield * makeCodexReplayHarness ( transcript ) ;
2562+ const resumeThreadEnvs : Array < unknown > = [ ] ;
2563+ const harness = yield * makeCodexReplayHarness (
2564+ transcript ,
2565+ ( ) => Effect . void ,
2566+ ( method , params ) =>
2567+ Effect . sync ( ( ) => {
2568+ if ( method === "thread/resume" ) resumeThreadEnvs . push ( threadEnvOf ( params ) ) ;
2569+ } ) ,
2570+ ) ;
25142571 const resumed = yield * harness . runtime . resumeThread ( {
25152572 providerThread : harness . providerThread ,
25162573 modelSelection : CODEX_TEST_MODEL_SELECTION ,
25172574 runtimePolicy : CODEX_TEST_RUNTIME_POLICY ,
25182575 } ) ;
2576+ yield * harness . runtime . resumeThread ( {
2577+ providerThread : { ...harness . providerThread , appThreadId : null } ,
2578+ modelSelection : CODEX_TEST_MODEL_SELECTION ,
2579+ runtimePolicy : CODEX_TEST_RUNTIME_POLICY ,
2580+ } ) ;
2581+ const explicitThreadId = ThreadId . make ( `thread-${ scenario } -explicit` ) ;
2582+ yield * harness . runtime . resumeThread ( {
2583+ threadId : explicitThreadId ,
2584+ providerThread : harness . providerThread ,
2585+ modelSelection : CODEX_TEST_MODEL_SELECTION ,
2586+ runtimePolicy : CODEX_TEST_RUNTIME_POLICY ,
2587+ } ) ;
25192588
25202589 assert . equal ( resumed . nativeThreadRef ?. nativeId , nativeThreadId ) ;
25212590 assert . equal ( resumed . status , "idle" ) ;
25222591 assert . equal ( DateTime . toEpochMillis ( resumed . updatedAt ) , 1782622450000 ) ;
2592+ assert . deepEqual ( resumeThreadEnvs , [ harness . threadId , undefined , explicitThreadId ] ) ;
25232593 } ) . pipe (
25242594 Effect . provide (
25252595 Layer . mergeAll ( IdAllocator . layer , McpProviderSessions . layer , NodeServices . layer ) ,
@@ -7489,12 +7559,14 @@ describe("CodexAdapterV2 post-settle continuation", () => {
74897559 ] ,
74907560 } ) ;
74917561 const outbound : Array < string > = [ ] ;
7562+ const forkThreadEnvs : Array < unknown > = [ ] ;
74927563 const harness = yield * makeCodexReplayHarness (
74937564 transcript ,
74947565 ( ) => Effect . void ,
7495- ( method ) =>
7566+ ( method , params ) =>
74967567 Effect . sync ( ( ) => {
74977568 outbound . push ( method ) ;
7569+ if ( method === "thread/fork" ) forkThreadEnvs . push ( threadEnvOf ( params ) ) ;
74987570 } ) ,
74997571 ) ;
75007572 const now = yield * DateTime . now ;
@@ -7524,6 +7596,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
75247596 assert . notEqual ( forkedProviderThread . id , harness . providerThread . id ) ;
75257597 assert . equal ( forkedProviderThread . forkedFrom ?. providerTurnId , firstTurn . id ) ;
75267598 assert . deepEqual ( outbound . slice ( - 2 ) , [ "thread/turns/list" , "thread/revert" ] ) ;
7599+ assert . deepEqual ( forkThreadEnvs , [ "thread-fork-paginated-fallback-target" ] ) ;
75277600 } ) . pipe (
75287601 Effect . scoped ,
75297602 Effect . provide (
0 commit comments