The best way to control Claude Code, Codex and more from any computer or phone
fix(server): Codex goal turns after a server restart are paused instead of running unseen (#25935)
Julius Marminge committed
Nov 19, 2026 at 12:14 UTC
47583f8682344a078c353eec01e95346bd770e8d
2 files changed
+115
-1
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+98
@@ -11906,6 +11906,104 @@ describe("CodexAdapterV2 post-settle continuation", () => {
11906
),
11907
),
11908
);
11909
+
11910
+ // regression: #21865 goal turns Codex continues after a server restart ran with no UI
11911
+ it.effect.each(["decoded", "undecodable"] as const)(
11912
+ "pauses a goal turn Codex starts on a resumed thread whose response is %s",
11913
+ (resumeResponse) =>
11914
+ Effect.gen(function* () {
11915
+ const transcript = makeCodexReplayTranscript({
11916
+ scenario: "goal-turn-after-resume",
11917
+ entries: [
11918
+ ...sessionStart,
11919
+ ...request(
11920
+ 3,
11921
+ "thread/resume",
11922
+ {
11923
+ threadId: nativeThreadId,
11924
+ excludeTurns: true,
11925
+ config: CodexAdapterV2.CODEX_THREAD_CONFIG,
11926
+ },
11927
+ resumeResponse === "decoded"
11928
+ ? { thread: { id: nativeThreadId, updatedAt: 1782622450 } }
11929
+ : { thread: { id: nativeThreadId } },
11930
+ ),
11931
+ notification("goal resumed", "thread/goal/updated", {
11932
+ threadId: nativeThreadId,
11933
+ turnId: null,
11934
+ goal: codexGoal("active", 10),
11935
+ }),
11936
+ notification("goal continuation", "turn/started", {
11937
+ threadId: nativeThreadId,
11938
+ turn: makeCodexReplayTurn({ id: "orphan-goal-turn", status: "inProgress" }),
11939
+ }),
11940
+ ...request(
11941
+ 4,
11942
+ "thread/goal/set",
11943
+ { threadId: nativeThreadId, status: "paused" },
11944
+ { goal: codexGoal("paused", 10) },
11945
+ ),
11946
+ ...request(
11947
+ 5,
11948
+ "turn/interrupt",
11949
+ { threadId: nativeThreadId, turnId: "orphan-goal-turn" },
11950
+ {},
11951
+ ),
11952
+ notification("interrupted", "turn/completed", {
11953
+ threadId: nativeThreadId,
11954
+ turn: makeCodexReplayTurn({ id: "orphan-goal-turn", status: "interrupted" }),
11955
+ }),
11956
+ ],
11957
+ });
11958
+ const requests: Array<[string, unknown]> = [];
11959
+ const interrupted = yield* Deferred.make<void>();
11960
+ const harness = yield* makeCodexReplayHarness(
11961
+ transcript,
11962
+ () => Effect.void,
11963
+ (method, params) =>
11964
+ Effect.sync(() => {
11965
+ requests.push([method, params]);
11966
+ }).pipe(
11967
+ Effect.andThen(
11968
+ method === "turn/interrupt"
11969
+ ? Deferred.succeed(interrupted, undefined)
11970
+ : Effect.void,
11971
+ ),
11972
+ ),
11973
+ );
11974
+ const resumed = yield* harness.runtime
11975
+ .resumeThread({
11976
+ providerThread: harness.providerThread,
11977
+ modelSelection: CODEX_TEST_MODEL_SELECTION,
11978
+ runtimePolicy: CODEX_TEST_RUNTIME_POLICY,
11979
+ })
11980
+ .pipe(Effect.exit);
11981
+ assert.equal(Exit.isSuccess(resumed), resumeResponse === "decoded");
11982
+ yield* Deferred.await(interrupted);
11983
+ const goalStatuses = () =>
11984
+ harness.events.flatMap((event) =>
11985
+ event.type === "provider_thread.updated"
11986
+ ? [event.providerThread.goal?.status ?? null]
11987
+ : [],
11988
+ );
11989
+ yield* harness.until(() => goalStatuses().length > 0);
11990
+ assert.deepEqual(goalStatuses(), ["active"]);
11991
+ assert.deepEqual(requests.slice(-2), [
11992
+ ["thread/goal/set", { threadId: nativeThreadId, status: "paused" }],
11993
+ ["turn/interrupt", { threadId: nativeThreadId, turnId: "orphan-goal-turn" }],
11994
+ ]);
11995
+ }).pipe(
11996
+ Effect.scoped,
11997
+ Effect.provide(
11998
+ Layer.mergeAll(
11999
+ IdAllocator.layer,
12000
+ McpProviderSessions.layer,
12001
+ NodeServices.layer,
12002
+ NodeCrypto.layer,
12003
+ ),
12004
+ ),
12005
+ ),
12006
+ );
12007
});
12008
12009
describe("Codex file-change approval paths", () => {
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+17
-1
@@ -8001,11 +8001,24 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
8001
: { runtimePolicy: threadInput.runtimePolicy }),
8002
}),
8003
});
8004
+ // Codex resumes an active goal's turns right after the response; own them before it.
8005
+ const previousRoot = rootProviderThreads.get(nativeThreadId);
8006
+ rootProviderThreads.set(nativeThreadId, threadInput.providerThread);
8007
+ goalUpdatesHeld.add(nativeThreadId);
8008
const response = yield* ensureInitialized.pipe(
8009
Effect.andThen(resume),
8010
Effect.flatMap(decodeCodexResumeMetadata),
8011
+ // Stay registered: a lost or undecodable response may still have resumed the thread.
8012
+ Effect.onError(() =>
8013
+ Effect.suspend(() => {
8014
+ if (previousRoot !== undefined) {
8015
+ rootProviderThreads.set(nativeThreadId, previousRoot);
8016
+ }
8017
+ return releaseGoalUpdates(nativeThreadId);
8018
+ }),
8019
+ ),
8020
);
8008
- return {
8021
+ const resumed = {
8022
...threadInput.providerThread,
8023
providerSessionId: input.providerSessionId,
8024
providerInstanceId: adapterOptions.instanceId,
@@ -8018,6 +8031,9 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
8031
nativeConversationHeadRef: threadInput.providerThread.nativeConversationHeadRef,
8032
updatedAt: codexTimestamp(response.thread.updatedAt),
8033
} satisfies OrchestrationV2ProviderThread;
8034
+ rootProviderThreads.set(nativeThreadId, resumed);
8035
+ yield* releaseGoalUpdates(nativeThreadId);
8036
+ return rootProviderThreads.get(nativeThreadId) ?? resumed;
8037
},
8038
(effect, threadInput) =>
8039
effect.pipe(