Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): skip full-message reads while streaming #9032

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/9032/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Each streaming message chunk read the current projected message into Node, joined the text, and wrote the full accumulated message back to SQLite. This added one query per chunk and copied more text as the message grew.

This change gives streaming messages a dedicated repository operation. SQLite appends each delta during the upsert. It preserves the original creation time and keeps existing attachments when the event omits attachment data. Empty attachment arrays still clear attachments. Completed messages keep the existing replace-or-preserve behavior.

Buffered delivery remains the default, so most turns do not use this path often. The change mainly helps configurations that still emit many message deltas.

This only changes the shared server projector. It does not change clients, providers, contracts, migrations, or transport.

PRCredit and outcome
#5651 by the T3 Code botThis PR uses its atomic SQLite append idea. It does not include the transaction, startup, thread, or turn changes from that PR.
#6608 by @x1xhlolIts server shell-summary scan idea is already on main. Its client activity cache is separate from this change.
#6613 by @patrozaIts selective activity-read idea is already on main.
#8993 and #8995 by @rcawstonWe reviewed both proposals. The SQL count rewrite is not needed here, and main no longer reads all activities on this path.

The related server scan fixes landed through #8150 and #8988.

We also reviewed adjacent stream work in #5344 by @danvernon, #8309 by @lnieuwenhuis, #6004 by @cheruvian, #4349 by @nateEc, and #4794 by @t3dotgg. Those PRs change client batching, provider progress events, Markdown render timing, or native iOS transport, so they stay separate.

Verification

  • 98 tests passed across the message repository, projection pipeline, provider ingestion, and orchestration engine test files
  • server typecheck passed
  • targeted lint and format checks passed
  • git diff --check passed

Made with GPT-5.6 Sol in the Codex harness through T3 Code.


Note

Medium Risk Changes core projection persistence for assistant streaming messages; incorrect append or completion logic could corrupt message text or attachment state, but scope is limited to the server projector and is well covered by tests.

Overview Streaming thread.message-sent events no longer load the full projected message into Node to concatenate text on each chunk. The thread-messages projector now calls a new appendStreaming repository path that upserts with SQLite text || excluded.text, keeps is_streaming set, and uses COALESCE so omitted attachment payloads preserve existing JSON while an explicit empty array still clears attachments.

Non-streaming completion events still upsert: text is replaced unless the payload text is empty (then prior text is kept), and is_streaming is always written as false with created_at taken from the existing row when present.

Tests cover repository append behavior and extend the projection-pipeline resume scenario with streaming chunks plus a final completion event (asserting merged text, timestamps, and is_streaming).

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 36124a05b72b9426393735514d850f83b327825e. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Skip full-message upserts during streaming via appendStreaming in projection pipeline

  • Adds appendStreaming to the ProjectionThreadMessageRepository that inserts with is_streaming=1 and, on conflict, concatenates incoming text to existing text while preserving created_at and prior attachments.
  • Routes thread.message-sent events with streaming=true in ProjectionPipeline to appendStreaming instead of upsert, avoiding full-message overwrites on every chunk.
  • On non-streaming (final) events, the projector finalizes the row via upsert with isStreaming=false, replacing text unless the incoming text is empty, and preserving createdAt from the prior row.
  • Behavioral Change: streaming events no longer overwrite the full message row — text is appended incrementally and isStreaming stays 1 until the completion event arrives; existing tests in ProjectionPipeline.test.ts and ProjectionThreadMessages.test.ts are updated to cover this.
Macroscope summarized 36124a0.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.2 KiB13.5 KiB+220 B (+1.6%)15.1 KiB✅
      CodexThread snapshot wire6.9 KiB6.9 KiB+6 B (+0.1%)7.3 KiB✅
      CodexLive turn WebSocket wire6.3 KiB6.6 KiB+214 B (+3.3%)7.8 KiB✅
      CodexLive turn WebSocket decoded55.5 KiB57.0 KiB+1.5 KiB (+2.7%)66.4 KiB✅
      CodexLive turn messages810+2 (+25.0%)21✅
      ClaudeTotal thread wire13.4 KiB13.5 KiB+4 B (+0.0%)15.1 KiB✅
      ClaudeThread snapshot wire6.9 KiB6.9 KiB+11 B (+0.2%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.6 KiB6.6 KiB−7 B (−0.1%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded57.8 KiB57.8 KiB0 B (0.0%)66.4 KiB✅
      ClaudeLive turn messages10100 (0.0%)21✅

      Baseline: 8b033de · PR result: 36124a0 · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 109.4 KiB
      • Claude decoded thread snapshot: 110.1 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    3. Approvability

      Verdict: Approved at 36124a0

      Macroscope's review found this PR approvable — This is a narrowly scoped server-side projection optimization that appends streaming deltas in SQLite while preserving completion, attachment, timestamp, and streaming-state behavior. It adds no product-default change, static-analysis override, schema migration, or user-facing capability, and the affected path has focused coverage.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).

Sign in to join this conversation.