Skip to content

Commit 89081d0

Browse files
fix(codex): launch-arg MCP servers survive the thread's t3-code server (pingdotgg#15839)
Co-authored-by: Julius Marminge <[email protected]>
1 parent 135b16f commit 89081d0

3 files changed

Lines changed: 129 additions & 52 deletions

File tree

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

Lines changed: 117 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -723,49 +723,6 @@ describe("CodexAdapterV2 runtime policy", () => {
723723
});
724724

725725
describe("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({

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ export const CODEX_THREAD_CONFIG = {
13031303
// that limit so the server's own wait timeout ends a long call.
13041304
const CODEX_T3_MCP_TOOL_TIMEOUT_SEC = 65 * 60;
13051305

1306-
export function codexThreadRuntimeParams(input: {
1306+
function codexThreadRuntimeParams(input: {
13071307
readonly mcpSession: McpProviderSession.McpProviderSessionConfig | undefined;
13081308
readonly modelSelection?: { readonly model: string };
13091309
readonly runtimePolicy?: ProviderAdapter.ProviderAdapterV2RuntimePolicy;
@@ -1321,13 +1321,12 @@ export function codexThreadRuntimeParams(input: {
13211321
...(mcpSession === undefined
13221322
? {}
13231323
: {
1324-
mcp_servers: {
1325-
"t3-code": {
1326-
url: mcpSession.endpoint,
1327-
tool_timeout_sec: CODEX_T3_MCP_TOOL_TIMEOUT_SEC,
1328-
http_headers: {
1329-
Authorization: mcpSession.authorizationHeader,
1330-
},
1324+
// Override only T3's server so launch-argument MCP servers survive.
1325+
"mcp_servers.t3-code": {
1326+
url: mcpSession.endpoint,
1327+
tool_timeout_sec: CODEX_T3_MCP_TOOL_TIMEOUT_SEC,
1328+
http_headers: {
1329+
Authorization: mcpSession.authorizationHeader,
13311330
},
13321331
},
13331332
}),

‎packages/effect-codex-app-server/src/replay.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,11 @@ function normalizeThreadRequest(frame: unknown, ignoredConfigKeys: ReadonlySet<s
268268
}
269269
const { cwd: _cwd, model: _model, config, ...params } = record.params as Record<string, unknown>;
270270
if (typeof config !== "object" || config === null) return { ...record, params };
271-
const { mcp_servers: _mcpServers, ...owned } = config as Record<string, unknown>;
271+
const owned = Object.fromEntries(
272+
Object.entries(config as Record<string, unknown>).filter(
273+
([key]) => key !== "mcp_servers" && !key.startsWith("mcp_servers."),
274+
),
275+
);
272276
for (const key of ignoredConfigKeys) delete owned[key];
273277
return { ...record, params: { ...params, config: owned } };
274278
}

0 commit comments

Comments
 (0)