perf(server): skip full-message reads while streaming #9032
main fromrefs/pull/9032/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubEach 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.
Related work#
| PR | Credit and outcome |
|---|---|
| #5651 by the T3 Code bot | This PR uses its atomic SQLite append idea. It does not include the transaction, startup, thread, or turn changes from that PR. |
| #6608 by @x1xhlol | Its server shell-summary scan idea is already on main. Its client activity cache is separate from this change. |
| #6613 by @patroza | Its selective activity-read idea is already on main. |
| #8993 and #8995 by @rcawston | We 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 --checkpassed
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).
Note
Skip full-message upserts during streaming via appendStreaming in projection pipeline#
- Adds
appendStreamingto theProjectionThreadMessageRepositorythat inserts withis_streaming=1and, on conflict, concatenates incoming text to existing text while preservingcreated_atand prior attachments. - Routes
thread.message-sentevents withstreaming=trueinProjectionPipelinetoappendStreaminginstead ofupsert, avoiding full-message overwrites on every chunk. - On non-streaming (final) events, the projector finalizes the row via
upsertwithisStreaming=false, replacing text unless the incoming text is empty, and preservingcreatedAtfrom the prior row. - Behavioral Change: streaming events no longer overwrite the full message row — text is appended incrementally and
isStreamingstays1until the completion event arrives; existing tests in ProjectionPipeline.test.ts and ProjectionThreadMessages.test.ts are updated to cover this.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved at
36124a0Macroscope'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).t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
8b033de· PR result:36124a0· Source CI: successScenario 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.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.