From 75c87747ef82c93d4be517cea15b8f6aa416361d Mon Sep 17 00:00:00 2001 From: Fluffy-Bunny-23 <193831219+Fluffy-Bunny-23@users.noreply.github.com> Date: Sat, 24 Oct 2026 13:44:31 -0700 Subject: [PATCH 01/12] fix(server): let native thread resume without handoff history When a resumed native conversation has no room for the recovery wrapper, start the requested turn against its existing transcript and leave the handoff pending for a later turn with more context. Implemented With: Codex via GPT-6 Luna on OpenAI through T3 Code --- .../src/orchestration-v2/ContextHandoffDelivery.ts | 8 ++++++++ .../src/orchestration-v2/ProviderTurnStartService.ts | 12 +++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/server/src/orchestration-v2/ContextHandoffDelivery.ts b/apps/server/src/orchestration-v2/ContextHandoffDelivery.ts index 799defe965cb..f40fee97a370 100644 --- a/apps/server/src/orchestration-v2/ContextHandoffDelivery.ts +++ b/apps/server/src/orchestration-v2/ContextHandoffDelivery.ts @@ -23,6 +23,7 @@ export const deliverContextHandoffs = Effect.fn("orchestrationV2.deliverContextH readonly providerThread: OrchestrationV2ProviderThread; readonly budget: number | Effect.Effect; readonly deferInline?: boolean; + readonly deferIfOverBudget?: boolean; readonly alreadyDeliveredItemIds: ReadonlySet; readonly inject?: ( history: ProviderAdapter.ProviderAdapterV2HistoricalContext, @@ -76,6 +77,13 @@ export const deliverContextHandoffs = Effect.fn("orchestrationV2.deliverContextH }); if (historyCost(selected.messages, selected.context) > budget) { if (input.deferInline) return { context: "", delivered: Effect.void, unsent: Effect.void }; + // The native transcript already contains this thread's conversation. If + // its remaining context is too small for the recovery wrapper, let the + // provider handle the current request against that transcript instead of + // failing before the provider sees it. Leave the handoff pending so a + // later turn with more room can still recover the omitted app history. + if (input.deferIfOverBudget) + return { context: "", delivered: Effect.void, unsent: Effect.void }; return yield* new ContextHandoffBudgetError(); } const omittedItemIds = new Set(selected.omittedItemIds); diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts index 4eb988ec4308..b248eb94dc17 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts @@ -1154,6 +1154,11 @@ export const layer: Layer.Layer< ...runningProviderThread, contextUsage: handoffUsage, }; + const nativeThreadHasTurns = + nativeInputRunIds.size > 0 || + (legacyInputRunIds.size > 0 && + sameNativeThread && + !acceptedAttempts.some((source) => source.nativeThreadId !== undefined)); const missedRuns = projection.runs.filter( (source) => source.ordinal < run.ordinal && @@ -1199,6 +1204,7 @@ export const layer: Layer.Layer< const delivery = yield* deliverContextHandoffs({ handoffs: [...effectiveHandoffs, ...retryHandoff], deferInline: compact, + deferIfOverBudget: sameNativeThread && nativeThreadHasTurns, providerThread: runningProviderThread, budget: Effect.gen(function* () { return handoffBudget({ @@ -1324,11 +1330,7 @@ export const layer: Layer.Layer< .filter((turn) => turn.providerThreadId === providerThread.id) .map((turn) => turn.ordinal), ) + 1, - nativeThreadHasTurns: - nativeInputRunIds.size > 0 || - (legacyInputRunIds.size > 0 && - sameNativeThread && - !acceptedAttempts.some((source) => source.nativeThreadId !== undefined)), + nativeThreadHasTurns, shouldStartProviderTurn: runControls.shouldStartProviderTurn, shouldFinalizeRun: runControls.shouldFinalizeRun, hasUnpairedRunInterruptRequest: runControls.hasUnpairedRunInterruptRequest, From a2975add1ad51079b5436dc046af9c5648489553 Mon Sep 17 00:00:00 2001 From: Fluffy-Bunny-23 <193831219+Fluffy-Bunny-23@users.noreply.github.com> Date: Sat, 24 Oct 2026 13:52:16 -0700 Subject: [PATCH 02/12] fix(server): keep deferred context handoffs available Only defer a handoff when its items are proven present in the same native transcript. Keep handoffs without a delivery record eligible after their originating run completes. Implemented With: Codex via GPT-6 Luna on OpenAI through T3 Code --- .../ProviderTurnStartService.ts | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts index b248eb94dc17..47c60e8ad7ef 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts @@ -5,6 +5,7 @@ import { latestProviderTurnForAttempt, type OrchestrationV2DomainEvent, type OrchestrationV2ExecutionNode, + type OrchestrationV2ContextHandoff, type OrchestrationV2ProviderThread, type OrchestrationV2Run, type OrchestrationV2RunAttempt, @@ -283,14 +284,7 @@ export const layer: Layer.Layer< source.id === handoff.targetRunId && (source.status === "failed" || source.status === "interrupted" || - (source.status === "completed" && - handoff.delivery === undefined && - projection.messages.some( - (message) => - message.id === source.userMessageId && - message.attachments.length === 0 && - message.text.trim().toLowerCase() === "/compact", - ))), + (source.status === "completed" && handoff.delivery === undefined)), ))), ); const nativeForkTransfer = projection.contextTransfers.find( @@ -1159,6 +1153,21 @@ export const layer: Layer.Layer< (legacyInputRunIds.size > 0 && sameNativeThread && !acceptedAttempts.some((source) => source.nativeThreadId !== undefined)); + // A turn in this native thread is not enough: another provider's handoff + // may contain work the native transcript has never seen. + const handoffIsAlreadyInNativeThread = (handoff: OrchestrationV2ContextHandoff) => + handoff.fromProviderThreadIds.includes(providerThread.id) && + handoff.history !== undefined && + handoff.history.messages.length > 0 && + handoff.history.omittedItems === 0 && + (handoff.history.omittedItemIds?.length ?? 0) === 0 && + handoff.history.messages.every( + (historical) => + historical.threadId === projection.thread.id && + historical.providerThreadId === providerThread.id && + historical.runId !== null && + nativeInputRunIds.has(historical.runId), + ); const missedRuns = projection.runs.filter( (source) => source.ordinal < run.ordinal && @@ -1201,10 +1210,16 @@ export const layer: Layer.Layer< createdAt: yield* DateTime.now, }), ]; + const handoffsToDeliver = [...effectiveHandoffs, ...retryHandoff]; const delivery = yield* deliverContextHandoffs({ - handoffs: [...effectiveHandoffs, ...retryHandoff], + handoffs: handoffsToDeliver, deferInline: compact, - deferIfOverBudget: sameNativeThread && nativeThreadHasTurns, + deferIfOverBudget: + sameNativeThread && + nativeThreadHasTurns && + missedItems.length === 0 && + handoffsToDeliver.length > 0 && + handoffsToDeliver.every(handoffIsAlreadyInNativeThread), providerThread: runningProviderThread, budget: Effect.gen(function* () { return handoffBudget({ From 7502fd96b1cf12f1e49e5d661c3e924d7c3a1ade Mon Sep 17 00:00:00 2001 From: Fluffy-Bunny-23 <193831219+Fluffy-Bunny-23@users.noreply.github.com> Date: Sat, 24 Oct 2026 13:54:56 -0700 Subject: [PATCH 03/12] fix(server): verify omitted handoff items before deferring Resolve capped handoff item IDs against source history and defer only when each item belongs to an accepted run on the current native thread. Implemented With: Codex via GPT-6 Luna on OpenAI through T3 Code --- .../ProviderTurnStartService.ts | 67 ++++++++++++++----- 1 file changed, 49 insertions(+), 18 deletions(-) diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts index 47c60e8ad7ef..5b9d4c1bfa6c 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts @@ -1109,11 +1109,16 @@ export const layer: Layer.Layer< ) .map((source) => source.id), ); + let turnStartHistory: ReadonlyArray | undefined; + const loadTurnStartHistory = Effect.gen(function* () { + turnStartHistory ??= yield* projectionStore.getTurnStartHistory(input.threadId); + return turnStartHistory; + }); // Legacy attempts lack native identity; exclude their explicitly recovered history, whose // attachments were not replayed into the replacement thread. const nativeContextEstimate = Effect.gen(function* () { return sameNativeThread - ? (yield* projectionStore.getTurnStartHistory(input.threadId)).reduce((sum, item) => { + ? (yield* loadTurnStartHistory).reduce((sum, item) => { if ( item.runId === run.id || (item.runId !== null && @@ -1155,19 +1160,36 @@ export const layer: Layer.Layer< !acceptedAttempts.some((source) => source.nativeThreadId !== undefined)); // A turn in this native thread is not enough: another provider's handoff // may contain work the native transcript has never seen. - const handoffIsAlreadyInNativeThread = (handoff: OrchestrationV2ContextHandoff) => - handoff.fromProviderThreadIds.includes(providerThread.id) && - handoff.history !== undefined && - handoff.history.messages.length > 0 && - handoff.history.omittedItems === 0 && - (handoff.history.omittedItemIds?.length ?? 0) === 0 && - handoff.history.messages.every( - (historical) => - historical.threadId === projection.thread.id && - historical.providerThreadId === providerThread.id && - historical.runId !== null && - nativeInputRunIds.has(historical.runId), + const itemIsInNativeThread = (item: { + readonly threadId: string; + readonly providerThreadId: string | null; + readonly runId: string | null; + }) => + item.threadId === projection.thread.id && + item.providerThreadId === providerThread.id && + item.runId !== null && + nativeInputRunIds.has(item.runId); + const handoffIsAlreadyInNativeThread = ( + handoff: OrchestrationV2ContextHandoff, + sourceItemsById: ReadonlyMap, + ) => { + const history = handoff.history; + if ( + !handoff.fromProviderThreadIds.includes(providerThread.id) || + history === undefined || + history.messages.length === 0 + ) + return false; + const omittedItemIds = history.omittedItemIds ?? []; + return ( + history.omittedItems === omittedItemIds.length && + history.messages.every(itemIsInNativeThread) && + omittedItemIds.every((itemId) => { + const item = sourceItemsById.get(itemId); + return item !== undefined && itemIsInNativeThread(item); + }) ); + }; const missedRuns = projection.runs.filter( (source) => source.ordinal < run.ordinal && @@ -1211,15 +1233,24 @@ export const layer: Layer.Layer< }), ]; const handoffsToDeliver = [...effectiveHandoffs, ...retryHandoff]; + const canDeferHandoff = + sameNativeThread && + nativeThreadHasTurns && + missedItems.length === 0 && + handoffsToDeliver.length > 0; + const sourceItemsById = + canDeferHandoff && + handoffsToDeliver.some((handoff) => (handoff.history?.omittedItems ?? 0) > 0) + ? new Map((yield* loadTurnStartHistory).map((item) => [item.id, item] as const)) + : new Map(); const delivery = yield* deliverContextHandoffs({ handoffs: handoffsToDeliver, deferInline: compact, deferIfOverBudget: - sameNativeThread && - nativeThreadHasTurns && - missedItems.length === 0 && - handoffsToDeliver.length > 0 && - handoffsToDeliver.every(handoffIsAlreadyInNativeThread), + canDeferHandoff && + handoffsToDeliver.every((handoff) => + handoffIsAlreadyInNativeThread(handoff, sourceItemsById), + ), providerThread: runningProviderThread, budget: Effect.gen(function* () { return handoffBudget({ From 31bfffb01f40509c9c177d9b115cb6369f612cf1 Mon Sep 17 00:00:00 2001 From: Fluffy-Bunny-23 <193831219+Fluffy-Bunny-23@users.noreply.github.com> Date: Sat, 24 Oct 2026 13:56:31 -0700 Subject: [PATCH 04/12] fix(server): allow verified fully capped handoffs to defer A handoff with no selected messages can still be proven to belong to the current native transcript when every omitted item ID resolves to an accepted native run. Implemented With: Codex via GPT-6 Luna on OpenAI through T3 Code --- .../src/orchestration-v2/ProviderTurnStartService.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts index 5b9d4c1bfa6c..3a221becf312 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts @@ -1174,14 +1174,11 @@ export const layer: Layer.Layer< sourceItemsById: ReadonlyMap, ) => { const history = handoff.history; - if ( - !handoff.fromProviderThreadIds.includes(providerThread.id) || - history === undefined || - history.messages.length === 0 - ) + if (!handoff.fromProviderThreadIds.includes(providerThread.id) || history === undefined) return false; const omittedItemIds = history.omittedItemIds ?? []; return ( + (history.messages.length > 0 || omittedItemIds.length > 0) && history.omittedItems === omittedItemIds.length && history.messages.every(itemIsInNativeThread) && omittedItemIds.every((itemId) => { From 53bb0c591748f6434bedb7fb2d2ea77b57fce534 Mon Sep 17 00:00:00 2001 From: Fluffy-Bunny-23 <193831219+Fluffy-Bunny-23@users.noreply.github.com> Date: Sat, 24 Oct 2026 20:40:22 -0700 Subject: [PATCH 05/12] fix(marketing): send Android visitors to Google Play Implemented With: Codex via gpt-6-luna on OpenAI through T3 Code --- apps/marketing/src/pages/index.astro | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/marketing/src/pages/index.astro b/apps/marketing/src/pages/index.astro index 292fc5985475..9fe0f4b2972c 100644 --- a/apps/marketing/src/pages/index.astro +++ b/apps/marketing/src/pages/index.astro @@ -421,11 +421,14 @@ const mobileEndorsementRows = [