GeezerVison is showing github.com — perf: make streaming projection and activity appends incremental by x1xhlol · Pull Request #6608 · pingdotgg/t3code
Conversation
x1xhlol
commented
Aug 14, 2026
•
edited by cursor
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
What Changed
Server (ProjectionPipeline):
thread.message-sent no longer triggers a full refreshThreadShellSummary; it updates the projection row directly, bumping updatedAt and advancing latestUserMessageAt only for newer user messages.
thread.activity-appended also updates the row directly and only refreshes the shell summary for lifecycle activity kinds that can change it (user-input.requested/resolved, approval.requested/resolved, and their provider failure events). Ordinary streaming activities (commands, deltas, logs) skip the recomputation entirely.
- Proposed-plan and explicit approval/user-input response events keep the full refresh. Every event that mutates
latestTurnId, proposed plans, or pending-approval rows still refreshes, so the gated kinds are exactly the ones the summary derives from.
Client (threadReducer):
- Appending an activity takes a fast path (plain append +
updatedAt bump) only when the current array is known to be reducer-produced and therefore activityOrder-sorted, the event is in order relative to the tail, and its id is unseen. A WeakMap-backed id set keyed by array identity provides both the sortedness proof and O(1) dedup; it moves forward with each append.
- Everything else — snapshot-loaded arrays (DB order), out-of-order arrivals, re-deliveries, resolvable context-window supersession — falls back to the previous filter + re-sort, which repairs ordering once and seeds the index so subsequent in-order appends are O(1).
Tests:
ProjectionPipeline: streaming messages/activities preserve latestUserMessageAt and pending counters; user-input.requested and approval lifecycle kinds still update the pending counts.
threadReducer: out-of-order insertion, re-delivered activity replacement (including right after fast-path appends), and snapshot-order repair (null-sequence rows in DB order get re-sorted before the fast path engages).
Why
Streaming a turn generates a high-frequency stream of thread.activity-appended and thread.message-sent events. Each one previously:
- recomputed the full thread shell summary on the server (queries across messages/activities per event), and
- re-filtered and re-sorted the whole activity array on the client per delta (O(n log n) per event, so O(n² log n) across a long turn).
Both costs grow with thread length and are hottest exactly when the app needs to stay responsive: during active streaming and during reconnect/sync, when the client replays buffered events after resuming a subscription. Making the projection update incremental and the common append O(1) amortized cuts redundant work on both ends without changing any observable state — the regression tests pin the fields the summary refresh used to recompute and the ordering invariant the fast path relies on.
Verification
vp test run apps/server/src/orchestration/Layers/ProjectionPipeline.test.ts: 23 tests pass
vp test run packages/client-runtime/src/state/threadReducer.test.ts: 31 tests pass
- Typecheck passes in
apps/server and packages/client-runtime
- Targeted lint on all four touched files passes
Checklist
- This PR is small and focused
- I explained what changed and why
- I included before/after screenshots for any UI changes (no UI changes)
- I included a video for animation/interaction changes (not applicable)
Note Medium Risk
Changes derived projection fields and client activity ordering invariants; regressions could show wrong pending counts or duplicate/misordered activities, but behavior is heavily regression-tested.
Overview
Cuts hot-path work during streaming by making server projections and client activity updates incremental instead of recomputing on every delta.
Server (ProjectionPipeline): thread.message-sent now patches the thread row directly—updatedAt always advances; latestUserMessageAt only moves forward on newer user messages—instead of calling refreshThreadShellSummary. thread.activity-appended always bumps updatedAt; full shell refresh runs only when activityAffectsShellSummary matches approval/user-input lifecycle kinds (requested, resolved, provider failures). High-frequency tool/progress activities skip the cross-table re-read.
Client (threadReducer): In-order thread.activity-appended events on reducer-owned, sorted activity arrays take a fast path: append + WeakMap-backed id set for O(1) dedup. Out-of-order delivery, snapshot-loaded ordering, context-window supersession, and redeliveries still use filter + sort and rebuild the index.
Tests lock shell summary fields under streaming messages/activities and activity ordering, dedup, and snapshot repair.
Reviewed by Cursor Bugbot for commit 5e23afa. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Make streaming projection and activity appends incremental in thread reducer and projection pipeline
- In ProjectionPipeline.ts, splits
thread.message-sent and thread.activity-appended into dedicated projection cases: user messages advance latestUserMessageAt monotonically, streaming deltas only bump updatedAt, and activities only refresh the shell summary when their kind relates to user-input or approval lifecycle events.
- In threadReducer.ts, adds a
WeakMap-backed id index on activity arrays to enable a fast-path append for in-order activities, skipping full re-sort and dedup scans when the new activity is already sorted at the tail and unseen.
- Out-of-order or duplicate activities still fall back to the full filter/sort path, and the id index is rebuilt after sorting.
- Behavioral Change: streaming assistant deltas no longer trigger shell summary refreshes, reducing server-side work during active streams.
Macroscope summarized 5e23afa.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
mInrOz reacted with thumbs up emoji
coderabbitai
Bot
commented
Aug 14, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Important
Review skipped
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3bcc83ab-8871-4ec8-872b-97592ad05587
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment @coderabbitai help to get the list of available commands.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5b48607. Configure here.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Approvability
Verdict: Needs human review
This PR changes core projection and reducer logic from full refresh to incremental updates for streaming events. While the intent is performance optimization, the change introduces new logic paths and caching mechanisms that alter how thread state is computed - warranting human review of the correctness invariants.
You can customize Macroscope's approvability policy. Learn more.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
mInrOz
commented
Aug 15, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
Data from a self-hosted instance.
Context: t3 0.0.32, Node 24, Linux LXC, measured on 2026-08-15. Our agent
threads run for tens of hours.
Symptom. The server slows down as a thread grows. The projection loop is
serialized, so one large thread delays every thread on the instance.
Measured on the live instance:
- One thread holds 4,655 activity rows with 413 MB of
payload_json in
projection_thread_activities. A second thread holds 4,507 rows with 359 MB.
- One stream produced 67,066
thread.activity-appended events for ~8,000
distinct activity ids. Task-progress ticks account for the difference.
- Only ~30 of the 79,000 activity rows on the instance are user-input
lifecycle kinds. This matches the design of this PR: ordinary streaming
activities can skip the recomputation.
- Retained server traces show
refreshThreadShellSummary spans up to ~8.0 s.
- With the default V8 heap limit, the server died with a heap OOM (SIGABRT)
after 11 h to 125 h. Restart=on-failure hid the crashes. We raised
--max-old-space-size to 32 GB. The crashes stopped, but GC thrash replaced
them: the crash log shows average mutator utilization 0.245 and major GC
pauses of 930–990 ms. The cgroup memory peaked at 42.7 GB.
Modeled, not measured directly:
- We replayed the exact
listByThreadId query and the JSON decode against a
copy of the production database. The replay costs 6.3–10.9 s per event on
the large threads.
- A cumulative model of the 413 MB thread gives ~846 GB of re-reads over its
lifetime. This is a prefix-sum model, not a counter we read.
This PR removes the dominant cost we measured: ordinary activities get a
single-row upsert instead of a full refresh. The reducer fix in
client-runtime also helps us — long threads lag in the UI today.
One related point. Event volume stays quadratic for chatty tools even with
this fix. Each tool.updated payload carries the full accumulated
data.rawOutput. The 180-char truncation applies only to detail.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Aug 15, 2026
This was referenced Sep 1, 2026
Agent comment posted on behalf of @t3dotgg by Claude Fable 5.1.
Thanks for this. Main moved under the branch (#8150 added a shell summary gate, #9032 changed streaming message projection), so I rebased the work and carried it forward in #9152. Your three commits are cherry-picked there with your authorship intact, and the squash merge will carry a Co-authored-by trailer for you. I will close this PR once #9152 merges.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
t3dotgg
added a commit
that referenced
this pull request
Sep 2, 2026
Takes over #6608 by @x1xhlol.
Server: thread.message-sent updates the projection row directly and folds latestUserMessageAt in as a running maximum instead of running refreshThreadShellSummary. Client: thread.activity-appended takes an O(1) append path for in-order, unseen activities on reducer-produced arrays, with a WeakMap id index, and falls back to filter and sort for out-of-order, re-delivered, context-window, and snapshot-loaded cases.
Reducer benchmark: 10,000 in-order appends went from 1,180 ms to 70 ms.
Change authored by Claude Fable 5.1 running in Claude Code, based on work by @x1xhlol.
Co-authored-by: Lucas Valbuena <[email protected]>
Agent comment posted on behalf of @t3dotgg by Claude Fable 5.1.
Merged via #9152 as c2283ce with a Co-authored-by trailer for you. Thanks again for the work.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
henrik092
pushed a commit
to henrik092/t3code
that referenced
this pull request
Nov 2, 2026
…gdotgg#9152)
Takes over pingdotgg#6608 by @x1xhlol.
Server: thread.message-sent updates the projection row directly and folds latestUserMessageAt in as a running maximum instead of running refreshThreadShellSummary. Client: thread.activity-appended takes an O(1) append path for in-order, unseen activities on reducer-produced arrays, with a WeakMap id index, and falls back to filter and sort for out-of-order, re-delivered, context-window, and snapshot-loaded cases.
Reducer benchmark: 10,000 in-order appends went from 1,180 ms to 70 ms.
Change authored by Claude Fable 5.1 running in Claude Code, based on work by @x1xhlol.
Co-authored-by: Lucas Valbuena <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
size:M
30-99 changed lines (additions + deletions).
vouch:unvouched
Author is not yet trusted in the VOUCHED list.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|