@@ -101,6 +101,7 @@ import * as Stream from "effect/Stream";
101101import { ChildProcess , ChildProcessSpawner } from "effect/process" ;
102102
103103import { resolveAttachmentPath , resolveAttachmentPathById } from "../../attachmentStore.ts" ;
104+ import * as PortScanner from "../../preview/PortScanner.ts" ;
104105import { getCodexServiceTierOptionValue } from "../../codexModelOptions.ts" ;
105106import { ServerConfig } from "../../config.ts" ;
106107import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion" ;
@@ -1334,6 +1335,7 @@ export const CODEX_THREAD_CONFIG = {
13341335const CODEX_T3_MCP_TOOL_TIMEOUT_SEC = 65 * 60 ;
13351336
13361337function codexThreadRuntimeParams ( input : {
1338+ readonly threadId : ThreadId | null ;
13371339 readonly mcpSession : McpProviderSession . McpProviderSessionConfig | undefined ;
13381340 readonly modelSelection ?: { readonly model : string } ;
13391341 readonly runtimePolicy ?: ProviderAdapter . ProviderAdapterV2RuntimePolicy ;
@@ -1348,6 +1350,10 @@ function codexThreadRuntimeParams(input: {
13481350 ...( input . modelSelection === undefined ? { } : { model : input . modelSelection . model } ) ,
13491351 config : {
13501352 ...CODEX_THREAD_CONFIG ,
1353+ // One app-server serves many threads, so the id goes in per-thread shell config, not its env.
1354+ ...( input . threadId === null
1355+ ? { }
1356+ : { [ `shell_environment_policy.set.${ PortScanner . AGENT_THREAD_ENV } ` ] : input . threadId } ) ,
13511357 ...( mcpSession === undefined
13521358 ? { }
13531359 : {
@@ -6957,6 +6963,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
69576963 client . request (
69586964 "thread/start" ,
69596965 codexThreadRuntimeParams ( {
6966+ threadId : threadInput . threadId ,
69606967 mcpSession,
69616968 modelSelection : threadInput . modelSelection ,
69626969 runtimePolicy : threadInput . runtimePolicy ,
@@ -6985,13 +6992,13 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
69856992 resumeThread : Effect . fn ( "CodexAdapterV2.resumeThread" ) (
69866993 function * ( threadInput ) {
69876994 const nativeThreadId = yield * getNativeThreadId ( threadInput . providerThread ) ;
6995+ const appThreadId = threadInput . threadId ?? threadInput . providerThread . appThreadId ;
69886996 const resume = client . raw . request ( "thread/resume" , {
69896997 threadId : nativeThreadId ,
69906998 excludeTurns : true ,
69916999 ...codexThreadRuntimeParams ( {
6992- mcpSession : yield * readMcpSession (
6993- threadInput . threadId ?? threadInput . providerThread . appThreadId ,
6994- ) ,
7000+ threadId : appThreadId ,
7001+ mcpSession : yield * readMcpSession ( appThreadId ) ,
69957002 ...( threadInput . modelSelection === undefined
69967003 ? { }
69977004 : { modelSelection : threadInput . modelSelection } ) ,
@@ -7776,6 +7783,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
77767783 threadId,
77777784 excludeTurns : true ,
77787785 ...codexThreadRuntimeParams ( {
7786+ threadId : threadInput . providerThread . appThreadId ,
77797787 mcpSession : yield * readMcpSession ( threadInput . providerThread . appThreadId ) ,
77807788 modelSelection : input . modelSelection ,
77817789 runtimePolicy : input . runtimePolicy ,
@@ -7828,6 +7836,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
78287836 ? { }
78297837 : { lastTurnId : boundary . lastTurnId } ) ,
78307838 ...codexThreadRuntimeParams ( {
7839+ threadId : threadInput . targetThreadId ,
78317840 mcpSession : yield * mcpSessions . read ( threadInput . targetThreadId ) ,
78327841 ...( threadInput . modelSelection === undefined
78337842 ? { }
0 commit comments