GeezerVison is showing github.com — event table bloat from message.updated.1 causes OOM when loading old sessions · Issue #32005 · anomalyco/opencode
event table bloat from message.updated.1 causes OOM when loading old sessions #32005DescriptionDescription
Description
When using explore subagents to read many files in a project, the event table in opencode.db accumulates massive amounts of data from message.updated.1 events during streaming. This causes the database to grow to hundreds of MB, and when reopening the project, the renderer process OOMs trying to load and render all message history.
Environment
- Version: 1.17.4
- Platform: Windows (win32, x64)
- Electron: 42.3.3 / Chrome 148
Steps to reproduce
- Open a project with many files
- Use an explore subagent to deeply scan directories and read many files
- Have multi-turn conversations with the LLM that produce long streaming responses
- Close and reopen the project
Actual behavior
The renderer process crashes with OOM when loading old sessions:
reason: 'oom', exitCode: -536870904
Call stack:
constructMessageRows (session-*.js:9808)
-> MessageTimeline (session-*.js:10264)
-> loadMessages (main-*.js:69910)
Data analysis
A single project session produced:
| Table |
Rows |
Size |
| event (message.updated.1) |
1,381 |
654 MB |
| event (message.part.updated.1) |
4,819 |
13.8 MB |
| message |
358 |
106 MB |
| Total DB |
— |
759 MB |
Each message.updated.1 event stores the full incremental message state during LLM streaming. Over multiple conversation turns with explore subagents touching many files, this accumulates rapidly.
Expected behavior
- Events should store only the final message state, not every incremental update during streaming
- Or old events should be automatically compacted/cleaned up with the 7-day prune
- The database should not require the user to manually delete old sessions to prevent OOM
Workaround
Manually delete old sessions and WAL files:
opencode session delete <sessionID>
Remove-Item "$env:USERPROFILE\.local\share\opencode\opencode.db-wal"
But this is not a sustainable solution for daily use.
Plugins
No response
OpenCode version
No response
Steps to reproduce
No response
Screenshot and/or share link
No response
Operating System
No response
Terminal
No response Reacted by Ingo Kegel and Mikhail Shchedrin Activitygithub-actions commented on Jun 12, 2026 This issue might be a duplicate of or related to existing issues. Please check:
RORHITD commented on Jun 14, 2026 Following up on my own comment — I queried my actual DB and traced the code more carefully. My first take (assistant streaming) was wrong on both the role and the mechanism; here's what's actually going on.
Breaking my ~16GB event table down:
| event |
rows |
total |
message.updated.1 (role=user) |
700 |
16,091 MB |
message.part.updated.1 |
4,679 |
16 MB |
message.updated.1 (role=assistant) |
1,773 |
1 MB |
~100% of each big user row is info.summary.diffs. The single biggest row was 180 MB holding 16,609 diff entries (all distinct files), each with a full-file patch.
Mechanism:
SessionSummary.summarize (packages/opencode/src/session/summary.ts) sets target.info.summary = { ...summary, diffs } on the user message and calls sessions.updateMessage(target.info). It's triggered both at turn start (prompt.ts:1304, if (step === 1)) and on every step-finish (processor.ts:745, forked) — so a multi-step agentic turn re-runs it repeatedly.
computeDiff → snapshot.diffFull(from, to) does git diff --numstat from to -- . (gitignored files are filtered out), then builds the patch for each remaining file via structuredPatch(..., { context: Number.MAX_SAFE_INTEGER }) from the diff lib — i.e. the entire file body per patch. There's no cap on patch size or entry count (the only size guard, a 2 MB limit, applies to untracked-file snapshotting, not the emitted patches). Snapshots are worktree-global (Session summary/diff is worktree-global (not session-scoped) causing cross-session attribution #11802), so a span that touches generated/build trees that aren't gitignored yields thousands of full-file patches → the 180 MB.
MessageUpdated is a sync/durable event (packages/core/src/v1/session.ts: sync: { aggregate: "sessionID", version: 1 }), so commitSyncEvent (packages/core/src/event.ts) inserts the full encoded info — diffs inline — into event.data. It's append-only (new seq/row per publish, no onConflictDoUpdate on EventTable). The MessageTable projection is upserted to a single row, but the event log isn't — so each re-summarize appends another fat row. Hundreds of those = the 16GB.
Net: a worktree-wide, full-file diff is re-serialized into the durable event log every time the user message is summarized. The read tables already hold the latest copy, so the diffs arguably don't need to be in the append-only event at all.
Two fix directions (happy to PR either, with before/after numbers):
- Bound
computeDiff at the source — also exclude common generated/vendor paths (not just gitignored) and cap per-file/total patch bytes, storing {file,status,additions,deletions} with patch omitted past the cap (FileDiff.patch is already optional and consumers tolerate it). Fixes every downstream copy at once. (Session summaries should cap or filter huge generated/vendor diffs in message.data.summary.diffs #30165 asked for a cap/filter here and was closed not-planned — would a bounded version be acceptable?)
- Keep diffs out of the durable encode — still deliver
summary on the live notify path (the app sync reducer reads info.summary.diffs and the TUI consumes the whole info, so it can't just be dropped), but exclude it from the stored EventTable payload, since reads/replay come from the message tables. Structural backstop regardless of diff size. (Related: [FEATURE]: Store per-message diffs separately and lazy-load them #16741, store per-message diffs separately + lazy-load.)
Could a maintainer confirm which direction fits — bound-at-source, exclude-from-durable-encode, or both? KirillDeviatka commented on Aug 6, 2026 Additional Jetsam evidence + workaround
Hit the same class of failure on macOS (128 GB) on 2026-08-06:
- long multi-step local-model session
- single user message ~136 MB almost entirely
info.summary.diffs (included a vendored .node-runtime/ tree that was not gitignored)
- that session alone ~6.2 GB of
message.updated.1 rows (47 events >100 MB)
opencode RSS ~87 GiB → Jetsam; Electron renderer for the UI shell also climbed to ~5–8 GiB
- disk-write diag: opencode dirtied ~34 GB via SQLite WAL checkpoint
Canonical part rows for the same session were only ~7.5 MB — so this is summary.diffs × append-only event fanout, not tool-output.
Local workaround (plugin, not a core fix)
https://github.com/KirillDeviatka/opencode-session-diff-spill
Caps/denies vendor+huge diffs in experimental.chat.messages.transform, spills fat message.updated payloads, plus an offline DB sanitizer. Cannot stop SessionSummary write-path or durable event encode — that still needs engine changes (bound computeDiff/diffFull, and omit full summary.diffs from durable message.updated.1).
Happy to test a PR against this session shape if useful. added a commit that references this issue on Aug 6, 2026This issue will close once commit 0ff0ad8 is merged into the 'dev' branch.0ff0ad8 neriousy commented on Oct 1, 2026 Closing as a duplicate of #33356, which tracks the event table in opencode.db growing without bound. Please add your measurements there.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|