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, 21:00 UTC
fix(server): resumed Claude sessions wait for their MCP servers (#34822)
Julius Marminge committed
Nov 11, 2026 at 23:20 UTC
9e716b694ae38c0598251baee553704bdb38e9c0
2 files changed
+33
-7
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+16
@@ -344,6 +344,22 @@ describe("ClaudeAdapterV2 runtime query policy", () => {
344
);
345
});
346
347
+ it("makes a resumed Claude session wait for its MCP servers before the first request", () => {
348
+ const appThread = {
349
+ lineage: {
350
+ parentThreadId: null,
351
+ relationshipToParent: null,
352
+ rootThreadId: ThreadId.make("t"),
353
+ },
354
+ };
355
+ const nonblocking = (environment: NodeJS.ProcessEnv, resume: boolean) =>
356
+ ClaudeAdapterV2.claudeQueryEnvironment(environment, appThread, undefined, resume)
357
+ .MCP_CONNECTION_NONBLOCKING;
358
+ assert.equal(nonblocking({}, true), "0");
359
+ assert.isUndefined(nonblocking({}, false));
360
+ assert.equal(nonblocking({ MCP_CONNECTION_NONBLOCKING: "1" }, true), "1");
361
+ });
362
+
363
it("pins Claude's auto tool search on through flag settings", () => {
364
const override = ClaudeAdapterV2.claudeToolSearchOverride;
365
for (const value of ["auto", "auto:10", "auto:99.5", "auto:x", "auto:Infinity"]) {
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+17
-7
@@ -1842,20 +1842,29 @@ function claudeLiveSelectionFlagSettings(
1842
1843
// A delegated child is its own SDK session, so Claude Code gives it the main-conversation cache
1844
// TTL. When the user sets Claude's subagentPromptCacheTtl, the child follows it like a native
1845
-// subagent would. An explicit CLAUDE_CODE_PROMPT_CACHE_TTL on the instance still wins.
1845
+// subagent would. A resumed session's first request otherwise goes out before its MCP servers
1846
+// connect, and Claude Code tells the agent they disconnected. Explicit instance values still win.
1847
export function claudeQueryEnvironment(
1848
environment: NodeJS.ProcessEnv,
1849
appThread: Pick<OrchestrationV2AppThread, "lineage">,
1850
subagentPromptCacheTtl: "5m" | "1h" | undefined,
1851
+ resume = false,
1852
): NodeJS.ProcessEnv {
1851
- if (
1852
- appThread.lineage.relationshipToParent !== "subagent" ||
1853
- subagentPromptCacheTtl === undefined ||
1854
- environment.CLAUDE_CODE_PROMPT_CACHE_TTL !== undefined
1855
- ) {
1853
+ const promptCacheTtl =
1854
+ appThread.lineage.relationshipToParent === "subagent" &&
1855
+ subagentPromptCacheTtl !== undefined &&
1856
+ environment.CLAUDE_CODE_PROMPT_CACHE_TTL === undefined
1857
+ ? subagentPromptCacheTtl
1858
+ : undefined;
1859
+ const blockingMcpConnect = resume && environment.MCP_CONNECTION_NONBLOCKING === undefined;
1860
+ if (promptCacheTtl === undefined && !blockingMcpConnect) {
1861
return environment;
1862
}
1858
- return { ...environment, CLAUDE_CODE_PROMPT_CACHE_TTL: subagentPromptCacheTtl };
1863
+ return {
1864
+ ...environment,
1865
+ ...(promptCacheTtl === undefined ? {} : { CLAUDE_CODE_PROMPT_CACHE_TTL: promptCacheTtl }),
1866
+ ...(blockingMcpConnect ? { MCP_CONNECTION_NONBLOCKING: "0" } : {}),
1867
+ };
1868
}
1869
1870
// Claude Code's auto tool search sends every MCP schema in full while they fit under a share of the
@@ -11791,6 +11800,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
11800
turnInput.appThread.lineage.relationshipToParent === "subagent"
11801
? yield* resolveSubagentPromptCacheTtl(turnInput.runtimePolicy.cwd)
11802
: undefined,
11803
+ shouldResume,
11804
),
11805
tools: queryPolicy.tools ?? CLAUDE_CODE_PRESET_TOOLS,
11806
...(mcpOverrides.allowedTools === undefined