GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(memory): add TTL, LRU eviction, and ring buffers to prevent memory leaks by Stranmor · Pull Request #12259 · anomalyco/opencode

Conversation

@Stranmor

@Stranmor Stranmor commented Feb 5, 2026

Copy link
Copy Markdown

Summary

Addresses memory leak issues reported in #10913, #9140, #5363.

This PR adds cleanup mechanisms to prevent unbounded memory growth in long-running sessions:

Changes

Component Fix Details
ACPSessionManager TTL + LRU 1h TTL, 50 session limit, 5min cleanup interval
Instance cache TTL + LRU 30min idle TTL, 10 instance limit, auto-dispose
LSP clients Max limit 20 client limit, oldest-first eviction
PTY buffers RingBuffer O(1) append instead of string concatenation

Technical Details

ACPSessionManager (acp/session.ts)

  • Added SessionEntry wrapper with lastAccess timestamp
  • Periodic cleanup every 5 minutes removes sessions idle >1 hour
  • Hard limit of 50 sessions with LRU eviction

Instance cache (project/instance.ts)

  • Added CacheEntry wrapper with lastAccess tracking
  • evictIdleInstances() called on new instance creation
  • Properly disposes State when evicting idle instances

LSP clients (lsp/index.ts)

  • Added MAX_LSP_CLIENTS = 20 limit
  • Evicts oldest client when limit reached
  • Graceful shutdown of evicted clients

PTY buffers (pty/index.ts)

  • New RingBuffer class with chunk-based storage
  • Avoids repeated large string allocations
  • O(1) append, automatic trimming to limit

Testing

  • TypeScript compiles without errors in changed files
  • Manual testing with long-running sessions
  • Memory profiling before/after

Related Issues

  • Fixes fix: multiple memory leaks in long-running sessions #10913 (memory leaks in long-running sessions)
  • Addresses Memory leak: Unbounded caches grow without limit #9140 (unbounded caches)
  • Addresses opencode eating 70gb of memory? #5363 (high memory usage)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Stranmor
fix(memory): add TTL, LRU eviction, and ring buffers to prevent memor…
e11b21c
…y leaks

- ACPSessionManager: add 1h TTL + 50 session limit with periodic cleanup
- Instance cache: add 30min idle TTL + 10 instance LRU limit
- LSP clients: add 20 client limit with oldest-first eviction
- PTY buffers: replace string concatenation with RingBuffer class

Addresses issues #10913, #9140, #5363
@github-actions

github-actions Bot commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search results, I found 3 potentially related PRs that address similar memory leak issues:

  1. PR fix(memory): resolve 6 memory leak issues in long-running sessions #12053 - "fix(memory): resolve 6 memory leak issues in long-running sessions"

    • Directly addresses the same category of problems (memory leaks in long-running sessions)
  2. PR fix(opencode): resolve multiple memory leaks in long-running sessions #10914 - "fix(opencode): resolve multiple memory leaks in long-running sessions"

    • Also targets memory leaks in long-running sessions with similar scope
  3. PR feat(util): Add bounded LRU cache utility #9141 - "feat(util): Add bounded LRU cache utility"

    • Provides LRU cache implementation that could be related to the eviction mechanisms in PR fix(memory): add TTL, LRU eviction, and ring buffers to prevent memory leaks #12259

These PRs likely overlap with the memory leak fixes in PR #12259. You should review PR #12053 in particular, as it appears to address the same core issue of resolving memory leaks in long-running sessions.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Feb 11, 2026
[BUG/PERF] Severe Memory Leak and Disk Swell leading to System Kernel Panic (macOS) #12687
Closed
fix: resolve memory leaks and zombie processes from missing cleanup handlers #13183
Closed
@github-actions github-actions Bot mentioned this pull request Feb 11, 2026
feat(core): add memory usage (leak) monitoring #13194
Closed
@davidvv davidvv mentioned this pull request Feb 18, 2026
[Critical] Memory leak causes kernel soft lockups (356s, 7/8 CPUs), OOM kills (111GB virt/21GB RSS), and total system death on Linux #13230
Closed
@guazi04 guazi04 mentioned this pull request Mar 5, 2026
[FEATURE]: Session Lifecycle Management — unified storage reclamation, auto-archival, and child session cleanup #16101
Closed
1 task done
This was referenced Mar 9, 2026
Multiple memory leaks cause unbounded RAM growth during extended TUI usage #16697
Closed
fix: resolve multiple memory leaks causing unbounded growth #16695
Closed
@Stranmor

Stranmor commented Mar 11, 2026

Copy link
Copy Markdown
Author

Closing in favor of the consolidated effort in #16695 by @binarydoubling, which covers the LSP eviction, ring buffer, and instance cleanup fixes from this PR. The ACP session TTL/eviction piece is tracked as a follow-up item in #16695 and #16697 — happy to submit a fresh targeted PR for that once the consolidated fix lands.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Stranmor Stranmor closed this Mar 11, 2026
@Stranmor
Stranmor deleted the memory-fixes branch November 26, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

fix: multiple memory leaks in long-running sessions

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@Stranmor
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.