fix(server): drop Codex sessions whose runtime exited #10799
Closedstephenjason89(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/10799/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
- apps/server/src/provider/Layers/CodexAdapter.ts line 2449Resolvedby stephenjason89(GitHub profile, opens in a new tab)@@ -2436,3 +2437,16 @@24362437 return;24372438 }24382439 yield* Queue.offerAll(runtimeEventQueue, runtimeEvents);2440+2441+ // A runtime that reports its own exit is gone, but nothing used to2442+ // remove it from `sessions`, so `hasSession`/`listSessions` kept2443+ // reporting the thread as live. Startup reconciliation and the2444+ // session reaper both trust that, so a thread whose Codex process2445+ // died mid-turn stayed `running` with its `activeTurnId` set and2446+ // showed "Working" forever. Scope identity guards a replacement2447+ // session already started for the same thread.2448+ if (runtimeEvents.some((runtimeEvent) => runtimeEvent.type === "session.exited")) {2449+ const exited = sessions.get(input.threadId);2450+ if (exited?.scope === sessionScope) {2451+ sessions.delete(input.threadId);2452+ yield* stopSessionInternal(exited).pipe(Effect.forkIn(adapterScope));
- apps/server/src/provider/Layers/CodexAdapter.ts lines 2446 to 2449Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2436,3 +2437,13 @@24362437 return;24372438 }24382439 yield* Queue.offerAll(runtimeEventQueue, runtimeEvents);2440+2441+ // A runtime that reported its own exit is gone, but startup2442+ // reconciliation and the session reaper keep reading the thread as2443+ // live until it leaves this map. Teardown is forked because it2444+ // interrupts this fiber and closes the scope it runs in.2445+ if (runtimeEvents.some((runtimeEvent) => runtimeEvent.type === "session.exited")) {2446+ const exited = sessions.get(input.threadId);2447+ if (exited?.scope === sessionScope) {2448+ sessions.delete(input.threadId);2449+ yield* stopSessionInternal(exited).pipe(Effect.forkIn(adapterScope));
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
juliusmarminge added labelsmacroscope-review
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed