High memory usage and database bloat in long-running OpenCode instances #16729
Copy link
Copy link
Closed as not planned
Closed as not planned
Copy link
Labels
coreAnything pertaining to core functionality of the application (opencode server stuff)Anything pertaining to core functionality of the application (opencode server stuff)perfIndicates a performance issue or need for optimizationIndicates a performance issue or need for optimization
Description
Description
A long-running OpenCode server instance (2+ days) consumes 1.76 GB (602 MB RSS + 1.15 GB swap) on an 8 GB system. The SQLite database grows to 1.99 GB with no automatic cleanup — 1,706 sessions spanning 53 days, 274K parts (1.49 GB) never pruned.
Root causes identified:
- No data retention — sessions are only soft-archived, never deleted
- auto_vacuum = OFF — deleted data never reclaims disk space
- No periodic WAL checkpoint — WAL file grows unbounded during long sessions
- Compaction marks parts but keeps full data — dead weight in SQLite
- Bash tool output accumulates unboundedly — verbose commands can grow to hundreds of MB in the output string
- Edit tool Levenshtein uses O(n×m) matrix — can spike to ~400 MB for 10K char strings
- FileTime per-session tracking never pruned — slow memory leak over instance lifetime
- RPC pending map has no timeout — orphaned promises leak if workers die
- LSP diagnostics Map grows monotonically — empty entries never deleted
Measured metrics:
| Metric | Value |
|---|---|
| Main process RSS | 602 MB |
| Main process swap | 1.15 GB |
| Peak RSS (VmHWM) | 1.64 GB |
| SQLite DB size | 1.99 GB |
| DB parts table | 1.49 GB |
| Sessions | 1,706 (never auto-deleted) |
| auto_vacuum | OFF |
Plugins
No plugins
OpenCode version
0.1.44 (dev build)
Steps to reproduce
- Run
opencode serveon a machine with 8 GB RAM - Use it actively for 2+ days with multiple worktrees
- Monitor RSS with
ps auxor/proc/<pid>/status— memory grows monotonically - Check
opencode.dbfile size — grows without bound since archived sessions are never deleted
Screenshot and/or share link
N/A
Operating System
Ubuntu 22.04 (Linux x86_64, 8 GB RAM, 16 GB swap)
Terminal
N/A (headless server mode via opencode serve)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
coreAnything pertaining to core functionality of the application (opencode server stuff)Anything pertaining to core functionality of the application (opencode server stuff)perfIndicates a performance issue or need for optimizationIndicates a performance issue or need for optimization
Activity
github-actions commentedon Mar 9, 2026
This issue doesn't fully meet our contributing guidelines.
What needs to be fixed:
Please edit this issue to address the above within 2 hours, or it will be automatically closed.
This issue might be a duplicate of existing issues. Please check:
If you believe this was flagged incorrectly, please let a maintainer know.
binarydoubling commentedon Mar 9, 2026
Went ahead and tagged you up, this needs more attention and there's a lot to be done. Had my poor MacBook crash way too many times.
github-actions commentedon Mar 9, 2026
This issue has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.
Feel free to open a new issue that follows our issue templates.
BYK commentedon Mar 9, 2026
Reformatted to match the bug report template. Reopening.
jnorthrup commentedon Mar 21, 2026
Comprehensive Memory Analysis - Related Findings
Your analysis of long-running OpenCode instances is extremely thorough. We found similar patterns in Bun runtime investigation.
Confirmed Leak Sources (Matching Our Findings)
Your identified sources align with our JSC GC investigation:
Additional Context
Hardware Risk: On Apple Silicon Macs, memory exhaustion leading to kernel panic → forced power cycle → potential SOC damage (non-replaceable, $500-1500 hardware loss).
Our Investigation
We built an ASAN tracker that identified 4 unique JSC GC leaks:
Cross-Project Issue
This affects all WebKit-based runtimes. We're coordinating upstream:
Your 8 root causes + our 4 JSC GC leaks = comprehensive picture of WebKit memory issues.
jnorthrup commentedon Mar 21, 2026
🚨 URGENT: Cross-Project Memory Leak Crisis - Hardware Damage Risk
We investigated memory leaks across WebKit-based runtimes (Bun, Claude Code, OpenCode) and found a critical pattern affecting all embedders.
Hardware Risk Statement
On Apple Silicon Macs:
On Linux servers:
Our Investigation Findings
Bun Runtime (WebKit JSC):
JSC::SlotVisitor::drainFromSharedrace condition (7,214 frames)WTF::HashTable::removeIterator(7,214 frames)WTF::Vector<>::operator=(7,220 frames)JSC::ASTBuilder::createForOfLoop(713 frames)OpenCode (from your issues):
Common Root Cause
WebKit JavaScriptCore parallel GC marking phase:
SlotVisitor::drainFromSharedUpstream References
Tool We Built
We created
test/asan_tracker.zig(760 lines) that:Happy to share this tool with OpenCode maintainers.
Urgency: Auto-Close Bot Pattern
We observed issues #17837 and #17185 were closed by github-actions bot within 2 hours for "contributing guidelines" - despite containing:
This pattern is dangerous for memory safety issues:
Recommended Actions
Immediate:
perfandbuglabelsShort-term:
Long-term:
Cross-Project Coordination
We're coordinating with:
Memory leaks don't respect project boundaries - this is an ecosystem-wide crisis.
Evidence:
Please prioritize this over formatting requirements.
jnorthrup commentedon Mar 21, 2026
🚨 URGENT: Cross-Project Memory Leak Crisis - Hardware Damage Risk
We investigated memory leaks across WebKit-based runtimes (Bun, Claude Code, OpenCode) and found a critical pattern affecting all embedders.
Hardware Risk Statement
On Apple Silicon Macs:
On Linux servers:
Our Investigation Findings
Bun Runtime (WebKit JSC):
JSC::SlotVisitor::drainFromSharedrace condition (7,214 frames)WTF::HashTable::removeIterator(7,214 frames)WTF::Vector<>::operator=(7,220 frames)JSC::ASTBuilder::createForOfLoop(713 frames)OpenCode (from your issues):
Common Root Cause
WebKit JavaScriptCore parallel GC marking phase:
SlotVisitor::drainFromSharedUpstream References
Tool We Built
We created an ASAN tracker (760 lines of Zig) that:
Happy to share this tool with OpenCode maintainers.
Urgency: Auto-Close Bot Pattern
We observed issues #17837 and #17185 were closed by github-actions bot within 2 hours for "contributing guidelines" - despite containing:
This pattern is dangerous for memory safety issues:
Recommended Actions
Immediate:
perfandbuglabelsShort-term:
Long-term:
Cross-Project Coordination
We're coordinating with:
Memory leaks don't respect project boundaries - this is an ecosystem-wide crisis.
Evidence:
Please prioritize this over formatting requirements.