Skip to content

Commit ae08fca

Browse files
fix(server): a restart no longer drops the wake Codex owed for a yielded command
Codex wakes the root agent when a command it yielded finishes after the turn, but restart recovery treated every cut shell as an unawaited dev server, so the agent stayed idle. The Codex adapter now marks root commands it offers that continuation for with completionWake "always", and recovery counts a marked shell as awaited work. Unmarked shells keep waiting for the next user message. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5f77198 commit ae08fca

5 files changed

Lines changed: 57 additions & 4 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,6 +2721,47 @@ describe("CodexAdapterV2 post-settle continuation", () => {
27212721
],
27222722
});
27232723

2724+
it.effect("marks a root command it wakes the agent for once the command finishes", () =>
2725+
Effect.gen(function* () {
2726+
const harness = yield* makeCodexReplayHarness({
2727+
...backgroundExecTranscript,
2728+
entries: backgroundExecTranscript.entries.map((entry) =>
2729+
entry.type === "emit_inbound" && entry.label === "item/completed/command-late"
2730+
? { ...entry, afterMs: 0 }
2731+
: entry,
2732+
),
2733+
});
2734+
yield* harness.runtime.startTurn(
2735+
makeCodexTestTurnInput({
2736+
threadId: harness.threadId,
2737+
providerThread: harness.providerThread,
2738+
now: yield* DateTime.now,
2739+
attemptId: RunAttemptId.make("attempt-command-completion-wake"),
2740+
text: BG_PROMPT,
2741+
}),
2742+
);
2743+
const commands = () =>
2744+
harness.events.flatMap((event) =>
2745+
event.type === "turn_item.updated" && event.turnItem.type === "command_execution"
2746+
? [[event.turnItem.status, event.turnItem.completionWake]]
2747+
: [],
2748+
);
2749+
yield* harness.until(
2750+
() => harness.continuationRequests.length === 1 && commands().length === 2,
2751+
);
2752+
// Restart recovery reads this to keep the wake the restart cut.
2753+
assert.deepEqual(commands(), [
2754+
["running", "always"],
2755+
["completed", "always"],
2756+
]);
2757+
}).pipe(
2758+
Effect.scoped,
2759+
Effect.provide(
2760+
Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
2761+
),
2762+
),
2763+
);
2764+
27242765
it.effect.each([false, true])(
27252766
"keeps commands interrupted after native thread closure (persistent tool: %s)",
27262767
(retainContext) =>

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3600,6 +3600,10 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
36003600
...(item.exitCode === null || item.exitCode === undefined
36013601
? {}
36023602
: { exitCode: item.exitCode }),
3603+
// Matches the continuation offered when it completes after the turn.
3604+
...(context.subagent === null && continuationRequests !== undefined
3605+
? { completionWake: "always" as const }
3606+
: {}),
36033607
};
36043608
return { node, turnItem };
36053609
});

‎apps/server/src/orchestration-v2/RestartBackgroundNote.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export function cancelledTurnItemWork(
5454
kind: "shell",
5555
label: compactLabel(item.input) ?? compactLabel(item.title) ?? "background command",
5656
id: item.id,
57+
...(item.completionWake === undefined ? {} : { completionWake: item.completionWake }),
5758
};
5859
case "dynamic_tool": {
5960
const monitor =
@@ -158,11 +159,11 @@ export function isRestartNoteSource(
158159
}
159160

160161
/**
161-
* A shell does not wake it: most are dev servers that nobody waits on, so their
162-
* note waits for the next user message.
162+
* A shell does not wake it unless its provider would have: most are dev
163+
* servers that nobody waits on, so their note waits for the next user message.
163164
*/
164-
export function isAwaitedWork(work: Pick<Work, "kind">): boolean {
165-
return work.kind !== "shell";
165+
export function isAwaitedWork(work: Pick<Work, "kind" | "completionWake">): boolean {
166+
return work.kind !== "shell" || work.completionWake === "always";
166167
}
167168

168169
export function runOutcome(

‎apps/server/src/orchestration-v2/RestartContinuation.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,7 @@ it.effect("wakes a settled Codex run whose own yielded command the restart cut",
11671167
type: "command_execution",
11681168
input: "sleep 180",
11691169
status: "running",
1170+
completionWake: "always",
11701171
},
11711172
],
11721173
} as unknown as OrchestrationV2ThreadProjection;

‎packages/contracts/src/orchestrationV2.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,8 @@ export const OrchestrationV2RestartCancelledBackgroundWork = Schema.Struct({
556556
kind: Schema.Literals(["subagent", "shell", "monitor", "task"]),
557557
label: TrimmedNonEmptyString,
558558
id: Schema.optional(TrimmedNonEmptyString),
559+
/** The provider wakes the agent when this work finishes, so it is awaited. */
560+
completionWake: Schema.optional(Schema.Literal("always")),
559561
});
560562
export type OrchestrationV2RestartCancelledBackgroundWork =
561563
typeof OrchestrationV2RestartCancelledBackgroundWork.Type;
@@ -1477,6 +1479,8 @@ export const OrchestrationV2TurnItem = Schema.Union([
14771479
outputOmitted: Schema.optional(Schema.Boolean),
14781480
outputIndicatesFailure: Schema.optional(Schema.Boolean),
14791481
exitCode: Schema.optional(Schema.Int),
1482+
/** The provider wakes the agent when this command finishes after its turn. */
1483+
completionWake: Schema.optional(Schema.Literal("always")),
14801484
}),
14811485
Schema.Struct({
14821486
...OrchestrationV2TurnItemBaseFields,
@@ -2244,6 +2248,8 @@ export const OrchestrationV2TurnItemJson = Schema.Union([
22442248
outputOmitted: Schema.optional(Schema.Boolean),
22452249
outputIndicatesFailure: Schema.optional(Schema.Boolean),
22462250
exitCode: Schema.optional(Schema.Int),
2251+
/** The provider wakes the agent when this command finishes after its turn. */
2252+
completionWake: Schema.optional(Schema.Literal("always")),
22472253
}),
22482254
Schema.Struct({
22492255
...OrchestrationV2TurnItemJsonBaseFields,

0 commit comments

Comments
 (0)