Skip to content

Sidebar session prefetch loads full tool outputs and can drive opencode serve to multi-GB memory #17837

Description

@OpenCodeEngineer

Summary

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 ...
  • Observed RSS / footprint growth: ~2.1 GB RSS, ~4.2-4.5 GB physical footprint
  • 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

  1. Have one or more sessions with large completed shell/tool outputs persisted in part.data.
  2. Run opencode serve.
  3. Browse sidebars / recent sessions so prefetch warms multiple sessions.
  4. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)perfIndicates a performance issue or need for optimization

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions