What Changed#
Optimizes assistant streaming message projection so streaming deltas are appended directly to the existing projected message instead of forcing the broader thread refresh path for every delta.
The change keeps the persisted message output the same, but avoids repeatedly rebuilding/read-refreshing the full thread state during high-volume assistant streaming.
Why#
Long threads can contain very large numbers of assistant streaming delta events. The old path spent most of its time refreshing thread read-model state after each tiny text delta.
Benchmark from a large production thread:
thread messages: 1,430
thread activities: 9,766
assistant streaming delta events: 165,130
legacy mode: sampled, 500 samples per 10k-event window
OVERALL
optimized: mean 0.0047ms/event, p50 0.0040ms, p90 0.0060ms, p99 0.0113ms
legacy: mean 39.8074ms/event, p50 38.4388ms, p90 46.3055ms, p99 59.6003ms
speedup: mean ~8,555x, p99 ~5,274x
SAMPLE BREAKDOWN
events 1-10,000:
optimized mean 0.0046ms/event, p99 0.0091ms
legacy mean 36.5874ms/event, p99 46.1719ms
events 50,001-60,000:
optimized mean 0.0042ms/event, p99 0.0081ms
legacy mean 36.9265ms/event, p99 44.2846ms
events 100,001-110,000:
optimized mean 0.0044ms/event, p99 0.0114ms
legacy mean 39.9709ms/event, p99 53.0225ms
events 130,001-140,000:
optimized mean 0.0052ms/event, p99 0.0175ms
legacy mean 42.7856ms/event, p99 68.0208ms
events 160,001-165,130:
optimized mean 0.0061ms/event, p99 0.0299ms
legacy mean 41.0519ms/event, p99 62.3399ms
BEFORE
https://github.com/user-attachments/assets/b970931c-12b7-48dd-abb7-6c63a025beb3
AFTER
https://github.com/user-attachments/assets/29be8e47-9480-45c4-a934-016f9a30360b
This keeps the hot path proportional to the incoming delta instead of proportional to the size of the thread.
Checklist#
Note
Fix assistant streaming degradation on long threads by appending deltas in-place#
- Adds an
appendText method to ProjectionThreadMessageRepositoryShape that inserts or concatenates streaming text deltas directly in the DB, preserving existing attachments unless replacements are provided.
- The projection pipeline uses this fast-path for
thread.message-sent events with role=assistant and streaming=true, skipping the previous read-then-write pattern that caused degradation on long threads.
- The
applyProjectsProjection projector also skips refreshing the thread shell summary for streaming assistant deltas.
- Behavioral Change: streaming assistant messages now go through
appendText instead of a full upsert; malformed inputs will now surface as decode errors rather than silently persisting.
Macroscope summarized 7cd48c7.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
a3834e94-3664-438e-b4ca-be536cfa0d07You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
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