fix(server): settle orphaned provider sessions at startup #7315
ClosedyassiEmp(GitHub profile, opens in a new tab)wants to merge 2 commits into
main fromrefs/pull/7315/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:L
- @@ -0,0 +79,21 @@79+ if (orphans.length === 0) {80+ return;81+ }82+83+ const nowUtc = yield* DateTime.now;84+ const now = DateTime.formatIso(nowUtc);85+ const nowMillis = DateTime.toEpochMillis(nowUtc);86+ let settledCount = 0;87+ for (const thread of orphans) {88+ if (yield* settleOrphan(thread, now, nowMillis)) {89+ settledCount += 1;90+ }91+ }92+93+ yield* Effect.logInfo("session.startup-reconciler.complete", {94+ orphanCount: orphans.length,95+ settledCount,96+ });97+ });98+99+ const reconcile: SessionStartupReconcilerShape["reconcile"] = () =>@@ -0,0 +97,21 @@97+ });98+99+ const reconcile: SessionStartupReconcilerShape["reconcile"] = () =>100+ sweep.pipe(101+ Effect.catch((error: unknown) =>102+ Effect.logWarning("session.startup-reconciler.failed", { error }),103+ ),104+ Effect.catchDefect((defect: unknown) =>105+ Effect.logWarning("session.startup-reconciler.defect", { defect }),106+ ),107+ );108+109+ return {110+ reconcile,111+ } satisfies SessionStartupReconcilerShape;112+});113+114+export const SessionStartupReconcilerLive = Layer.effect(115+ SessionStartupReconciler,116+ makeSessionStartupReconciler,117+);@@ -0,0 +1,16 @@1+import * as Context from "effect/Context";2+import type * as Effect from "effect/Effect";3+4+export interface SessionStartupReconcilerShape {5+ /**6+ * Settle sessions the read model considers live but whose provider process7+ * did not survive the last shutdown. Runs once during startup, after the8+ * projection pipeline is bootstrapped and before commands are accepted.9+ */10+ readonly reconcile: () => Effect.Effect<void>;11+}12+13+export class SessionStartupReconciler extends Context.Service<14+ SessionStartupReconciler,15+ SessionStartupReconcilerShape16+>()("t3/provider/Services/SessionStartupReconciler") {}
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:
2b46e23a-b9a3-4709-8963-c5117bd23438You 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