Repository navigation
Send history compaction only to viewers of the compacted thread - #4652
Conversation
Event pruning and output-retention sweeps announced their work as history-rewritten, which every connected client treats as a reason to refetch thread lists, search, prompt history and the timeline. Compaction changes only stored event bodies, so announce it as history-compacted, deliver it to that thread's detail subscribers only, and refresh just the timeline window on the client. Compaction changes timeline rows without advancing the thread's sequence, so a row delta computed for one viewer could leave a second viewer at the same sequence holding the old rows. After a rewrite or compaction the timeline route now answers afterSequence requests at or below the sequence current at that moment with a full window. 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: 1595cb99cb
ℹ️ 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".
| "history-compacted": { | ||
| flush: "debounced", | ||
| dirty: [getThreadTimelineWindowInvalidationQueryKeys], |
There was a problem hiding this comment.
Invalidate cached turn-summary details on compaction
When the retained-output expiry sweep now emits history-compacted, this rule invalidates only the main timeline query. Expanded or previously loaded turns use useThreadTimelineTurnSummaryDetails, whose cache has staleTime: Infinity; because its query-key prefix is omitted here, those views can continue displaying output that the server has expired until the cache is discarded or the page reloads. Include the turn-summary-details queries in this invalidation while still avoiding unrelated thread/list queries.
Useful? React with 👍 / 👎.
Expanded turn details are cached without a stale time, so output expired by a retention sweep stayed visible in an open thread. Invalidate them together with the timeline window. Co-Authored-By: Claude Code <[email protected]>
Human comments
What was wrong
Event pruning and the output-retention sweeps announced their work as
history-rewritten. That change kind is broadcast to every connected client and makes each one refetch thread lists, search, prompt history and timelines, although compaction only changes stored event bodies. Idle sidebars refetched continuously while sweeps ran.Separately, compaction changes timeline rows without advancing the thread's sequence. The timeline route computes
afterSequencedeltas against the last rows it served at that sequence, so once one viewer refetched, a second viewer at the same sequence got an empty delta and kept the pre-compaction rows. This already happened on main.What changed
Split out of #4532 (the compaction part of commit 9537a77) plus a fix for the second-viewer case. Part 3 of 6.
packages/domain/src/change-kinds.ts: new thread change kindhistory-compacted.apps/server/src/services/system/{event-pruning,periodic-sweeps,thread-pruning-sweep}.ts: emithistory-compactedinstead ofhistory-rewritten; the pruning sweep sends one notification per thread at the end of the sweep.apps/server/src/ws/hub.ts: a change that is onlyhistory-compactedgoes to that thread's detail subscribers, not to every client.apps/app/src/hooks/cache-owners/realtime-cache-registry.ts:history-compactedrefreshes only the thread's timeline window and its loaded turn details (the second added after review; expired output otherwise stayed visible in expanded turns).apps/server/src/routes/threads/data.ts(not in Speed up thread switching, resume, realtime, and composer #4532): after a rewrite or compaction,afterSequencerequests at or below the sequence current at that moment get a full window instead of a delta. Compaction also clears the latest-rows cache as a rewrite does. The global ordering-context cache is still cleared only for rewrites; its entries are already keyed by the rewrite generation that pruning bumps.docs/events-table-pruning.mdupdated.Compatibility: an already-open tab running the old bundle drops the unknown kind (lenient parse) and simply does not refresh after a compaction. No host daemon wire change. Not included from #4532: moving
history-rewrittenfrom immediate to debounced, and invalidation without cancelling in-flight fetches.How you verified
pnpm exec turbo run typecheck lint --filter=@bb/app --filter=@bb/server --filter=@bb/domain: pass (0 lint errors).vitest run test/system/thread-pruning-sweep.test.ts test/system/event-pruning.test.ts test/services/periodic-sweeps.test.ts test/app/hub.test.ts test/public/public-thread-timeline-delta.test.ts: 51/51 pass.{ upsertRows: [] }) and passes with it.vitest run src/hooks/realtime-cache-effects.test.ts src/hooks/cache-owners/cache-owner-registry.test.ts: pass, including the new test that compaction marks only the timeline and loaded turn details stale.@bb/domaintests: 204/204.🤖 Generated with Claude Code