The best way to control Claude Code, Codex and more from any computer or phone
fix(codex): keep late subagent interrupts from freezing other threads (#25322)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Victor Vogel committed
Oct 30, 2026 at 16:13 UTC
6919aa4cf1bfd31e4bfd61b478fcaa16e0e2dc06
2 files changed
+141
-13
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+126
@@ -4909,6 +4909,132 @@ describe("CodexAdapterV2 post-settle continuation", () => {
4909
),
4910
);
4911
4912
+ const interruptSubagentTurnAfterStopTranscript = makeCodexReplayTranscript({
4913
+ scenario: "codex-interrupt-subagent-turn-after-stop",
4914
+ entries: [
4915
+ ...interruptSubagentCommandTranscript.entries.slice(0, -1),
4916
+ {
4917
+ type: "emit_inbound",
4918
+ label: "turn/started/child-after-stop",
4919
+ frame: {
4920
+ method: "turn/started",
4921
+ params: {
4922
+ threadId: INTERRUPT_CHILD_NATIVE_THREAD,
4923
+ turn: makeCodexReplayTurn({
4924
+ id: INTERRUPT_LATE_CHILD_NATIVE_TURN,
4925
+ status: "inProgress",
4926
+ }),
4927
+ },
4928
+ },
4929
+ },
4930
+ {
4931
+ type: "expect_outbound",
4932
+ label: "turn/interrupt/child-after-stop",
4933
+ frame: {
4934
+ id: 7,
4935
+ method: "turn/interrupt",
4936
+ params: {
4937
+ threadId: INTERRUPT_CHILD_NATIVE_THREAD,
4938
+ turnId: INTERRUPT_LATE_CHILD_NATIVE_TURN,
4939
+ },
4940
+ },
4941
+ },
4942
+ {
4943
+ type: "emit_inbound",
4944
+ label: "turn/interrupt/child-after-stop",
4945
+ frame: { id: 7, result: {} },
4946
+ },
4947
+ {
4948
+ type: "emit_inbound",
4949
+ label: "thread/goal/updated/root",
4950
+ frame: {
4951
+ method: "thread/goal/updated",
4952
+ params: {
4953
+ threadId: INTERRUPT_NATIVE_THREAD,
4954
+ turnId: null,
4955
+ goal: {
4956
+ threadId: INTERRUPT_NATIVE_THREAD,
4957
+ objective: INTERRUPT_PROMPT,
4958
+ status: "paused",
4959
+ tokenBudget: null,
4960
+ tokensUsed: 0,
4961
+ timeUsedSeconds: 0,
4962
+ createdAt: 1782622440,
4963
+ updatedAt: 1782622450,
4964
+ },
4965
+ },
4966
+ },
4967
+ },
4968
+ { type: "runtime_exit", status: "success" },
4969
+ ],
4970
+ });
4971
+
4972
+ it.effect(
4973
+ "keeps reading notifications while interrupting a child turn that starts after Stop",
4974
+ () =>
4975
+ Effect.scoped(
4976
+ Effect.gen(function* () {
4977
+ const harness = yield* makeCodexReplayHarness(interruptSubagentTurnAfterStopTranscript);
4978
+ const now = yield* DateTime.now;
4979
+
4980
+ yield* harness.runtime.startTurn(
4981
+ makeCodexTestTurnInput({
4982
+ threadId: harness.threadId,
4983
+ providerThread: harness.providerThread,
4984
+ now,
4985
+ attemptId: RunAttemptId.make("attempt-codex-interrupt-subagent-turn-after-stop"),
4986
+ text: INTERRUPT_PROMPT,
4987
+ }),
4988
+ );
4989
+ yield* harness.until(() =>
4990
+ harness.events.some(
4991
+ (event) =>
4992
+ event.type === "turn_item.updated" &&
4993
+ event.turnItem.type === "command_execution" &&
4994
+ event.turnItem.nativeItemRef?.nativeId === INTERRUPT_CHILD_COMMAND_ITEM &&
4995
+ event.turnItem.status === "running",
4996
+ ),
4997
+ );
4998
+ const providerTurnId = harness.events.find(
4999
+ (
5000
+ event,
5001
+ ): event is Extract<
5002
+ ProviderAdapter.ProviderAdapterV2Event,
5003
+ { type: "provider_turn.updated" }
5004
+ > => event.type === "provider_turn.updated" && event.threadId === harness.threadId,
5005
+ )?.providerTurn.id;
5006
+ assert.isDefined(providerTurnId);
5007
+
5008
+ yield* harness.runtime.interruptTurn({
5009
+ providerThread: harness.providerThread,
5010
+ providerTurnId,
5011
+ });
5012
+ yield* harness.awaitTerminal(1);
5013
+
5014
+ // The TestClock never reaches the interrupt's timeout, so this arrives only
5015
+ // if the reader is free to read the interrupt response and the frame after it.
5016
+ yield* harness.until(() =>
5017
+ harness.events.some(
5018
+ (event) =>
5019
+ event.type === "provider_thread.updated" &&
5020
+ event.providerThread.goal?.status === "paused",
5021
+ ),
5022
+ );
5023
+ assert.isFalse(
5024
+ harness.events.some(
5025
+ (event) =>
5026
+ event.type === "provider_turn.updated" &&
5027
+ event.providerTurn.nativeTurnRef?.nativeId === INTERRUPT_LATE_CHILD_NATIVE_TURN,
5028
+ ),
5029
+ );
5030
+ }).pipe(
5031
+ Effect.provide(
5032
+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
5033
+ ),
5034
+ ),
5035
+ ),
5036
+ );
5037
+
5038
it.effect.each([
5039
{
5040
name: "usage",
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+15
-13
@@ -2565,31 +2565,33 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
2565
while (ancestor !== undefined) {
2566
if (terminalizedNativeTurns.has(ancestor.nativeTurnId)) {
2567
const nativeThreadId = yield* getNativeThreadId(subagent.providerThread);
2568
- const interrupted = yield* client
2568
+ // Fork requests off the notification reader so it can read their responses.
2569
+ yield* client
2570
.request("turn/interrupt", {
2571
threadId: nativeThreadId,
2572
turnId: turn.nativeTurnId,
2573
})
2574
.pipe(
2574
- Effect.as(true),
2575
Effect.catch((cause) =>
2576
Effect.logWarning("orchestration-v2.codex-late-subagent-interrupt-failed", {
2577
nativeThreadId,
2578
nativeTurnId: turn.nativeTurnId,
2579
cause,
2580
- }).pipe(Effect.as(false)),
2580
+ }),
2581
),
2582
- Effect.timeoutOption("10 seconds"),
2583
- );
2584
- if (Option.isNone(interrupted)) {
2585
- yield* Effect.logWarning(
2586
- "orchestration-v2.codex-late-subagent-interrupt-timeout",
2587
- {
2588
- nativeThreadId,
2589
- nativeTurnId: turn.nativeTurnId,
2590
- },
2582
+ Effect.timeoutOrElse({
2583
+ duration: "10 seconds",
2584
+ orElse: () =>
2585
+ Effect.logWarning(
2586
+ "orchestration-v2.codex-late-subagent-interrupt-timeout",
2587
+ {
2588
+ nativeThreadId,
2589
+ nativeTurnId: turn.nativeTurnId,
2590
+ },
2591
+ ),
2592
+ }),
2593
+ Effect.forkIn(scope),
2594
);
2592
- }
2595
return;
2596
}
2597
ancestor = ancestor.subagent?.parentContext;