fix(server): clear Codex commands when their native thread closes #19936
MergedItayCohen-Prog(GitHub profile, opens in a new tab)merged 5 commits into
main fromrefs/pull/19936/headmerged by juliusmarminge 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/orchestration-v2/Adapters/CodexAdapterV2.ts line 4691Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -4695 +4695,21 @@469546954696+ // Codex unloads an unsubscribed idle thread after shutting down its4697+ // terminals, without completing each command item. The shared session4698+ // stays alive, so its retained commands need their own terminal events.4699+ yield* client.handleServerNotification("thread/closed", (payload) =>4700+ Effect.gen(function* () {4701+ const completedAt = yield* DateTime.now;4702+ for (const context of (yield* Ref.get(settledTurns)).values()) {4703+ if (context.providerThread.nativeThreadRef?.nativeId !== payload.threadId) continue;4704+ yield* terminalizeRunningCommandItems(4705+ context,4706+ context.nativeTurnId,4707+ "interrupted",4708+ completedAt,4709+ );4710+ yield* Ref.update(runningCommandItemsByTurn, (current) => {4711+ const updated = new Map(current);4712+ updated.delete(context.nativeTurnId);4713+ return updated;4714+ });4715+ yield* releaseSettledTurnIfIdle(context.nativeTurnId);
juliusmarminge assignedjuliusmarminge
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 merged this45bcde1
juliusmarminge closed this
Sign in to join this conversation.
Warning
Review limit reached#
Only developers with an assigned seat can use this organization's usage-based review budget, and seats here are assigned manually. Ask an admin to assign a seat, or change the review continuation mode in Billing.
Next included review available in 12 minutes.
Check out review usage here.
View limit details
Limit details: You’ve used all 10 included reviews currently available.
Learn how review limits work.
Review configuration:
⚙️ Run configuration
68c95a7f-2342-4cfb-90fb-4ce70949bc72📥 Commits
Reviewing files that changed from the base of the PR and between 74139513deefeb0b3d8ca476902c104d1f2bcbbd and f0cbf08b2dcad3065c5f790c54718d1e268f9214.
📒 Files selected for processing: 2
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.tsapps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts📝 Walkthrough
CodexAdapterV2 now handles
thread/closednotifications. It interrupts running command items for retained settled turns on the closed native thread, clears their tracking state, and attempts to release each turn. A replay test covers matching, unrelated, and duplicate closure notifications.Changes: Codex thread closure
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts,apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.tsPriority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~15 minutes
Change: Bug fix
Suggested reviewers:
juliusmarmingeMerge Risk: 🟡 Moderate · up to
74139When other background work retains a turn, a command interrupted by thread closure can reappear as completed and trigger a continuation. Guard late completions before merging.
Security architecture risk: 🔵 Low · up to
74139The change is narrowly scoped and does not show expanded privileges. However, a command marked interrupted on closure can later be marked completed if other background work keeps its context alive. Closure is therefore not consistently final.
Retained concerns
Security review details
Security Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Pre-merge checks:
3 · 
1
Full details: Description check
Explanation
The description clearly explains the problem, implementation, verification results, limitations, and tooling used. However, it does not provide the required Scope and approval section with a triaged issue or explicit maintainer approval, and it does not use the template’s section headings for Problem and Change.
Resolution
Add a Scope and approval section. Link the triaged issue or approval discussion and include the explicit maintainer approval comment. If this focused fix qualifies as an obvious bug exception, explain why. Organize the existing content under the required Problem, Change, Scope and approval, and Verification headings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.