@devries-cameron20 / t3code Mirror · read-only / commits / 6e3ada1a27
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 21:00 UTC

fix(server): wake Codex callers when restart cancels commands (#24538)

Julius Marminge committed Nov 11, 2026 at 15:45 UTC 6e3ada1a27163d7d455365f331d6b4fde0427ae0
5 files changed +60
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+46
@@ -4772,6 +4772,52 @@ describe("CodexAdapterV2 post-settle continuation", () => {
4772 ],
4773 });
4774
4775 + it.effect("marks a root command it wakes the agent for once the command finishes", () =>
4776 + Effect.gen(function* () {
4777 + const harness = yield* makeCodexReplayHarness({
4778 + ...backgroundExecTranscript,
4779 + entries: backgroundExecTranscript.entries.map((entry) =>
4780 + entry.type === "emit_inbound" && entry.label === "item/completed/command-late"
4781 + ? { ...entry, afterMs: 0 }
4782 + : entry,
4783 + ),
4784 + });
4785 + yield* harness.runtime.startTurn(
4786 + makeCodexTestTurnInput({
4787 + threadId: harness.threadId,
4788 + providerThread: harness.providerThread,
4789 + now: yield* DateTime.now,
4790 + attemptId: RunAttemptId.make("attempt-command-completion-wake"),
4791 + text: BG_PROMPT,
4792 + }),
4793 + );
4794 + const commands = () =>
4795 + harness.events.flatMap((event) =>
4796 + event.type === "turn_item.updated" && event.turnItem.type === "command_execution"
4797 + ? [[event.turnItem.status, event.turnItem.completionWake]]
4798 + : [],
4799 + );
4800 + yield* harness.until(
4801 + () => harness.continuationRequests.length === 1 && commands().length === 2,
4802 + );
4803 + // Restart recovery reads this to keep the wake the restart cut.
4804 + assert.deepEqual(commands(), [
4805 + ["running", "always"],
4806 + ["completed", "always"],
4807 + ]);
4808 + }).pipe(
4809 + Effect.scoped,
4810 + Effect.provide(
4811 + Layer.mergeAll(
4812 + IdAllocator.layer,
4813 + McpProviderSessions.layer,
4814 + NodeServices.layer,
4815 + NodeCrypto.layer,
4816 + ),
4817 + ),
4818 + ),
4819 + );
4820 +
4821 it.effect("wakes with well-formed text when the cuts split an emoji", () =>
4822 Effect.scoped(
4823 Effect.gen(function* () {
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+4
@@ -3789,6 +3789,10 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
3789 ...(item.exitCode === null || item.exitCode === undefined
3790 ? {}
3791 : { exitCode: item.exitCode }),
3792 + // Matches the continuation offered when it completes after the turn.
3793 + ...(context.subagent === null && continuationRequests !== undefined
3794 + ? { completionWake: "always" as const }
3795 + : {}),
3796 };
3797 return { node, turnItem };
3798 });
apps/server/src/orchestration-v2/RestartBackgroundNote.test.ts
+5
@@ -128,6 +128,11 @@ it("names a lost subagent by the id the agent resumes it with", () => {
128 assert.isTrue(
129 isAwaitedWork(cancelledRosterTaskWork({ kind: "monitor", taskId: "ci", awaited: true })),
130 );
131 + const codexCommand = { id: "item-2", type: "command_execution", input: "sleep 180" };
132 + assert.isFalse(isAwaitedWork(cancelledTurnItemWork(codexCommand as never)!));
133 + assert.isTrue(
134 + isAwaitedWork(cancelledTurnItemWork({ ...codexCommand, completionWake: "always" } as never)!),
135 + );
136 assert.equal(
137 cancelledTurnItemWork({
138 id: "item-1",
apps/server/src/orchestration-v2/RestartBackgroundNote.ts
+1
@@ -56,6 +56,7 @@ export function cancelledTurnItemWork(
56 kind: item.monitor === true ? "monitor" : "shell",
57 label: compactLabel(item.input) ?? compactLabel(item.title) ?? "background command",
58 id: item.id,
59 + ...(item.completionWake === "always" ? { awaited: true as const } : {}),
60 };
61 case "dynamic_tool": {
62 const monitor =
packages/contracts/src/orchestrationV2.ts
+4
@@ -1722,6 +1722,8 @@ export const OrchestrationV2TurnItem = Schema.Union([
1722 exitCode: Schema.optional(Schema.Int),
1723 /** Set when the command is a monitor, so background work lists it as a monitor. */
1724 monitor: Schema.optional(Schema.Boolean),
1725 + /** The provider wakes the agent when this command finishes after its turn. */
1726 + completionWake: Schema.optional(Schema.Literal("always")),
1727 }),
1728 Schema.Struct({
1729 ...OrchestrationV2TurnItemBaseFields,
@@ -2566,6 +2568,8 @@ export const OrchestrationV2TurnItemJson = Schema.Union([
2568 exitCode: Schema.optional(Schema.Int),
2569 /** Set when the command is a monitor, so background work lists it as a monitor. */
2570 monitor: Schema.optional(Schema.Boolean),
2571 + /** The provider wakes the agent when this command finishes after its turn. */
2572 + completionWake: Schema.optional(Schema.Literal("always")),
2573 }),
2574 Schema.Struct({
2575 ...OrchestrationV2TurnItemJsonBaseFields,