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
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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Feb 11, 2026
This was referenced Mar 9, 2026
|
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.
|