Warm sidebar thread detail subscriptions#2001
Conversation
- Prewarm visible sidebar threads - Keep active thread subscriptions sticky until idle - Expand cache capacity and add coverage
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Prewarm effect re-runs on every sidebar thread change
- Replaced the prewarmedSidebarThreads memo (which depended on the frequently-changing sidebarThreadByKey map) with prewarmedSidebarThreadRefs that uses parseScopedThreadKey to extract stable identity pairs directly from prewarmedSidebarThreadKeys, breaking the dependency chain that caused unnecessary effect re-runs on every thread summary update.
Or push these changes by commenting:
@cursor push 1017cc1156
Preview (1017cc1156)
diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx
--- a/apps/web/src/components/Sidebar.tsx
+++ b/apps/web/src/components/Sidebar.tsx
@@ -43,6 +43,7 @@
type GitStatusResult,
} from "@t3tools/contracts";
import {
+ parseScopedThreadKey,
scopedProjectKey,
scopedThreadKey,
scopeProjectRef,
@@ -2884,18 +2885,18 @@
() => getSidebarThreadIdsToPrewarm(visibleSidebarThreadKeys),
[visibleSidebarThreadKeys],
);
- const prewarmedSidebarThreads = useMemo(
+ const prewarmedSidebarThreadRefs = useMemo(
() =>
prewarmedSidebarThreadKeys.flatMap((threadKey) => {
- const thread = sidebarThreadByKey.get(threadKey);
- return thread ? [thread] : [];
+ const ref = parseScopedThreadKey(threadKey);
+ return ref ? [ref] : [];
}),
- [prewarmedSidebarThreadKeys, sidebarThreadByKey],
+ [prewarmedSidebarThreadKeys],
);
useEffect(() => {
- const releases = prewarmedSidebarThreads.map((thread) =>
- retainThreadDetailSubscription(thread.environmentId, thread.id),
+ const releases = prewarmedSidebarThreadRefs.map((ref) =>
+ retainThreadDetailSubscription(ref.environmentId, ref.threadId),
);
return () => {
@@ -2903,7 +2904,7 @@
release();
}
};
- }, [prewarmedSidebarThreads]);
+ }, [prewarmedSidebarThreadRefs]);
useEffect(() => {
const clearThreadJumpHints = () => {You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 9284b86. Configure here.
ApprovabilityVerdict: Needs human review This PR introduces a new feature that proactively warms thread subscriptions for visible sidebar items and significantly changes the subscription cache policy (longer TTL, larger cache, sticky non-idle threads). While the author owns this code and changes are well-tested, this is a new capability with runtime behavior implications around network subscriptions and resource management that warrants human review. You can customize Macroscope's approvability policy. Learn more. |
…s on thread summary changes The prewarmedSidebarThreads memo depended on sidebarThreadByKey, which is recreated whenever any sidebar thread summary changes. Since the useEffect only needs environmentId and threadId (stable identities), this caused unnecessary cleanup/re-setup cycles for all prewarm subscriptions on every thread status update. Replace the thread-object lookup with parseScopedThreadKey to extract identity pairs directly from the already-stable prewarmedSidebarThreadKeys, breaking the dependency on the frequently-changing sidebarThreadByKey map. Applied via @cursor push command
Co-authored-by: Cursor Agent <cursoragent@cursor.com>


Summary
Testing
bun fmtbun lintbun typecheckbun run test apps/web/src/components/Sidebar.logic.test.tsbun run test apps/web/src/environments/runtime/service.threadSubscriptions.test.tsNote
Medium Risk
Changes thread-detail subscription caching/eviction and adds background prewarming from the sidebar, which can affect memory/network usage and when subscriptions are released. Logic now depends on thread activity state to prevent eviction, so regressions could keep subscriptions alive longer than intended.
Overview
Prewarms thread-detail data for the first visible sidebar threads by retaining their detail subscriptions (default 10) while they remain visible, releasing them when the visible set changes.
Updates the runtime thread-detail subscription cache policy to be stickier for non-idle threads (pending approvals/input/plan, running turns, or non-idle orchestration), and to evict only idle unretained entries; idle TTL increases to 15 minutes and cache capacity to 32.
Adds unit tests covering
getSidebarThreadIdsToPrewarmand the new eviction behavior (longer warm period, non-idle stickiness, and increased capacity before eviction).Reviewed by Cursor Bugbot for commit a4afe8c. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Warm thread detail subscriptions for visible sidebar threads
SIDEBAR_THREAD_PREWARM_LIMIT) usingretainThreadDetailSubscription, releasing them when threads leave the prewarmed set.isNonIdleThreadDetailSubscriptionhelper in service.ts; eviction is deferred until the thread becomes idle.Macroscope summarized a4afe8c.