anomalyco / anomalyco/opencode
perf: guard unlimited whole-session message hydration
@rekram1-node is already working on this.
Since Aug 26, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
Several paths call Session.messages() without a limit. The implementation pages by 50, hydrates every part, accumulates the complete session, and reverses the arrays. Sessions with tens of thousands of projected records can therefore create very large JavaScript object graphs.
MessageV2.page() hydrates all parts for each page. Unlimited callers include plan, stats, revert, export, compaction, summary, sharing, and HTTP handlers. The summarize handler loads unlimited history merely to find the last user agent.
Expected: each caller fetches only the fields and window it needs. Operations that need all history, such as export, stream or page it without retaining the full hydrated session.
Production data contained sessions with roughly 25,000 to 105,000 projected records. This is a confirmed unbounded allocation path, but it was not proven as the active OOM owner because one saturated runtime sample had no client connection.
Plugins
@loreai/opencode
OpenCode version
Current v2 development source
Steps to reproduce
- Create or import a session with tens of thousands of messages and parts.
- Invoke an unlimited
Session.messages()caller, such as session export or the HTTP history handler. - Observe that every page and hydrated part remains accumulated until the complete session is returned.
- Compare retained heap with a bounded/page-streaming implementation.
A regression should use a large synthetic session and enforce bounded retained heap while preserving complete export output.
Screenshot and/or share link
Not applicable; this is a server-side allocation path.
Operating System
Linux
Terminal
OpenCode server mode
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.