fix(server): retry Codex capacity failures with empty input #25611
MergedYash-Singh1(GitHub profile, opens in a new tab)merged 8 commits into
main fromrefs/pull/25611/headmerged by Yash-Singh1(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts line 6207OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -6094,0 +6187,21 @@6187+ yield* Ref.update(providerRetries, (current) =>6188+ new Map(current).set(context.providerTurnId, state),6189+ );6190+ yield* emitProviderEvent({6191+ type: "turn_item.updated",6192+ driver: CODEX_PROVIDER,6193+ turnItem: codexRetryTurnItem(context, state, "running", now),6194+ });6195+ yield* Effect.sleep(retryDelayMs).pipe(6196+ Effect.andThen(6197+ turnTerminalizationPermit.withPermits(1)(6198+ Effect.gen(function* () {6199+ if (6200+ (yield* Ref.get(activeTurns)).get(terminal.nativeTurnId) !== context ||6201+ (yield* Ref.get(interruptingNativeTurns)).has(terminal.nativeTurnId)6202+ )6203+ return;6204+ const nativeThreadId = yield* getNativeThreadId(context.providerThread);6205+ capacityContinuations.set(nativeThreadId, { context, retry: state });6206+ yield* finalizeCodexTurn({ ...terminal, continueRun: true });6207+ yield* startNativeTurn(apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts lines 5875 to 5875OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -5836,11 +5863,13 @@5836- providerTurnId: input.context.providerTurnId,5837- itemOrdinal: providerRetry.itemOrdinal,5838- failure: providerRetry.failure,5839- retry: providerRetry.retry,5840- status: providerTurnStatusToTerminal(input.status),5841- startedAt: providerRetry.startedAt,5842- updatedAt: input.completedAt,5843- }),5863+ turnItem: codexRetryTurnItem(5864+ input.context,5865+ providerRetry,5866+ input.status === "failed" &&5867+ providerRetry.context !== input.context &&5868+ providerRetry.context !== undefined5869+ ? "interrupted"5870+ : providerTurnStatusToTerminal(input.status),5871+ input.completedAt,5872+ ),58445873 });58455874 }58465875 if (input.status !== "completed") {
- apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts lines 7027 to 7044Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -6822,3 +7015,21 @@68227015 ),68237016 interruptTurn: Effect.fn("CodexAdapterV2.interruptTurn")(68247017 function* (requestedInput) {7018+ const nativeThreadId = requestedInput.providerThread.nativeThreadRef?.nativeId;7019+ const startingRetry =7020+ nativeThreadId == null7021+ ? undefined7022+ : capacityContinuations.get(nativeThreadId)?.context;7023+ if (7024+ startingRetry?.providerTurnId === latestRunTurnId(requestedInput.providerTurnId) &&7025+ startingRetry.capacityRetryPending !== undefined7026+ ) {7027+ const started = yield* Deferred.await(startingRetry.capacityRetryPending).pipe(7028+ Effect.timeoutOption("10 seconds"),7029+ );7030+ if (Option.isNone(started))7031+ return yield* toProtocolError(7032+ "Codex did not start the capacity retry within 10 seconds; Stop could not be delivered.",7033+ );7034+ if (started.value === undefined) return;7035+ }
- apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts lines 1967 to 1967Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1934,3 +1961,7 @@19341961 fileChangeKindsByItem: new Map(),19351962 runningCompactionItemIds: new Set(),19361963 };1964+ const nativeThreadId = input.turnInput.providerThread.nativeThreadRef?.nativeId;1965+ const continuation =1966+ nativeThreadId == null ? undefined : capacityContinuations.get(nativeThreadId);1967+ if (continuation !== undefined) {
Yash-Singh1(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed