perf(server): trim stale context-window rows and drop dead replay RPC #4791
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 3 commits into
main fromrefs/pull/4791/headmerged by t3dotgg(GitHub profile, opens in a new tab) 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/ActivityPayloadProjection.ts line 248Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -203,0 +207,21 @@207+ * the full history — often thousands of rows on long threads — buys nothing.208+ * Live `thread.activity-appended` events are untouched: newer updates still209+ * stream through and supersede the retained row on the client.210+ */211+function dropStaleContextWindowActivities(212+ activities: ReadonlyArray<OrchestrationThreadActivity>,213+): ReadonlyArray<OrchestrationThreadActivity> {214+ let latestIndex = -1;215+ for (let index = activities.length - 1; index >= 0; index -= 1) {216+ if (activities[index]?.kind === "context-window.updated") {217+ latestIndex = index;218+ break;219+ }220+ }221+ if (latestIndex === -1) {222+ return activities;223+ }224+ return activities.filter(225+ (activity, index) => activity.kind !== "context-window.updated" || index === latestIndex,226+ );227+}
- apps/server/src/orchestration/ActivityPayloadProjection.ts lines 234 to 247Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -203,0 +210,21 @@210+ * latest row means the meter can still resolve a value from the turns that211+ * survive. Live `thread.activity-appended` events are untouched: newer updates212+ * still stream through and supersede the retained rows on the client.213+ */214+function dropStaleContextWindowActivities(215+ activities: ReadonlyArray<OrchestrationThreadActivity>,216+): ReadonlyArray<OrchestrationThreadActivity> {217+ const latestIndexByTurn = new Map<string | null, number>();218+ for (let index = 0; index < activities.length; index += 1) {219+ if (activities[index]?.kind === "context-window.updated") {220+ latestIndexByTurn.set(activities[index]!.turnId, index);221+ }222+ }223+ if (latestIndexByTurn.size === 0) {224+ return activities;225+ }226+ return activities.filter(227+ (activity, index) =>228+ activity.kind !== "context-window.updated" ||229+ latestIndexByTurn.get(activity.turnId) === index,230+ );
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
t3dotgg(GitHub profile, opens in a new tab) 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:
c0f74c5a-fd0c-45b9-94f1-f53a8f0a76b2You 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