The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
fix(server): MCP apps resume an idle Codex thread in its own workspace (#38468)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Alex Tyh Wang committed
Nov 19, 2026 at 15:12 UTC
571c27acaba142f63376067aff32ede793eb3245
2 files changed
+16
-5
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+12
-1
@@ -8619,7 +8619,12 @@ describe("CodexAdapterV2 post-settle continuation", () => {
8619
],
8620
});
8621
8622
- const harness = yield* makeCodexReplayHarness(transcript);
8622
+ const resumeParams: Array<unknown> = [];
8623
+ const harness = yield* makeCodexReplayHarness(transcript, undefined, (method, params) =>
8624
+ Effect.sync(() => {
8625
+ if (method === "thread/resume") resumeParams.push(params);
8626
+ }),
8627
+ );
8628
const mcpApps = harness.runtime.mcpApps;
8629
assert.ok(mcpApps, "Codex runtime should expose MCP apps");
8630
@@ -8630,6 +8635,12 @@ describe("CodexAdapterV2 post-settle continuation", () => {
8635
});
8636
8637
assert.deepEqual(result, resourceResult);
8638
+ // The shared app-server session's cwd and model belong to whichever thread opened it.
8639
+ // Codex must resume this thread with its own saved cwd, or it loads another
8640
+ // project's MCP servers and drops this project's.
8641
+ assert.equal(resumeParams.length, 1);
8642
+ assert.ok(!Predicate.hasProperty(resumeParams[0], "cwd"), "resume must not send a cwd");
8643
+ assert.ok(!Predicate.hasProperty(resumeParams[0], "model"), "resume must not send a model");
8644
}).pipe(
8645
Effect.provide(
8646
Layer.mergeAll(
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+4
-4
@@ -7770,6 +7770,9 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
7770
payload: cause,
7771
});
7772
// Codex unloads idle threads; MCP requests against one fail until it is resumed.
7773
+ // The session's model and cwd belong to whichever thread opened this shared
7774
+ // app-server, so leave them out: Codex resumes with the thread's saved settings
7775
+ // and loads that workspace's project MCP servers.
7776
const withLoadedThread = <A, E, R>(
7777
providerThread: OrchestrationV2ProviderThread,
7778
threadId: string,
@@ -7784,8 +7787,6 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
7787
...codexThreadRuntimeParams({
7788
threadId: providerThread.appThreadId,
7789
mcpSession,
7787
- modelSelection: input.modelSelection,
7788
- runtimePolicy: input.runtimePolicy,
7790
}),
7791
}),
7792
),
@@ -8855,14 +8856,13 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
8856
});
8857
}
8858
// thread/revert requires the thread loaded in this app-server; resume after restart or idle release.
8859
+ // Like withLoadedThread, resume with the thread's saved model and cwd, not the session's.
8860
if (!loaded) {
8861
yield* resumeNativeThread(threadId, {
8862
excludeTurns: true,
8863
...codexThreadRuntimeParams({
8864
threadId: threadInput.providerThread.appThreadId,
8865
mcpSession: yield* readMcpSession(threadInput.providerThread.appThreadId),
8864
- modelSelection: input.modelSelection,
8865
- runtimePolicy: input.runtimePolicy,
8866
}),
8867
});
8868
}