Skip to content

Per-session caches (epoch, latestPrompt, sessionStats) grow unbounded in a long-lived server #75

Closed

Description

@abogartz

Problem

The plugin's per-session caches in src/index.ts grow without bound for the lifetime of the server process. A long-lived opencode serve (or the desktop app's resident server) that hosts many sessions accumulates them forever.

  • epoch: Map<string, { version; block; at; reason }> — one entry per session ID ever seen; block holds up to injectBudget chars each.
  • latestPrompt: Map<string, string> — being added by PR fix(inject): refresh the frozen memory block when its rows change #65 — one entry per session holding that session's full last prompt text, which can be many KB.
  • Both are only cleared at compaction (epoch.delete / latestPrompt.delete), so a session that never compacts is never reclaimed.
  • sessionStats: Map<string, SessionStats> is small but has the same lifetime; measuredTurns likewise.

Pre-existing for epoch; #65 makes it materially worse by adding the largest of the three.

Suggested fix

Mirror what src/repokey.ts already does for this exact shape (SESSION_CAP = 64, evict oldest on insert): a small LRU cap per map, evicting the least-recently-touched session. Semantics are safe — the worst case for an evicted session is one epoch recompute (and the digest line already busts the cache on every write), which is a cost, not a correctness problem.

Acceptance

  • N sessions (> cap) through one server process: map sizes stay bounded, asserted in a test.
  • No behavioural change for a single long session; epoch byte-stability across requests is preserved (there is an existing test asserting an unchanged store yields an identical block — keep it green).

Context

Noted while reviewing PR #65 (which adds latestPrompt); split out so the review isn't blocked on a lifetime change.

Activity

  1. added
    bug
    on Oct 24, 2026
  2. added a commit that references this issue on Oct 24, 2026
    ee67acd
  3. abogartz-opencode-self-improvement commented on Oct 24, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved in version 0.8.6 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

  4. abogartz commented on Nov 1, 2026

    @abogartz
    OwnerAuthor

    Follow-up filed: #224. The 2026-10-31 architecture review verified that three ledgers that grow with work remain unbounded after this fix: state.sessions (src/state.ts:102), per-session calls (src/triggers.ts:51), and frontierInjectedSessions (src/inject.ts:228); and src/repokey.ts:93 re-declares SESSION_CAP = 64 instead of importing the shared constant from src/sessions.ts.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugreleased

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions