perf(orchestration): per-thread shell deltas, visit throttling, event compaction #4971
Mergedjuliusmarmingemerged 3 commits into
t3code/codex-turn-mapping fromrefs/pull/4971/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
- apps/web/src/components/Sidebar.logic.ts line 273OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -260,4 +260,14 @@260260 localLastVisitedAt: string | undefined,261261 ): string | undefined {262262 if (serverLastVisitedAt === undefined) return localLastVisitedAt;263- return serverLastVisitedAt ?? undefined;263+ // Explicitly marked unread: a stale local watermark must not mask it.264+ if (serverLastVisitedAt === null) return undefined;265+ // The server value is authoritative but its dispatch is throttled while a266+ // thread is open; the eagerly-written local watermark keeps the open thread267+ // reading as visited until the trailing dispatch echoes back.268+ if (localLastVisitedAt === undefined) return serverLastVisitedAt;269+ const serverMs = Date.parse(serverLastVisitedAt);270+ const localMs = Date.parse(localLastVisitedAt);271+ if (Number.isNaN(localMs)) return serverLastVisitedAt;272+ if (Number.isNaN(serverMs)) return localLastVisitedAt;273+ return localMs > serverMs ? localLastVisitedAt : serverLastVisitedAt;
- apps/web/src/components/ChatView.tsx line 1968Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1941,0 +1948,21 @@1948+ lastVisitDispatchAtRef.current = Date.now();1949+ void visitThreadMutation({1950+ environmentId: serverThread.environmentId,1951+ input: { threadId: serverThread.id, visitedAt: serverThread.updatedAt },1952+ });1953+ };1954+ // Unread prominence only flips on run completions (hasUnseenCompletion),1955+ // so an unseen completion publishes immediately; mid-turn activity bumps1956+ // — several per second while a turn streams — ride a trailing throttle,1957+ // each rerun swapping the timer so the trailing dispatch carries the1958+ // newest watermark.1959+ const latestRunCompletedAtMs = serverThread.latestRun?.completedAt1960+ ? Date.parse(serverThread.latestRun.completedAt)1961+ : NaN;1962+ const hasUnseenCompletion =1963+ !Number.isNaN(latestRunCompletedAtMs) &&1964+ (Number.isNaN(lastVisitedAt) || latestRunCompletedAtMs > lastVisitedAt);1965+ const elapsed = Date.now() - lastVisitDispatchAtRef.current;1966+ if (hasUnseenCompletion || elapsed >= VISIT_DISPATCH_THROTTLE_MS) {1967+ dispatch();1968+ return;
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- @@ -212,0 +325,21 @@325+ WHERE application_event_version = 2326+ AND event_type = ${eventType}327+ GROUP BY stream_id, json_extract(payload_json, '$.id')328+ )329+ `;330+ const supersededMessageRows = yield* supersededEntityRows("message.updated");331+ const supersededNodeRows = yield* supersededEntityRows("node.updated");332+333+ const importedLegacyEventRows = yield* sql<{ readonly sequence: number }>`334+ SELECT sequence335+ FROM orchestration_events336+ WHERE application_event_version = 1337+ AND aggregate_kind = 'thread'338+ AND stream_id IN (339+ SELECT thread_id340+ FROM orchestration_v2_legacy_imports341+ WHERE transcript_imported_at IS NOT NULL342+ )343+ `;344+345+ const deletedEventCount = yield* deleteRowsBatched({
juliusmarminge merged thisa22a61d
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:
75de4261-8fcb-4d99-be8e-9ed4a0745091You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Comment `@coderabbitai help` to get the list of available commands.