fix(server): serialize checkpoint restores with pending turns #10608
Closedsaphid(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/10608/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:L
- apps/server/src/orchestration/projector.ts line 681OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -639,3 +676,6 @@639676 ...nextBase,640677 threads: updateThread(nextBase.threads, payload.threadId, {641678 session,679+ pendingTurnStartMessageId:680+ (session.status === "running" && session.activeTurnId !== null) ||681+ session.status === "error" ||apps/server/src/orchestration/decider.ts line 2061Resolvedby saphid(GitHub profile, opens in a new tab)@@ -1670,3 +1688,4 @@16701688 payload: {16711689 threadId: command.threadId,16721690 turnCount: command.turnCount,1691+ preservedMessageIds:
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- @@ -273,3 +273,5 @@273273 }),274274 );275275276+const CheckpointAndProviderCommandReactorsLive = ProviderCommandReactorLive.pipe(277+ Layer.provideMerge(CheckpointReactorLive),
- apps/server/src/orchestration/Layers/CheckpointReactor.ts line 795OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -753,3 +789,7 @@753789754790 yield* providerService.assertConversationRollbackSupported(event.payload.threadId);755791792+ const fromCheckpointRef = thread.checkpoints793+ .filter(794+ (checkpoint) =>795+ checkpoint.status === "ready" && checkpoint.checkpointTurnCount <= currentTurnCount,apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts line 2997OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2973,3 +2994,4 @@29732994 }));29742995 });297529962997+ const listPendingTurnStarts: ProjectionSnapshotQueryShape["listPendingTurnStarts"] = () =>apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts line 1335Resolvedby saphid(GitHub profile, opens in a new tab)@@ -1167,3 +1172,4 @@11671172 `,11681173 });116911741175+ const listPendingTurnStartRows = SqlSchema.findAll({
- apps/server/src/orchestration/Layers/ProviderCommandReactor.ts line 1209OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1182,0 +1189,21 @@1189+ readonly messageId: MessageId;1190+ readonly turnId: TurnId;1191+ }) {1192+ const command = {1193+ type: "thread.turn.start.acknowledge" as const,1194+ commandId: yield* serverCommandId("thread-turn-start-acknowledge"),1195+ threadId: input.threadId,1196+ messageId: input.messageId,1197+ turnId: input.turnId,1198+ };1199+ const dispatch = orchestrationEngine.dispatch(command).pipe(Effect.asVoid);1200+ yield* dispatch.pipe(1201+ Effect.catchCause((cause) => {1202+ if (Cause.hasInterruptsOnly(cause)) {1203+ return Effect.failCause(cause);1204+ }1205+ return Effect.logWarning("provider command reactor retrying turn start acknowledgement", {1206+ threadId: input.threadId,1207+ messageId: input.messageId,1208+ cause: Cause.pretty(cause),1209+ }).pipe(Effect.andThen(dispatch));apps/server/src/orchestration/Layers/ProviderCommandReactor.ts line 2029Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1798,12 +1858,13 @@17981858 }17991859 });180018601801- // Subscribe before returning, even while event handling waits for server activation.1802- const domainEvents = yield* orchestrationEngine.subscribeDomainEvents;1803- yield* forkParked(Stream.runForEach(domainEvents, processEvent));1861+ const liveDomainEvents = domainEvents.pipe(1862+ Stream.filter((event) => event.sequence > handoffSequence),1863+ );1804186418051865 // The domain event stream is hot, so work pending before this reactor18061866 // starts cannot be resumed. Correlated completions only clear the request18071867 // captured here, leaving any newer request untouched.1808- const clearInterrupted = clearInterruptedThreadTitleRegenerations(1809- interruptedTitleRegenerations,1868+ const clearInterruptedTurnStarts = Effect.forEach(1869+ interruptedTurnStarts,1870+ (pending) =>
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed