You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sidebar session prefetch loads full tool outputs and can drive opencode serve to multi-GB memory #17837
opencode serve can grow into the 2-5 GB range when sidebar/session prefetch loads message histories for sessions that contain very large completed tool outputs.
Findings
Live process sample: bun run --conditions=browser ./src/index.ts serve --hostname ...
vmmap -summary showed the growth concentrated in WebKit Malloc, not SQLite or child-process fanout.
The local DB contained active sessions with very large persisted tool payloads:
two sessions at ~183 MB each in part.data
repeated tool parts around ~15.26 MB each
payload example: captured bash stdout from head -c 8000000 /dev/zero | tr '\0' 'a'
The sidebar prefetch path requests GET /session/:id/message?limit=200 and stores full message.parts, even though hover preview only needs user-message text snippets and message metadata.
This forces the server to hydrate and JSON-encode large tool outputs during prefetch and can retain large JSC/Bun heap allocations afterward.
Likely trigger paths
Sidebar hover / warm prefetch in packages/app/src/pages/layout.tsx
Session row hover warming in packages/app/src/pages/layout/sidebar-items.tsx
Recent sessions sidebar on the redesign-recent-sessions-tab branch increases exposure by warming across a global recent list
Reproduction outline
Have one or more sessions with large completed shell/tool outputs persisted in part.data.
Run opencode serve.
Browse sidebars / recent sessions so prefetch warms multiple sessions.
Observe bun footprint rise into multi-GB territory.
Expected behavior
Sidebar prefetch should use a lightweight preview payload and avoid loading full completed tool outputs unless the user actually opens the session timeline.
Notes
A fix is in progress / under validation locally that introduces a lightweight preview mode for session-message prefetch and upgrades to the full payload only when the session page is opened.
The issue does not use one of the required issue templates (Bug Report, Feature Request, or Question). Please re-submit using the Bug Report template, which requires standard fields such as Steps to Reproduce, OpenCode version, Operating System, and Terminal.
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:
The sidebar/session warm-prefetch path was requesting full GET /session/:id/message?limit=200 payloads.
Heavy sessions had very large persisted tool/reasoning parts in SQLite, so prefetching those sessions forced Bun/JSC to hydrate and JSON-encode large message bodies, which drove the serve process into multi-GB memory usage.
The recent-sessions sidebar surface increased how often this path hit large sessions across projects.
Fix implemented locally:
Added preview=true support to GET /session/:id/message so the server can return lightweight preview payloads.
Preview payload keeps only real user text parts and strips assistant parts/tool output.
Sidebar prefetch now requests preview=true.
Prefetch metadata now tracks preview seeds so opening a session still upgrades to full history instead of treating the preview cache as complete.
Validation:
packages/opencode: bun test test/server/session-messages.test.ts test/session/messages-pagination.test.ts
packages/opencode: bun typecheck
packages/app: bun test --preload ./happydom.ts ./src/context/global-sync/session-prefetch.test.ts
packages/app: bun typecheck
Browser e2e: bun script/e2e-local.ts e2e/sidebar/sidebar-recent-prefetch.spec.ts --workers=1
The new server test covers paginated preview=true responses specifically, and the browser e2e verifies the sidebar hover-prefetch request carries preview=true on the real UI path.
Your analysis of sidebar prefetch loading full tool outputs aligns with our findings - WebKit JSC GC is not properly reclaiming memory during parallel marking phase. This appears to be an upstream WebKit issue affecting all embedders.
Activity
github-actions commentedon Mar 16, 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:
opencode serveIf you believe this was flagged incorrectly, please let a maintainer know.
OpenCodeEngineer commentedon Mar 16, 2026
Confirmed root cause and validated a fix locally.
Root cause:
GET /session/:id/message?limit=200payloads.tool/reasoningparts in SQLite, so prefetching those sessions forced Bun/JSC to hydrate and JSON-encode large message bodies, which drove theserveprocess into multi-GB memory usage.Fix implemented locally:
preview=truesupport toGET /session/:id/messageso the server can return lightweight preview payloads.preview=true.Validation:
packages/opencode:bun test test/server/session-messages.test.ts test/session/messages-pagination.test.tspackages/opencode:bun typecheckpackages/app:bun test --preload ./happydom.ts ./src/context/global-sync/session-prefetch.test.tspackages/app:bun typecheckbun script/e2e-local.ts e2e/sidebar/sidebar-recent-prefetch.spec.ts --workers=1The new server test covers paginated
preview=trueresponses specifically, and the browser e2e verifies the sidebar hover-prefetch request carriespreview=trueon the real UI path.github-actions commentedon Mar 16, 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.
jnorthrup commentedon Mar 21, 2026
Investigation from Bun Runtime - Related Memory Leak Analysis
We investigated similar memory leak patterns in Bun runtime (which also uses WebKit JavaScriptCore) and found this issue through our research.
Our Findings
We identified 4 unique JSC GC memory leaks in our runtime with similar characteristics:
JSC::SlotVisitor::drainFromSharedrace condition (7,214 stack frames)WTF::HashTable::removeIterator(7,214 frames)WTF::Vector<JSC::InByVariant>::operator=(7,220 frames)JSC::ASTBuilder::createForOfLoop(713 frames)Root Cause Pattern
Your analysis of sidebar prefetch loading full tool outputs aligns with our findings - WebKit JSC GC is not properly reclaiming memory during parallel marking phase. This appears to be an upstream WebKit issue affecting all embedders.
Related Upstream Issues
Tool We Built
We created an ASAN tracker (test/asan_tracker.zig) that can help identify and classify these leaks. Happy to share if useful for your investigation.
Bun Tracking Issue
This is a cross-project WebKit GC issue - coordinating across Bun, Claude Code, and other embedders.
jnorthrup commentedon Mar 21, 2026
We found this issue through our investigation of WebKit JavaScriptCore memory leaks across multiple projects (Bun, Claude Code, OpenCode).
Why This Matters
This issue contained:
But was closed by github-actions bot for:
Hardware Risk Ignored
Memory leaks on Apple Silicon Macs can cause:
Cross-Project Pattern
We found the same auto-closure pattern affecting:
opencode serveto multi-GB memory #17837 - Multi-GB sidebar prefetch leak (closed by bot)Our Related Investigation
Bun team identified 4 JSC GC leaks:
JSC::SlotVisitor::drainFromSharedrace (7,214 frames)WTF::HashTable::removeIterator(7,214 frames)WTF::Vector<>::operator=(7,220 frames)JSC::ASTBuilder::createForOfLoop(713 frames)All point to WebKit upstream GC issue affecting all embedders.
Recommendation
For anomalyco/opencode maintainers:
perfandbuglabelsThis is a hardware safety issue, not a formatting problem.
Related:
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.