fix(v2): compact full sessions before provider handoffs #13123
ClosedBil0000(GitHub profile, opens in a new tab)wants to merge 5 commits into
t3code/codex-turn-mapping fromrefs/pull/13123/headopened 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:XL
- apps/server/src/orchestration-v2/ProviderTurnStartService.ts line 839OutdatedResolvedby Bil0000(GitHub profile, opens in a new tab)@@ -628,5 +823,17 @@628823 runtimePolicy: resolvedRuntimePolicy,629824 }),630825 );826+ let contextExhausted = false;631827 if (resumed._tag === "Success") {632- return resumed.success;828+ if (message.text.trim() === "/compact" && message.attachments.length === 0)829+ return resumed.success;830+ const context = yield* getHandoffContext(resumed.success);831+ const prepared = yield* Effect.result(832+ prepareContextHandoffs({833+ handoffs: effectiveHandoffs,834+ providerThread: resumed.success,835+ budget: context.preflightBudget,836+ alreadyDeliveredItemIds: context.deliveredItemIds,837+ }),838+ );839+ contextExhausted =
- apps/server/src/orchestration-v2/ProviderTurnStartService.ts lines 950 to 950OutdatedResolvedby Bil0000(GitHub profile, opens in a new tab)@@ -716,5 +946,5 @@716946 ],717947 });718948 return replacement;719- });720- if (!(yield* isCurrentAttemptInStatus("starting"))) {949+ }).pipe(950+ Effect.catchTag(
Bil0000(GitHub profile, opens in a new tab) changed the title
- apps/server/src/orchestration-v2/RestartContinuation.ts lines 26 to 32OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -15,12 +15,18 @@1515 export function restartContinuationRun(1616 projection: Pick<1717 ProjectionRuntimeRecoveryState,18- "thread" | "runs" | "providerThreads" | "providerSessions" | "providerTurns"18+ "thread" | "runs" | "attempts" | "providerThreads" | "providerSessions" | "providerTurns"1919 >,2020 ): OrchestrationV2Run | undefined {2121 if (projection.thread.archivedAt !== null || projection.thread.deletedAt !== null) return;2222 const run = projection.runs.reduce<OrchestrationV2Run | undefined>(2323 (latest, candidate) => (!latest || candidate.ordinal > latest.ordinal ? candidate : latest),2424 undefined,2525 );26- if (!run) return;26+ if (27+ !run ||28+ projection.attempts.some(29+ (attempt) => attempt.id === run.activeAttemptId && attempt.contextCompaction,30+ )31+ )32+ return;
- apps/server/src/orchestration-v2/ProviderTurnStartService.ts line 906OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +886,21 @@886+ );887+ const resumed = yield* Effect.result(888+ uncertainDelivery889+ ? Effect.fail(890+ new ProviderAdapterTurnStartError({891+ driver: session.driver,892+ threadId: projection.thread.id,893+ providerThreadId: providerThread.id,894+ runId,895+ cause: "Uncertain native history injection",896+ }),897+ )898+ : session.resumeThread({899+ providerThread,900+ threadId: projection.thread.id,901+ modelSelection: run.modelSelection,902+ runtimePolicy: resolvedRuntimePolicy,903+ }),904+ );905+ if (resumed._tag === "Success") {906+ if (message.text.trim() === "/compact" && message.attachments.length === 0)
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed