perf(orchestration): bound in-memory read model and client per-thread state #4176
ClosedRusiruSadathana(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/4176/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
- apps/server/src/orchestration/projector.ts lines 331 to 336Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -304,13 +316,17 @@304316 };305317 });306318307319 case "thread.deleted":320+ // Evict deleted threads from the in-memory model entirely rather than321+ // tombstoning them. The DB projection retains the row (it is the source322+ // of truth for downstream/HTTP reads and cleanup reactors consume the323+ // event stream, not this model), and no command legitimately targets an324+ // already-deleted thread. This is the primary fix for unbounded growth:325+ // a deleted thread's messages/activities/checkpoints are freed and it no326+ // longer costs anything on every subsequent event.308327 return decodeForEvent(ThreadDeletedPayload, event.payload, event.type, "payload").pipe(309328 Effect.map((payload) => ({310329 ...nextBase,311- threads: updateThread(nextBase.threads, payload.threadId, {312- deletedAt: payload.deletedAt,313- updatedAt: payload.deletedAt,314- }),330+ threads: HashMap.remove(nextBase.threads, payload.threadId),315331 })),316332 );apps/server/src/vcs/VcsStatusBroadcaster.ts line 499OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -498,2 +498,2 @@498498499499 if (pollerToInterrupt) {
- @@ -50,6 +50,17 @@5050 Atom.withLabel("preview:empty-thread"),5151 );525253+// Previously `Atom.keepAlive`, which pinned one atom node per thread key ever54+// visited in the registry for the process lifetime — an unbounded leak in a55+// long-lived tab. Idle-TTL lets the registry evict a thread's preview atom once56+// nothing observes it, matching the pattern used for other per-resource atom57+// families (see browser/previewWebviewConfigState.ts). Threads with live58+// preview sessions stay resident because the observed aggregate59+// `activePreviewSessionsAtom` reads them, keeping them out of the idle state;60+// only closed/idle threads are collected. An evicted idle thread re-seeds from61+// EMPTY and is re-populated by the next server snapshot, so eviction is safe.62+const PREVIEW_STATE_IDLE_TTL_MS = 5 * 60_000;63+5364 export const previewStateAtom = Atom.family((threadKey: string) =>5465 Atom.make<ThreadPreviewState>(EMPTY_THREAD_PREVIEW_STATE).pipe(55- Atom.keepAlive,66+ Atom.setIdleTTL(PREVIEW_STATE_IDLE_TTL_MS),@@ -50,6 +50,17 @@5050 Atom.withLabel("preview:empty-thread"),5151 );525253+// Previously `Atom.keepAlive`, which pinned one atom node per thread key ever54+// visited in the registry for the process lifetime — an unbounded leak in a55+// long-lived tab. Idle-TTL lets the registry evict a thread's preview atom once56+// nothing observes it, matching the pattern used for other per-resource atom57+// families (see browser/previewWebviewConfigState.ts). Threads with live58+// preview sessions stay resident because the observed aggregate59+// `activePreviewSessionsAtom` reads them, keeping them out of the idle state;60+// only closed/idle threads are collected. An evicted idle thread re-seeds from61+// EMPTY and is re-populated by the next server snapshot, so eviction is safe.62+const PREVIEW_STATE_IDLE_TTL_MS = 5 * 60_000;63+5364 export const previewStateAtom = Atom.family((threadKey: string) =>5465 Atom.make<ThreadPreviewState>(EMPTY_THREAD_PREVIEW_STATE).pipe(55- Atom.keepAlive,66+ Atom.setIdleTTL(PREVIEW_STATE_IDLE_TTL_MS),
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:
30f20953-b942-43f8-bcf8-3a2f69a5f75fYou 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