Skip to content

Commit 69d7ca5

Browse files
fix(server): a failed Codex resume restores the root it replaced
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b74a25f commit 69d7ca5

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6614,9 +6614,6 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
66146614
resumeThread: Effect.fn("CodexAdapterV2.resumeThread")(
66156615
function* (threadInput) {
66166616
const nativeThreadId = yield* getNativeThreadId(threadInput.providerThread);
6617-
// Codex resumes an active goal's turns right after the response; own them before it.
6618-
rootProviderThreads.set(nativeThreadId, threadInput.providerThread);
6619-
goalUpdatesHeld.add(nativeThreadId);
66206617
// excludeTurns is not in the generated request schema yet.
66216618
const resume = client.raw.request("thread/resume", {
66226619
threadId: nativeThreadId,
@@ -6633,6 +6630,10 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
66336630
: { runtimePolicy: threadInput.runtimePolicy }),
66346631
}),
66356632
});
6633+
// Codex resumes an active goal's turns right after the response; own them before it.
6634+
const previousRoot = rootProviderThreads.get(nativeThreadId);
6635+
rootProviderThreads.set(nativeThreadId, threadInput.providerThread);
6636+
goalUpdatesHeld.add(nativeThreadId);
66366637
const response = yield* ensureInitialized.pipe(
66376638
Effect.andThen(
66386639
resume.pipe(
@@ -6655,7 +6656,8 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
66556656
Effect.flatMap(decodeCodexResumeMetadata),
66566657
Effect.onError(() =>
66576658
Effect.sync(() => {
6658-
rootProviderThreads.delete(nativeThreadId);
6659+
if (previousRoot === undefined) rootProviderThreads.delete(nativeThreadId);
6660+
else rootProviderThreads.set(nativeThreadId, previousRoot);
66596661
goalUpdatesHeld.delete(nativeThreadId);
66606662
}),
66616663
),

0 commit comments

Comments
 (0)