Skip to content

Commit 0c4454c

Browse files
t3dotggclaude
andauthored
perf(server): Codex calls t3_thread_wait directly instead of from Code Mode (#29026)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent d890e5c commit 0c4454c

4 files changed

Lines changed: 41 additions & 19 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,14 @@ describe("CodexAdapterV2 post-settle continuation", () => {
15301530
url: "http://127.0.0.1:43123/mcp",
15311531
tool_timeout_sec: 3_900,
15321532
http_headers: { Authorization: "Bearer secret-codex-token" },
1533+
disabled_tools: ["t3_thread_wait"],
1534+
},
1535+
"mcp_servers.t3code": {
1536+
url: "http://127.0.0.1:43123/mcp",
1537+
tool_timeout_sec: 3_900,
1538+
http_headers: { Authorization: "Bearer secret-codex-token" },
1539+
enabled_tools: ["t3_thread_wait"],
1540+
omit_tools_from: ["code_mode", "deferred"],
15331541
},
15341542
},
15351543
},

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,9 @@ export const CODEX_THREAD_CONFIG = {
13341334

13351335
// T3 waits can block for an hour; keep Codex's MCP timeout above that.
13361336
const CODEX_T3_MCP_TOOL_TIMEOUT_SEC = 65 * 60;
1337+
// Calls arrive as `t3code.<tool>`; t3McpToolPresentation.ts must keep resolving that form.
1338+
const CODEX_T3_WAIT_MCP_SERVER = "t3code";
1339+
const CODEX_DIRECT_ONLY_T3_TOOL = "t3_thread_wait";
13371340

13381341
function codexThreadRuntimeParams(input: {
13391342
readonly threadId: ThreadId | null;
@@ -1346,6 +1349,14 @@ function codexThreadRuntimeParams(input: {
13461349
readonly config: Readonly<Record<string, Schema.Json>>;
13471350
} {
13481351
const { mcpSession } = input;
1352+
const t3Server =
1353+
mcpSession === undefined
1354+
? undefined
1355+
: {
1356+
url: mcpSession.endpoint,
1357+
tool_timeout_sec: CODEX_T3_MCP_TOOL_TIMEOUT_SEC,
1358+
http_headers: { Authorization: mcpSession.authorizationHeader },
1359+
};
13491360
return {
13501361
...(input.runtimePolicy?.cwd == null ? {} : { cwd: input.runtimePolicy.cwd }),
13511362
...(input.modelSelection === undefined ? {} : { model: input.modelSelection.model }),
@@ -1355,16 +1366,17 @@ function codexThreadRuntimeParams(input: {
13551366
...(input.threadId === null
13561367
? {}
13571368
: { [`shell_environment_policy.set.${PortScanner.AGENT_THREAD_ENV}`]: input.threadId }),
1358-
...(mcpSession === undefined
1369+
...(t3Server === undefined
13591370
? {}
13601371
: {
1361-
// Override only T3's server so launch-argument MCP servers survive.
1362-
"mcp_servers.t3-code": {
1363-
url: mcpSession.endpoint,
1364-
tool_timeout_sec: CODEX_T3_MCP_TOOL_TIMEOUT_SEC,
1365-
http_headers: {
1366-
Authorization: mcpSession.authorizationHeader,
1367-
},
1372+
// Override only T3's servers so launch-argument MCP servers survive.
1373+
"mcp_servers.t3-code": { ...t3Server, disabled_tools: [CODEX_DIRECT_ONLY_T3_TOOL] },
1374+
// Code Mode runs a blocking wait as a nested call, and the model keeps working
1375+
// around it. A second, direct-only registration makes it a plain tool call.
1376+
[`mcp_servers.${CODEX_T3_WAIT_MCP_SERVER}`]: {
1377+
...t3Server,
1378+
enabled_tools: [CODEX_DIRECT_ONLY_T3_TOOL],
1379+
omit_tools_from: ["code_mode", "deferred"],
13681380
},
13691381
}),
13701382
},

‎docs/orchestration-v2/orchestrator-mcp-server.md‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,18 @@ check the `orchestration` capability before reading or mutating state.
5858

5959
### Codex V2
6060

61-
Codex app-server receives the remote MCP server through command-line config
62-
overrides:
63-
64-
```text
65-
-c mcp_servers.t3-code.url=http://127.0.0.1:<port>/mcp
66-
-c mcp_servers.t3-code.bearer_token_env_var="T3_MCP_BEARER_TOKEN"
67-
```
68-
69-
The provider-session token is placed in `T3_MCP_BEARER_TOKEN`. Both the
70-
production Codex launcher and the injectable test launcher use the same
71-
projection helper.
61+
Codex gets T3's MCP server in each thread's `thread/start`, `thread/resume`,
62+
and `thread/fork` config, with the provider-session token in an
63+
`Authorization` header. The same server is registered twice:
64+
65+
- `t3-code`: every tool except `t3_thread_wait`.
66+
- `t3code`: only `t3_thread_wait`, with `omit_tools_from = ["code_mode", "deferred"]`.
67+
68+
Code Mode runs a nested call as part of a script, so the model keeps working
69+
while a blocking wait runs. The second entry makes the wait a direct tool call,
70+
like Codex's own wait tools. Codex reports calls as `<server>.<tool>`, so
71+
`packages/shared/src/t3McpToolPresentation.ts` must resolve both server names.
72+
Tool display and pending-work detection depend on it.
7273

7374
### Claude Agent SDK V2
7475

‎packages/shared/src/t3McpToolPresentation.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe("resolveT3McpToolPresentation", () => {
1616
"mcp__t3_code__",
1717
"mcp__t3code__",
1818
"T3-code.",
19+
"t3code.",
1920
"t3_code/",
2021
"t3code:",
2122
"mcp_t3-code_",

0 commit comments

Comments
 (0)