anomalyco / anomalyco/opencode

perf: guard unlimited whole-session message hydration

Open
#45,216 1 comment 0 reactions 1 assignee View on GitHub

@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
  1. Create or import a session with tens of thousands of messages and parts.
  2. Invoke an unlimited Session.messages() caller, such as session export or the HTTP history handler.
  3. Observe that every page and hydrated part remains accumulated until the complete session is returned.
  4. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.