feat(orchestration): persist run-next messages server-side across providers #7240
ClosedDavidIlie(GitHub profile, opens in a new tab)wants to merge 4 commits into
main fromrefs/pull/7240/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/web/src/components/chat/MessagesTimeline.tsx lines 1053 to 1059OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1035,5 +1040,20 @@10351040 markdownCwd={ctx.markdownCwd}10361041 />10371042 </div>1038- <div className="flex w-full max-w-[80%] items-center justify-end pe-1 text-xs tabular-nums opacity-0 transition-opacity duration-200 focus-within:opacity-100 group-hover:opacity-100">1043+ <div1044+ className={cn(1045+ "flex w-full max-w-[80%] items-center justify-end pe-1 text-xs tabular-nums opacity-0 transition-opacity duration-200 focus-within:opacity-100 group-hover:opacity-100",1046+ row.message.deliveryState === "queued" && "opacity-100",1047+ )}1048+ >10391049 <div className="flex shrink-0 items-center gap-2">1050+ {row.message.deliveryState === "queued" ? (1051+ <div className="flex items-center gap-1.5 text-muted-foreground">1052+ <span>Queued</span>1053+ <button1054+ type="button"1055+ className="font-medium text-destructive hover:underline"1056+ onClick={() => ctx.onCancelQueuedMessage(row.message.id)}1057+ >1058+ Cancel1059+ </button>
- apps/server/src/orchestration/Layers/ProviderCommandReactor.ts line 1508OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1396,14 +1492,17 @@13961492 event.type === "thread.turn-interrupt-requested" ||13971493 event.type === "thread.approval-response-requested" ||13981494 event.type === "thread.user-input-response-requested" ||1399- event.type === "thread.session-stop-requested"1495+ event.type === "thread.session-stop-requested" ||1496+ event.type === "thread.session-set"14001497 ) {14011498 return yield* worker.enqueue(event);14021499 }14031500 });1404150114051502 yield* forkParked(Stream.runForEach(orchestrationEngine.streamDomainEvents, processEvent));140615031407- // The domain event stream is hot, so work pending before this reactor1408- // starts cannot be resumed. Correlated completions only clear the request1409- // captured here, leaving any newer request untouched.1504+ yield* Effect.gen(function* () {1505+ const persistedQueuedTurns = yield* projectionQueuedTurnRepository.listAll;1506+ yield* Effect.forEach(1507+ persistedQueuedTurns.filter((row) => row.status === "ready"),1508+ (row) => worker.enqueue(queuedTurnStartEvent(row)),apps/mobile/src/state/use-thread-composer-state.ts line 167OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -160,3 +163,5 @@160163 modelSelection: draft.modelSelection ?? thread.modelSelection,161164 runtimeMode: draft.runtimeMode ?? thread.runtimeMode,162165 interactionMode: draft.interactionMode ?? thread.interactionMode,166+ deliveryMode:167+ AsyncResult.isSuccess(preferences) && preferences.value.steerActiveTurns === false@@ -1036,0 +1065,21 @@1065+ aggregateKind: "thread",1066+ aggregateId: command.threadId,1067+ occurredAt: command.createdAt,1068+ commandId: command.commandId,1069+ })),1070+ type: "thread.queued-turn-cancelled",1071+ payload: {1072+ threadId: command.threadId,1073+ messageId: command.messageId,1074+ cancelledAt: command.createdAt,1075+ },1076+ };1077+ }1078+1079+ case "thread.queued-turn.dispatch": {1080+ const thread = yield* requireThread({1081+ readModel,1082+ command,1083+ threadId: command.threadId,1084+ });1085+ const message = thread.messages.find((entry) => entry.id === command.messageId);
- apps/server/src/persistence/Services/ProjectionQueuedTurns.ts lines 46 to 69OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +49,21 @@49+ input: typeof ProjectionQueuedTurnMessageInput.Type,50+ ) => Effect.Effect<void, ProjectionRepositoryError>;51+ readonly deleteByMessageId: (52+ input: typeof ProjectionQueuedTurnMessageInput.Type,53+ ) => Effect.Effect<void, ProjectionRepositoryError>;54+ readonly deleteReadyByThreadId: (55+ input: typeof ProjectionQueuedTurnThreadInput.Type,56+ ) => Effect.Effect<void, ProjectionRepositoryError>;57+ readonly deleteByThreadId: (58+ input: typeof ProjectionQueuedTurnThreadInput.Type,59+ ) => Effect.Effect<void, ProjectionRepositoryError>;60+ readonly listByThreadId: (61+ input: typeof ProjectionQueuedTurnThreadInput.Type,62+ ) => Effect.Effect<ReadonlyArray<ProjectionQueuedTurn>, ProjectionRepositoryError>;63+ readonly listAll: Effect.Effect<ReadonlyArray<ProjectionQueuedTurn>, ProjectionRepositoryError>;64+}65+66+export class ProjectionQueuedTurnRepository extends Context.Service<67+ ProjectionQueuedTurnRepository,68+ ProjectionQueuedTurnRepositoryShape69+>()("t3/persistence/Services/ProjectionQueuedTurns/ProjectionQueuedTurnRepository") {}apps/server/src/persistence/Layers/ProjectionQueuedTurns.ts lines 194 to 197OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +177,21 @@177+ const listByThreadId: ProjectionQueuedTurnRepositoryShape["listByThreadId"] = (input) =>178+ listThreadRows(input).pipe(mapError("ProjectionQueuedTurnRepository.listByThreadId:query"));179+ const listAll: ProjectionQueuedTurnRepositoryShape["listAll"] = listAllRows(undefined).pipe(180+ mapError("ProjectionQueuedTurnRepository.listAll:query"),181+ );182+183+ return {184+ upsert,185+ markReady,186+ deleteByMessageId,187+ deleteReadyByThreadId,188+ deleteByThreadId,189+ listByThreadId,190+ listAll,191+ } satisfies ProjectionQueuedTurnRepositoryShape;192+});193+194+export const ProjectionQueuedTurnRepositoryLive = Layer.effect(195+ ProjectionQueuedTurnRepository,196+ make,197+);
- apps/server/src/orchestration/Layers/ProjectionPipeline.ts line 1130Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1026,0 +1108,21 @@1108+ });1109+ return;1110+1111+ case "thread.session-set":1112+ if (1113+ event.payload.session.status === "running" ||1114+ event.payload.session.status === "error" ||1115+ event.payload.session.status === "stopped" ||1116+ event.payload.session.status === "interrupted"1117+ ) {1118+ yield* projectionQueuedTurnRepository.deleteReadyByThreadId({1119+ threadId: event.payload.threadId,1120+ });1121+ }1122+ return;1123+1124+ case "thread.deleted":1125+ case "thread.reverted":1126+ yield* projectionQueuedTurnRepository.deleteByThreadId({1127+ threadId: event.payload.threadId,1128+ });apps/server/src/orchestration/decider.ts line 126Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -116,3 +121,6 @@116121 },117122 occurredAt: string,118123 ): boolean {124+ if (thread.messages.some((message) => message.deliveryState === "queued")) {125+ return true;126+ }
- apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts line 442Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -438,3 +438,4 @@438438 pending_approval_count AS "pendingApprovalCount",439439 pending_user_input_count AS "pendingUserInputCount",440440 has_actionable_proposed_plan AS "hasActionableProposedPlan",441+ EXISTS (
DavidIlie(GitHub profile, opens in a new tab) changed the title
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
77925c33-a0c0-4a41-9415-c28a7df6659cYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share