Unbounded caches in Instance and Provider modules cause memory growth #9437

Closed
opened 2026-02-16 18:12:27 -05:00 by yindo · 2 comments
Owner

Originally created by @sauerdaniel on GitHub (Feb 15, 2026).

Originally assigned to: @rekram1-node on GitHub.

Problem

Several places in the codebase use unbounded Map objects for caching:

  • Instance cache in project/instance.ts
  • Provider SDK cache in provider/provider.ts

In long-running processes or when handling many directories/providers, these maps can grow without limit, causing steady memory growth.

Expected behavior

Caches should have a maximum size with LRU eviction so memory remains bounded, with optional cleanup callbacks for evicted entries.

Related

This is distinct from #9143 (LSP diagnostics/files cleanup, already fixed in f936043dd). This issue is about the broader pattern of unbounded Map caches elsewhere in the codebase.

Originally created by @sauerdaniel on GitHub (Feb 15, 2026). Originally assigned to: @rekram1-node on GitHub. ## Problem Several places in the codebase use unbounded `Map` objects for caching: - Instance cache in `project/instance.ts` - Provider SDK cache in `provider/provider.ts` In long-running processes or when handling many directories/providers, these maps can grow without limit, causing steady memory growth. ## Expected behavior Caches should have a maximum size with LRU eviction so memory remains bounded, with optional cleanup callbacks for evicted entries. ## Related This is distinct from #9143 (LSP diagnostics/files cleanup, already fixed in f936043dd). This issue is about the broader pattern of unbounded `Map` caches elsewhere in the codebase.
yindo added the perf label 2026-02-16 18:12:27 -05:00
yindo closed this issue 2026-02-16 18:12:27 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 15, 2026):


This issue might be a duplicate of existing issues. Please check:

  • #9140: Memory leak: Unbounded caches grow without limit (exact duplicate — same files and root cause)
  • #5363: Related to broader memory issues in long-running sessions
  • #9157: Memory leak: Instance disposal doesn't clean up plugins or cached resources (related)
  • #10913: fix: multiple memory leaks in long-running sessions (open PR addressing this)
  • #9699: Memory usage grows very quickly when running commands with large output (related)

Please review #9140 in particular, as it describes the exact same problem with the same proposed solution (LRU cache with eviction). If you have additional context or reproduction steps beyond what's in #9140, please add them as a comment there.

@github-actions[bot] commented on GitHub (Feb 15, 2026): --- This issue might be a duplicate of existing issues. Please check: - #9140: Memory leak: Unbounded caches grow without limit (exact duplicate — same files and root cause) - #5363: Related to broader memory issues in long-running sessions - #9157: Memory leak: Instance disposal doesn't clean up plugins or cached resources (related) - #10913: fix: multiple memory leaks in long-running sessions (open PR addressing this) - #9699: Memory usage grows very quickly when running commands with large output (related) Please review #9140 in particular, as it describes the exact same problem with the same proposed solution (LRU cache with eviction). If you have additional context or reproduction steps beyond what's in #9140, please add them as a comment there.
Author
Owner

@sauerdaniel commented on GitHub (Feb 15, 2026):

Closing as duplicate of #9140 to keep one issue per problem/PR scope. PR #9141 now references #9140 directly.

@sauerdaniel commented on GitHub (Feb 15, 2026): Closing as duplicate of #9140 to keep one issue per problem/PR scope. PR #9141 now references #9140 directly.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#9437