Repository navigation
Retain recently opened thread timelines for delta reopen - #4653
Conversation
Thread timeline and thread-detail bootstrap queries now stay cached for an hour instead of the default five minutes after the thread view unmounts. Reopening a retained thread renders its cached first page immediately and refreshes it with the existing afterSequence delta read instead of a cold full-page load. A per-QueryClient recency list bounds the retention: every useThreadTimeline mount touches its thread, and past 20 threads (8 on coarse pointers) the least recently opened thread's inactive timeline and bootstrap queries are removed. Threads still mounted in another pane are never evicted. Carved out of #4532; intent prefetch, the mounted scroll body, and timeline websocket push are not included. Co-authored-by: hemaaanth <[email protected]> Co-Authored-By: Claude Code <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 99fdaf2796
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| touched.delete(threadId); | ||
| touched.add(threadId); | ||
| evictThreadOpenCache(queryClient, touched); |
There was a problem hiding this comment.
Remove deleted threads from the open-cache LRU
When a recently opened thread is deleted, removeThreadScopedQueries removes its timeline but neither removes its retained bootstrap query nor can remove the ID from this private touched set. If the deleted IDs are newer than other cached threads, subsequent opens evict those older, still-valid timelines first while the deleted entries continue consuming the cap for up to an hour, reducing the number of threads that can benefit from delta reopening. Add a removal path for this bookkeeping and invoke it from the thread-deletion cache cleanup.
Useful? React with 👍 / 👎.
A deleted thread kept its slot in the recency list and its retained bootstrap query, so later opens evicted still-valid timelines first. Forget the thread when its scoped queries are removed. Co-Authored-By: Claude Code <[email protected]>
Human comments
What was wrong
Thread timeline and thread-detail bootstrap queries used React Query's default five-minute cache lifetime. Coming back to a thread after a few minutes threw away its cached rows and paid for a cold full-page timeline load, even though the server can answer with a small
afterSequencedelta when the client still has rows.What changed
Split out of #4532 (the retention part of commit dbcbfe1, re-applied on current main). Part 4 of 6.
apps/app/src/hooks/cache-owners/thread-open-cache-owner.ts(new): keeps a per-QueryClient recency list of opened threads. Past 20 threads (8 on coarse pointers) the least recently opened thread's inactive timeline and bootstrap queries are removed. A thread still mounted in another pane is never evicted. A deleted thread is dropped from the list and its bootstrap query removed (added after review).apps/app/src/hooks/queries/thread-queries.ts: the timeline and bootstrap queries are kept for one hour after unmount, anduseThreadTimelinetouches its thread on mount.Reopening a retained thread shows its cached rows immediately and refreshes them through the delta read main already has. A cached bootstrap still triggers the existing
refetchOnMount: "always"thread read. Trade-off: rows up to an hour old are visible for one request round trip.Not included from #4532: prefetch on hover or focus, keeping the scroll body mounted, first-window rendering, and timeline push over the socket. No server change.
How you verified
pnpm exec turbo run typecheck lint --filter=@bb/app: pass (0 lint errors).vitest run src/hooks/queries/thread-queries.test.tsx src/hooks/cache-owners/cache-owner-registry.test.ts: 34/34 pass. Six tests are new: a deleted thread frees its slot (fails without the fix), hour-long retention, eviction past the cap, keeping a thread open in another pane, the smaller cap on touch devices, and reopening a retained timeline with a delta from its cached sequence. The other five fail with main'sthread-queries.tsrestored.@bb/appsuite at concurrency 1: 5,180 passed, 3 failed (ToolsView.plugin-detail,CommandPalette.cold-open,CommandPalette). Each of those files passes when run alone on this branch and none touch the changed code; they were not run on clean main.🤖 Generated with Claude Code