Repository navigation
Resubscribe thread timelines with the cached window's tag - #6395
Merged
Merged
Conversation
Leaving a thread forgot its timeline tag, so returning within the query's stale window resubscribed with null. The server sends nothing to a null subscriber, no refetch followed, and appended events don't invalidate a pushed timeline, so the thread froze until a focus refetch or reconnect. Subscribe and reconnect messages now carry the tag of the window in the React Query cache, falling back to the tracked tag, and pushes that land after the last subscriber left no longer re-record a tag. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
#6220 made
thread-timelinesubscriptions tag-aware: asubscribemessage tells the server which window the client holds (timelineTags), and a subscriber whose tag isnullgets no pushes until a tag arrives. The client only sent a tag after a fetch (fetchThreadTimeline→syncThreadTimelineSubscriptionTag).WebSocketManager.unsubscribe()deleted the tracked tag when you left a thread, so coming back resubscribed withnulland the server recorded apendingbaseline thatpushTargetskips. If the cached timeline was less than 2s old (globalstaleTime), remounting didn't refetch. With pushes on, that is the usual case for a running thread, because every applied push refreshesdataUpdatedAt. So no tag was ever sent. In push mode, appended events also don't invalidate an open timeline (dirtyThreadTimelineQueriesForAppendedEvents). The thread stayed frozen until a focus refetch or reconnect. This only happens with thetimelinePushexperiment, which early adopters get by default.A real app run also showed a race that hides the bug on fast-streaming threads. A push still in flight after the unsubscribe re-recorded the tag in
handleIncomingMessage, so the bug showed only when you left during a quiet moment. That stale entry could also outlive the cached window it named.What changed
apps/app/src/lib/ws.ts:WebSocketManager.setHeldThreadTimelineTagSource(source)registers a lookup for the tag of the window the client holds. Everysubscribemessage, both a single subscribe and the batched one sent when the socket opens or reconnects, uses that tag first, then the tracked tag, thennull. It also records the tag it sends, so latersyncThreadTimelineTagcalls dedupe against what the server holds. A pushed tag is recorded only while the target is still subscribed.apps/app/src/hooks/cache-owners/thread-timeline-push-owner.ts:trackHeldThreadTimelineTags(queryClient)points that lookup at the React Query cache: the.tagof the cachedThreadTimelineResponse. The cache is the source of truth.useWebSocketinstalls it next to the existingapplyThreadTimelineSignalwiring.null. The mount fetch that always follows sends the tag. This is Shrink timeline pushes and diff idle windows against active ones #6220's first-open path, so the double full-window push it removed doesn't come back.fetchThreadTimelinealready sendsafterTagacross limits the same way.nullonly when it holds no window, and then a fetch always follows and syncs the tag. A server-side fallback forpendingsubscribers would bring back the full-window push before the GET that Shrink timeline pushes and diff idle windows against active ones #6220 removed. I added a server test that pins the assumption the fix relies on: a subscriber that leaves and returns with the last pushed window's tag gets a delta, not a full window, even after the 30s read hold has expired.docs/timeline-pagination.md: updated the "Deltas and pushes" paragraph.HOST_DAEMON_PROTOCOL_VERSIONbump. No server/daemon field changed, and app/server subscribe messages keep the same shape.How you verified
apps/app/src/hooks/queries/thread-timeline-resubscribe.test.tsxrenders the realuseWebSocketanduseThreadTimeline, with the realwsManageron a fake socket and the app query client (staleTime2000):main: the tag sent isnull.main: it sends the pushed tag.null, then sends the refetched tag.apps/app/src/lib/ws.test.ts: a push that lands after the last subscriber left doesn't leave a tag behind.apps/server/test/public/public-thread-timeline-push.test.ts: a subscriber returning with its last pushed tag gets a delta that matches a fresh GET.pnpm exec turbo run typecheck lint test --filter=@bb/app --filter=@bb/server: 14/14 tasks pass. App: 6310 passed. Server: 3690 passed. The first run had one failure in the existingpushes deltas from the fetched window that keep a subscriber equal to a fresh GET, which this PR doesn't touch. It uses 50ms push-settle timing under full-suite load. The file passed 3/3 times alone, and the full rerun was green.pnpm dev, fresh data dir, Claude Code provider,bb settings experiment timelinePush true, headless Chromium with aWebSocketsend/receive hook). I opened a running thread that runs a 4s Bash step at a time, waited for a push, then clicked another thread and clicked back about 450ms later:useWebSocketwiring (mainbehaviour): the resubscribe carriednull. No pushes arrived in the next 12s, and the view stayed on step 3 while the server was past step 6.mainsometimes escaped the bug through the in-flight push race described above. That race is why the bug showed up only intermittently.🤖 Generated with Claude Code