Skip to content

[Bug]: Paragraph streaming stores every full reasoning snapshot as a permanent event (OpenCode: 93k rows, 2.2 GB in one day) #23365

Open

Description

@vifar

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Related: #20443 (closed; asked for database growth from a live OpenCode session), #21154 (closed; asked for a new issue covering only the turn-item.updated / OpenCode per-chunk part), #19780 and #20990 (compacting intermediate turn-item snapshots after the fact).

Area

apps/server

Steps to reproduce

  1. Leave responseStreamingMode at its default, "paragraph".
  2. Run OpenCode threads on a model that writes long reasoning (we used local models served through Ollama).
  3. On a copy of statev2.sqlite, count streamed reasoning snapshots per item:
SELECT json_extract(payload_json, '$.id') AS item,
       count(*) AS streaming_rows,
       sum(length(payload_json)) AS bytes
FROM orchestration_events
WHERE event_type = 'turn-item.updated'
  AND json_extract(payload_json, '$.type') = 'reasoning'
  AND json_extract(payload_json, '$.streaming') = 1
GROUP BY item
ORDER BY bytes DESC;

Expected behavior

The durable event log stores a bounded number of rows for a streamed reasoning item, so its storage cost grows roughly with the final text length, not with its square.

Actual behavior

In paragraph mode, makeAssistantStreamingFilter (apps/server/src/orchestration-v2/assistantStreaming.ts) passes one streaming turn_item.updated snapshot per item at most every 400 ms, whenever a new paragraph is ready. RunExecutionService hands each passed event to ProviderEventIngestor.ingestNormalized, so each snapshot becomes a permanent turn-item.updated row holding the full cumulative text. A reasoning block that streams for several minutes writes hundreds of rows, each larger than the last.

Measured read-only on a copy of one macOS install's statev2.sqlite (about 24 GiB, 3.76 M events), for one day (2026-10-20 UTC) in paragraph mode:

provider / item type items streaming rows payload
opencode / reasoning 5,656 93,095 2,188 MB
opencode / assistant_message 14,581 2,781 28 MB
claude / reasoning 4,769 833 8 MB
codex / assistant_message 1,976 441 5 MB
codex / reasoning 969 3 2 MB
  • OpenCode reasoning averaged 17.5 turn-item.updated rows per item that day. Every other provider and item type stayed at 1.22 or less.
  • The largest single item was one reasoning block: 612 rows, 69 MB. The next four were 448 rows (50 MB), 484 (43 MB), 416 (36 MB) and 392 (33 MB).
  • The top 10% of streamed OpenCode reasoning items hold 86% of those bytes. p50 final reasoning length was about 1.7 k characters and p99 about 77 k.
  • Total event payload that day was 2.78 GB, against 0.5 to 1.2 GB on other days.
  • After switching the same install to responseStreamingMode: "turn", the next day stored 0 streaming reasoning rows and 0.6 GB of event payload in total.

The 400 ms throttle decides how many rows are stored. The gap between consecutive stored snapshots of one item was p10 0.43 s, p50 0.53 s, p90 0.99 s. So adapter-side delta coalescing at the 50 ms interval the Claude, Codex and ACP adapters use would not change the stored row count. OpenCode stands out because its reasoning streams long and in many paragraphs. It is not because those adapters persist less. Claude reasoning goes through the same filter but is short, so it stays small.

Background compaction (#19435) does not remove these rows, because turn-item.updated is outside its scope (#19780). #20990 would remove them on a later pass, but they are still written: on this install, 2.2 GB a day of writes on the single writer connection, then the page churn.

assistantStreaming.ts, the OpenCode v2 adapter's text path and ProjectionMaintenance.ts are unchanged in this respect between v0.1.1 and main at a49d18c.

Impact

Major degradation or frequent failure

Version or commit

v0.1.1 (desktop); the code paths above are unchanged on main at a49d18c.

Environment

macOS, T3 Code desktop v0.1.1, OpenCode provider with local Ollama models, plus Claude and Codex on the same install for comparison.

Logs or stack traces

2026-10-20 UTC, turn-item.updated, type in (reasoning, assistant_message)
opencode   reasoning          items 5656  rows 98751  streaming rows 93095  payload 2188 MB
opencode   assistant_message  items 14581 rows 17362  streaming rows 2781   payload 28 MB
claude     reasoning          items 4769  rows 5602   streaming rows 833    payload 8 MB
codex      assistant_message  items 1976  rows 2417   streaming rows 441    payload 5 MB
codex      reasoning          items 969   rows 972    streaming rows 3      payload 2 MB
gap between stored streaming snapshots of one opencode reasoning item: p10 0.429 s, p50 0.531 s, p90 0.989 s (n = 89,568)

Counts and sizes only. No thread content was read beyond $.id, $.type and $.streaming.

Workaround

Set responseStreamingMode to "turn". That stops live paragraph streaming for every provider. On this install it brought streaming reasoning rows to zero and daily event payload from 2.78 GB to 0.6 GB.

Possible directions for maintainers to choose from (no PR opened, since this changes how streamed text is persisted):

  1. Deliver intermediate streaming snapshots to live clients without making each one a durable event. Store only the first snapshot (for item position) and the final one.
  2. Bound intermediate persistence per item, for example a minimum interval that grows with text length, or a byte budget per item.
  3. Land the compaction in fix(server): compact superseded turn-item snapshots #20990 so these rows are at least removed after a pass. That bounds what is retained but not what is written.

Activity

  1. jason5545 commented on Oct 26, 2026

    @jason5545
    Contributor

    A related symptom of the same paragraph gate, for reasoning: a model that thinks in one unbroken paragraph shows no thought at all until it ends. splitBufferedAssistantText finds no boundary, so makeAssistantStreamingFilter passes nothing while the item streams.

    Checked with Node against assistantStreaming.ts on main @ f88b33a, feeding a reasoning item one sentence every 500 ms for 30 s:

    • one paragraph, 6,060 characters: 0 snapshots passed while streaming
    • the same text with a blank line every five sentences: 12 snapshots

    We hit it with local models run through a Pi-based CLI: the thought box stayed empty for the whole thought.

    Our fork passes reasoning's whole text on the existing 400 ms gate instead of waiting for a boundary, and keeps paragraph buffering for assistant text (assistantStreaming.ts). That runs straight into this issue's cost: every 400 ms of streamed reasoning becomes another full-text row, for every provider, so it is not something to upstream as is.

    #24700 keeps the paragraph gate, so it does not change this. Its growth rule might: if reasoning snapshots passed on growth alone (each at least a set fraction longer than the last one passed), a one-paragraph thought would stream live and its stored snapshots would still stay within a few times the final text.

  2. joei4cm commented on Nov 12, 2026

    @joei4cm
    Contributor

    Per CONTRIBUTING's prior-approval rule, a scope proposal before anyone opens a PR here.

    #24700 implemented direction 2 — once a streamed item passes 8,000 characters, a snapshot is stored only when its text is at least 25% longer than the last stored one, so past that point stored snapshots grow geometrically instead of with the square of the text. Macroscope approved it at 62bb46d; it was then closed at @StiensWout's request because it intentionally changes paragraph streaming and interrupted-stream durability and had no prior scope agreement.

    If direction 2 is the one you want, I'd like to take it over: rebase the same rule onto the current filter (#24432 landed yesterday and rewrote these lines), keep the constants as proposed there (8,000-character threshold, 1.25 growth), and re-run its tests — the long-stream bound test fails on main today. The two decisions listed on that PR still need your call:

    • apply the rule to assistant messages too, not only reasoning (the filter treats both the same; reasoning-only is a one-line condition);
    • when a stream ends without its final event (server restart, Stop after the session died), a long item settles from its last stored snapshot — up to about a fifth of its text lost, against one paragraph today.

    If you would rather have direction 1 — live delivery without durable intermediate events — that needs a non-durable path through the live stream and its resume cursors, a larger change I would want to scope with you first.

    No PR until a direction is confirmed on this issue.

  3. joei4cm commented on Nov 13, 2026

    @joei4cm
    Contributor

    Thanks for picking this one up — #36362 covers it far more thoroughly than my proposal would have, so I'm dropping mine and staying out of the way.

  4. sk1gl4a commented on Nov 20, 2026

    @sk1gl4a

    Another data point for this issue, from a different provider path: Mistral Vibe over ACP (acpRegistry driver, vibe-acp 3.1.1), running open-weight models with visible reasoning (deepseek-v4-1-flash, zai-glm-5-3-flash) in long autonomous orchestration. T3 Code 0.1.10 desktop, macOS (Intel), responseStreamingMode at its default "paragraph".

    Setup

    One orchestrator thread per project. A launchd script starts worker threads with t3 thread start (up to 3 at once) and wakes the orchestrator with t3 thread send when they finish. Nobody watches the UI. On 2026-11-20 it started 276 worker threads.

    These models stream all of their reasoning, and T3 stores it the same way as reasoning from any other provider: every passed snapshot of a reasoning item is a permanent turn-item.updated row with the full text so far. Nothing compresses or caps these rows while the run is going. With many long reasoning blocks spawned by an orchestrator, statev2.sqlite grew to 13.9 GB in one day and the disk hit 0 bytes free twice.

    Numbers (read-only, on the live database)

    • orchestration_events: 337,557 rows, 10.7 GB of payload_json.
    • turn-item.updated: 156,873 rows, 10.5 GB, which is 98% of all event payload.
    • By item type: reasoning 10.3 GB, command_execution 127 MB, file_change 28 MB, assistant_message 9 MB.
    • Two reasoning items hold 96% of it:
    item model rows stored largest row duration
    1 deepseek-v4-1-flash 3,056 5.28 GB 3.5 MB 24 min
    2 zai-glm-5-3-flash 3,308 4.84 GB 3.0 MB 26 min

    The next largest item in the whole database is 14 MB.

    For item 2 I checked every row in order: in 3,307 of 3,307 consecutive pairs the earlier text is a prefix of the later one. The text grew by a median of 887 bytes per row (p90 1,275), about one row every 0.48 s, so each ~0.9 KB of new reasoning wrote the whole accumulated text (up to 2.9 MB) again. Stored bytes grow with the square of the text length, as described above.

    Both items are degenerate reasoning loops: the model repeats its own plan without calling a tool. Item 1 ran until its turn ended on its own; item 2 ran until we killed the agent process. Item 1's final text is one 316-character block repeated about 11,000 times (compresses 217:1); item 2's compresses 119:1. That happened in 2 of the 276 runs that day. Each time, a single turn wrote about 5 GB in under half an hour.

    Why the existing cleanup does not save the disk

    ProjectionMaintenance.pruneEventStore keeps at least RETAINED_EVENT_HISTORY (1 day) of events. Then DatabaseStorage.reclaim returns at most 1,024 pages (4 MB) per minute through incremental_vacuum, so 5 GB takes about 22 hours to go back to the OS. The rows are written in minutes. During long autonomous orchestration, space runs out much faster than the cleanup gives it back.

    What would help

    • The storage fix in fix(server): a streamed reply or reasoning block no longer stores every snapshot of its text #36362 (keep only the newest streaming snapshot of an item) would turn each of these items from about 5 GB into about 3 MB.
    • A size cap for one streaming item: past some length (say 1 MB of text), stop storing intermediate snapshots and keep only the final one. A reasoning item that large is almost always a loop.
    • Optionally, pause new runs or warn when free disk falls below a threshold.

    Workaround we are trying

    projectSettingsOverrides.<projectId>.responseStreamingMode: "turn" for the autonomous projects only, so interactive threads keep live streaming. The server picked the change up without a restart. I will add a follow-up once it has run for a day.

  5. sk1gl4a commented on Nov 21, 2026

    @sk1gl4a

    Follow-up, about 26 hours after the change.

    Since 2026-11-20 21:30 UTC, responseStreamingMode is "turn" for our four autonomous projects through projectSettingsOverrides. Interactive projects still stream. The same orchestration kept running the whole time: 595 new threads up to 2026-11-21 22:47 UTC, up to five workers per orchestrator.

    The disk problem is gone for us. Read-only numbers from the live statev2.sqlite, turn-item.updated rows of type reasoning written after the change:

    streaming rows largest row
    false 40,499 3.1 MB
    true 27 1.1 MB

    The 27 streaming rows come from two threads and add up to 8.8 MB.

    The models still fall into reasoning loops now and then. Seven final reasoning rows are larger than 1 MB, the biggest is 3.1 MB. On 2026-11-20 a loop of about that size wrote about 5 GB in paragraph mode. In turn mode T3 writes it once.

    Across all event types, orchestration_events now holds 532,465 rows and 904 MB of payload_json for 2026-11-18 to 2026-11-21. The database file is 3.9 GB, down from 13.9 GB. We deleted the old intermediate snapshots by hand once, and T3 gave the rest of the space back on its own. Free disk on the machine is 21 GB.

    The cost is that these projects show reasoning only when a turn ends. For runs nobody watches, that is fine.

    Separately, tonight we turned reasoning off for deepseek-v4-1-flash in these projects with thinking = "off" in the project's .vibe/config.toml. We did that for answer quality, not for T3, but it also means most of those turns write no reasoning item at all.

    I'd still like #36362 or a per-item size cap upstream. The override only helps someone who has already lost a disk and then found this issue.

  6. joei4cm commented on Nov 21, 2026

    @joei4cm
    Contributor

    Two data points, and the second is the one still open.

    The turn-mode numbers confirm the workaround: one row per item instead of one per snapshot is what takes 13.9 GB down to 3.9 GB, and 40,499 streaming=false rows against 27 streaming=true rows show that shape directly.

    On the two upstream asks — they cover different halves, and your own numbers split them:

    • fix(server): a streamed reply or reasoning block no longer stores every snapshot of its text #36362 bounds how many rows one item keeps. In paragraph mode that turns a 5 GB item into two rows (one streaming, one final), which lands at the same order as your turn-mode result. In turn mode there is already exactly one row per item, so it changes nothing there.
    • A per-item size cap bounds how large one row can be, which is the part still open: your seven final rows above 1 MB, the largest 3.1 MB, are stored in full.

    There is no such cap in the tree today. The reasoning turn item's text is a plain Schema.String with no maxLength (packages/contracts/src/orchestrationV2.ts), the streaming filter applies no byte guard (apps/server/src/orchestration-v2/assistantStreaming.ts), and appendAgentEvents writes the payload through without one (apps/server/src/persistence/OrchestrationEventStore.ts). A single reasoning item is stored at whatever length the model produced, so the same 3.1 MB row is written with or without #36362.

    #36362 itself is open and mergeable with 22 green checks. Its remaining gate is Macroscope's "Needs Human Approval" on a replay-ordering question when reasoning and message updates interleave — it is waiting on that, not on further code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions