Repository navigation
Description
Short description
Small auto-search decisions rewrite large session_meta rows
What problem does this solve?
Auto-search saves a decision for a new prompt with or without a hint. The runner saves the decision synchronously on the plugin thread. The UPDATE changes only the decision column. When its length changes, SQLite can write the full row to the write-ahead log (WAL). This writes pages with unrelated data.
The largest rows in one database held most of their data in merged_reasoning_stripped_ids. The append path does not limit or prune these replay entries during a session. Of 13,255 metadata rows, 35 held 256 KiB or more of column values and five held 1 MiB or more. In a replay on wide rows, 120 hint decisions wrote 190 MB to the WAL. Linux throttled some writes to limit dirty pages in memory. This can stall prompt processing without a SQLite lock wait.
Reproduce on v0.49.119 (4d4bded91):
- Make a database with the plugin schema. Seed one
session_metarow with 32,000 synthetic assistant IDs and 8,000 frozen part decisions inmerged_reasoning_stripped_ids. - Disable WAL auto-checkpoints and truncate the WAL. Make one call to
appendAutoSearchHintDecisionwith a newno-hintdecision. Read back the decision and measure the WAL file size increase. - Run the test again with a new database and an empty stripped-ID set. Use the same decision and a limit of 64 KiB for the two cases.
With Bun 1.4.5, SQLite 3.54.1, and schema 95, the wide row added 2,459,672 bytes of WAL, above the limit. The control added 4,152 bytes, below the limit. The test checks bytes, not time.
Proposed solution
Store hint decisions in their own small table or row. This lets the plugin write a new decision without a rewrite of the larger row. A different option is to limit or compact merged_reasoning_stripped_ids. Keep the decisions necessary to replay the same prompt. Move fields that change size frequently out of wide metadata rows. Keep the stored hint and no-hint results stable across restarts.
Area
OpenCode plugin
Additional context
Related: #864 (WAL checkpoint cost inside main-thread commits). This report is about the size of each write, not the checkpoint.
I can send a PR with the WAL regression test and replay checks when the issue has the design-approved label.
AI helped write this draft.
Activity
magic-alfonso commentedon Dec 6, 2026
Confirmed from the code, both parts.
appendAutoSearchHintDecisionrewrites the wholeauto_search_hint_decisionsarray insession_metafor every new prompt, on the plugin thread, and the array is never pruned.addMergedReasoningStrippedIdsappends tomerged_reasoning_stripped_idsin the same row without a bound (the placeholder ids next to it are capped; these are not). So the row grows for the life of the session, and every size-changing write to it puts the whole record in the WAL. Migration 94 fixed the same thing for the last-good prefix and the trailing-blank decisions; these two columns were left behind.Thank you for the byte-based reproduction. Measuring WAL growth instead of time is the right test for this, and we will keep it.
Two things before a design answer:
session_replay_decisions(one small row per message, from migration 94) and pruning. Which of the two fits depends on point 2.session_meta, and the row also carries other large values. Before choosing, we want the WAL bytes per ordinary pass on a typical row and on a wide one, by column, and for each of the two columns the answer to "which entries can never be read again" on each host (entries for messages behind the history cut look removable, but a revert across a checkpoint has to be checked).We run that now and come back here with the design and the conditions for a PR. Please hold the PR until then; your WAL regression test is wanted either way.
magic-alfonso commentedon Dec 6, 2026
Correcting my earlier reply: I wrote that the hint-decision array is never pruned. That is wrong.
pruneAutoSearchHintDecisionsand the queue beside it (storage-meta-persisted.ts, about lines 1884-1980) already remove decisions for messages that a history summary removed or the host deleted, on a pass that may rebuild, and drop the oldest hidden no-hint entries above 2,000. What has no such rule ismerged_reasoning_stripped_ids, and that is where your wide rows come from.We measured the row (script and numbers are ours to keep with the fix; one session row at three widths, auto-checkpoint off, WAL truncated before each write):
So the hint decision is one of about thirty writes that put the whole record in the WAL when a length changes, an integer crossing an encoded width included. Moving only the hint decisions out would leave the other twenty-nine. What makes a row pathological is its width, and the unbounded part of the width is the merged-reasoning list.
What we will not do on this line
session_replay_decisions. We tried it against the real readers: the strict full reader throws on a row it cannot parse, and the clone path calls it before filtering by message id; writing a clone's replay document deletes every row of the session; a row of any kind counts as "previously managed" evidence. Released versions read that table the same way, so rows of another kind are not safe next to them.The design: bound the merged-reasoning list by the same rule the hint decisions already have
merged_reasoning_stripped_idsfor those messages are queued for removal, at the same point and from the same set of removed ids as the hint retirement (queueAutoSearchHintDecisionRetirement), and flushed on a pass that has rebuild permission, keeping any id that is visible again at the flush. One retirement path for both lists, not a second mechanism.__merged_reasoning_parts_v1__entry for that assistant. Every other string in that column stays untouched:binding_mismatch:,compaction_off_thinking:, the@tool-sweepmarkers, the signed-fit refusal marker,pi-content-replay-v1:entries. A test lists every prefix the column can hold and fails on an unknown one, so a new kind cannot be pruned by accident.What this does not fix, and the release notes will say so: every length-changing write still logs the record including the cached history head (about 180 KB on a typical session, 250 KB for a pass with a new prompt). Taking the head out of the record needs a schema change, which this line does not get.
design-approvedfor this shape. The usual rules apply: reference this issue without a closing keyword, and the PR goes through an independent review, because the replay state for reasoning is the part of the plugin where a missing entry can cost a rejected request.