fix(server): detaching a Codex thread unloads it from the shared app-server #14187
Mergedjuliusmarmingemerged 2 commits into
t3code/codex-turn-mapping fromrefs/pull/14187/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/orchestration-v2/ProviderSessionManager.ts line 1880OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1866,3 +1869,12 @@18661869 });18671870 return;18681871 }1872+ // The shared runtime stays up for other threads, so unload this1873+ // thread's native state rather than leaving it (and its MCP1874+ // servers) resident until the whole runtime is released.1875+ const unloadThread = detached.value.exposedRuntime.unloadThread;1876+ if (detached.value.supportsMultipleProviderThreads && unloadThread !== undefined) {1877+ yield* Effect.forEach(1878+ detachedProviderThreads.filter((thread) => thread.nativeThreadRef !== null),1879+ (providerThread) =>1880+ unloadThread({ providerThread }).pipe(
- apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts lines 5602 to 5606OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -5589,3 +5589,18 @@55895589 }),55905590 ),55915591 ),5592+ // Dropping this connection's subscription lets the shared app-server5593+ // shut the native thread (and its MCP servers) down once it is idle.5594+ // `notLoaded` / `notSubscribed` mean there is nothing left to unload.5595+ unloadThread: (unloadInput) =>5596+ Effect.gen(function* () {5597+ const nativeThreadId = yield* getNativeThreadId(unloadInput.providerThread);5598+ yield* client.request("thread/unsubscribe", { threadId: nativeThreadId });5599+ }).pipe(5600+ Effect.mapError((cause) =>5601+ cause._tag === "ProviderAdapterProtocolError"5602+ ? cause5603+ : toProtocolError(5604+ `Failed to unload Codex thread for provider thread ${unloadInput.providerThread.id}.`,5605+ normalizeCodexCause(cause),5606+ ),
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged thisa3f967a
juliusmarminge closed this
- @@ -1868,0 +1894,21 @@1894+ if (1895+ entry?.runtime !== detached.value.runtime ||1896+ entry.attachedThreadIds.has(input.threadId)1897+ ) {1898+ return;1899+ }1900+ yield* Effect.forEach(1901+ detachedProviderThreads.filter((thread) => thread.nativeThreadRef !== null),1902+ (providerThread) =>1903+ unloadThread({ providerThread }).pipe(1904+ // Bounded so a wedged provider cannot hold up the1905+ // thread's next attach.1906+ Effect.timeout(UNLOAD_THREAD_TIMEOUT_MS),1907+ Effect.catchCause((cause) =>1908+ Effect.logWarning(1909+ "orchestration-v2.driver-session.detach-unload-failed",1910+ {1911+ providerSessionId: input.providerSessionId,1912+ threadId: input.threadId,1913+ providerThreadId: providerThread.id,1914+ cause,
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed