perf(orchestration): speed up new-chat propagation and offline catch-up #4177
MergedRusiruSadathana(GitHub profile, opens in a new tab)merged 3 commits into
main fromrefs/pull/4177/headmerged by juliusmarminge 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:L
- @@ -1086,0 +1144,21 @@1144+ // refetch) is far more expensive than a single O(active-threads)1145+ // snapshot. Send a fresh snapshot, then the live tail — exactly1146+ // what the no-afterSequence path does. The client reducer already1147+ // handles a `snapshot` item.1148+ if (headSequence - afterSequence > SHELL_RESUME_MAX_GAP) {1149+ const snapshot = yield* projectionSnapshotQuery.getShellSnapshot().pipe(1150+ Effect.tapError((cause) =>1151+ Effect.logError("orchestration shell snapshot load failed", { cause }),1152+ ),1153+ Effect.mapError(1154+ (cause) =>1155+ new OrchestrationGetSnapshotError({1156+ message: "Failed to load orchestration shell snapshot",1157+ cause,1158+ }),1159+ ),1160+ );1161+ return Stream.concat(1162+ Stream.make({ kind: "snapshot" as const, snapshot }),1163+ liveStream,1164+ );@@ -680,0 +698,21 @@698+ // and drops any `sequence <= snapshotSequence` — never skips a coalesced699+ // item. The refetch runs with bounded concurrency (order-preserving).700+ const SHELL_REFETCH_CONCURRENCY = 8;701+ const coalesceShellEvents = (702+ events: ReadonlyArray<OrchestrationEvent>,703+ ): Effect.Effect<ReadonlyArray<OrchestrationShellStreamEvent>, never, never> =>704+ Effect.gen(function* () {705+ if (events.length === 0) {706+ return [];707+ }708+ const latestByAggregate = new Map<string, OrchestrationEvent>();709+ for (const event of events) {710+ latestByAggregate.set(`${event.aggregateKind}:${event.aggregateId}`, event);711+ }712+ const survivors = Array.from(latestByAggregate.values()).sort(713+ (left, right) => left.sequence - right.sequence,714+ );715+ const shellEvents = yield* Effect.forEach(survivors, toShellStreamEvent, {716+ concurrency: SHELL_REFETCH_CONCURRENCY,717+ });718+ return shellEvents.flatMap((option) => (Option.isSome(option) ? [option.value] : []));
juliusmarminge merged thisdb4b2d8
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
Run ID:
37d04697-16ea-450b-a7a9-36aaf0fb7a85You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
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