@@ -723,49 +723,6 @@ describe("CodexAdapterV2 runtime policy", () => {
723723} ) ;
724724
725725describe ( "CodexAdapterV2 process spawning" , ( ) => {
726- it ( "injects cwd, model, and MCP authorization into thread-scoped params" , ( ) => {
727- const threadId = ThreadId . make ( "thread-codex-mcp" ) ;
728- const mcpSession = {
729- environmentId : EnvironmentId . make ( "environment-codex-mcp" ) ,
730- threadId,
731- providerSessionId : "mcp-session-codex" ,
732- providerInstanceId : ProviderInstanceId . make ( "codex" ) ,
733- endpoint : "http://127.0.0.1:43123/mcp" ,
734- authorizationHeader : "Bearer secret-codex-token" ,
735- browserToolsAvailable : true ,
736- } ;
737-
738- assert . deepEqual (
739- CodexAdapterV2 . codexThreadRuntimeParams ( {
740- mcpSession,
741- modelSelection : { model : "gpt-5.4" } ,
742- runtimePolicy : {
743- runtimeMode : "full-access" ,
744- interactionMode : "default" ,
745- cwd : "/workspace/thread-codex-mcp" ,
746- } ,
747- } ) ,
748- {
749- cwd : "/workspace/thread-codex-mcp" ,
750- model : "gpt-5.4" ,
751- config : {
752- "tools.update_plan.enabled" : true ,
753- // Codex waits up to 10 s, not 1 s, for MCP servers before the first request (#13437).
754- mcp_optional_startup_grace_ms : 10_000 ,
755- mcp_servers : {
756- "t3-code" : {
757- url : "http://127.0.0.1:43123/mcp" ,
758- tool_timeout_sec : 3_900 ,
759- http_headers : {
760- Authorization : "Bearer secret-codex-token" ,
761- } ,
762- } ,
763- } ,
764- } ,
765- } ,
766- ) ;
767- } ) ;
768-
769726 it . effect ( "resolves Windows command shims through the shared spawn policy" , ( ) =>
770727 Effect . gen ( function * ( ) {
771728 const command = yield * CodexAdapterV2 . makeCodexAppServerSpawnCommand ( {
@@ -2275,6 +2232,123 @@ describe("CodexAdapterV2 post-settle continuation", () => {
22752232 ) ,
22762233 ) ;
22772234
2235+ it . effect ( "adds the session MCP server without replacing launch-argument servers" , ( ) =>
2236+ Effect . gen ( function * ( ) {
2237+ const scenario = "launch-mcp-servers" ;
2238+ yield * ( yield * McpProviderSessions . McpProviderSessions ) . set ( {
2239+ environmentId : EnvironmentId . make ( "environment-codex-mcp" ) ,
2240+ threadId : ThreadId . make ( `thread-${ scenario } ` ) ,
2241+ providerSessionId : `provider-session-${ scenario } ` ,
2242+ providerInstanceId : ProviderInstanceId . make ( "codex" ) ,
2243+ endpoint : "http://127.0.0.1:43123/mcp" ,
2244+ authorizationHeader : "Bearer secret-codex-token" ,
2245+ browserToolsAvailable : true ,
2246+ } ) ;
2247+ const requests : Array < unknown > = [ ] ;
2248+ yield * makeCodexReplayHarness (
2249+ makeCodexReplayTranscript ( {
2250+ scenario,
2251+ entries : codexReplayPreamble ( {
2252+ nativeThreadId : "launch-mcp-thread" ,
2253+ nativeTurnId : "unused" ,
2254+ prompt : "unused" ,
2255+ } ) . slice ( 0 , 5 ) ,
2256+ } ) ,
2257+ ( ) => Effect . void ,
2258+ ( method , params ) =>
2259+ Effect . sync ( ( ) => {
2260+ if ( method === "thread/start" ) requests . push ( params ) ;
2261+ } ) ,
2262+ ) ;
2263+ assert . deepEqual ( requests , [
2264+ {
2265+ cwd : "/workspace" ,
2266+ model : "gpt-5.4" ,
2267+ config : {
2268+ "tools.update_plan.enabled" : true ,
2269+ mcp_optional_startup_grace_ms : 10_000 ,
2270+ "mcp_servers.t3-code" : {
2271+ url : "http://127.0.0.1:43123/mcp" ,
2272+ tool_timeout_sec : 3_900 ,
2273+ http_headers : { Authorization : "Bearer secret-codex-token" } ,
2274+ } ,
2275+ } ,
2276+ } ,
2277+ ] ) ;
2278+ } ) . pipe (
2279+ Effect . scoped ,
2280+ Effect . provide (
2281+ Layer . mergeAll ( IdAllocator . layer , McpProviderSessions . layer , NodeServices . layer ) ,
2282+ ) ,
2283+ ) ,
2284+ ) ;
2285+
2286+ it . effect ( "replays historical and dotted MCP config while enforcing other thread config" , ( ) =>
2287+ Effect . gen ( function * ( ) {
2288+ const recordedServer = {
2289+ url : "http://127.0.0.1:41000/mcp" ,
2290+ http_headers : { Authorization : "Bearer recorded-token" } ,
2291+ } ;
2292+ const currentConfig = {
2293+ "tools.update_plan.enabled" : true ,
2294+ "mcp_servers.t3-code" : {
2295+ url : "http://127.0.0.1:42000/mcp" ,
2296+ http_headers : { Authorization : "Bearer current-token" } ,
2297+ } ,
2298+ "mcp_servers.extra.command" : "cat" ,
2299+ } ;
2300+ for ( const recordedMcp of [
2301+ { mcp_servers : { "t3-code" : recordedServer } } ,
2302+ { "mcp_servers.t3-code" : recordedServer , "mcp_servers.extra.command" : "echo" } ,
2303+ ] ) {
2304+ const entries = codexReplayPreamble ( {
2305+ nativeThreadId : "replayed-mcp-thread" ,
2306+ nativeTurnId : "unused" ,
2307+ prompt : "unused" ,
2308+ } )
2309+ . slice ( 3 , 5 )
2310+ . map ( ( entry ) => withReplayRequestId ( entry , 1 ) ) ;
2311+ entries [ 0 ] = {
2312+ type : "expect_outbound" ,
2313+ frame : {
2314+ id : 1 ,
2315+ method : "thread/start" ,
2316+ params : { config : { "tools.update_plan.enabled" : true , ...recordedMcp } } ,
2317+ } ,
2318+ } ;
2319+ entries . push ( {
2320+ ...entries [ 0 ] ,
2321+ frame : {
2322+ id : 2 ,
2323+ method : "thread/start" ,
2324+ params : { config : { "tools.update_plan.enabled" : true , ...recordedMcp } } ,
2325+ } ,
2326+ } ) ;
2327+ const driver = yield * CodexReplay . makeReplayDriver (
2328+ makeCodexReplayTranscript ( {
2329+ scenario : "mcp-config-normalization" ,
2330+ entries,
2331+ } ) ,
2332+ ) ;
2333+ yield * Effect . gen ( function * ( ) {
2334+ const client = yield * CodexClient . CodexAppServerClient ;
2335+ const response = yield * client . request ( "thread/start" , { config : currentConfig } ) ;
2336+ assert . equal ( response . thread . id , "replayed-mcp-thread" ) ;
2337+ assert . isNull ( ( yield * Ref . get ( driver . state ) ) . failure ) ;
2338+ yield * client
2339+ . request ( "thread/start" , {
2340+ config : { ...currentConfig , "tools.update_plan.enabled" : false } ,
2341+ } )
2342+ . pipe ( Effect . flip ) ;
2343+ assert . instanceOf (
2344+ ( yield * Ref . get ( driver . state ) ) . failure ,
2345+ CodexReplay . CodexAppServerReplayFrameMismatchError ,
2346+ ) ;
2347+ } ) . pipe ( Effect . provide ( CodexReplay . layerReplayWithDriver ( driver ) ) ) ;
2348+ }
2349+ } ) . pipe ( Effect . scoped ) ,
2350+ ) ;
2351+
22782352 it . effect ( "identifies sessions to Codex with the same client info as main" , ( ) =>
22792353 Effect . gen ( function * ( ) {
22802354 const transcript = makeCodexReplayTranscript ( {
0 commit comments