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(opencode): memory leaks in session handling by ztripez · Pull Request #10392 · anomalyco/opencode

Conversation

@ztripez

@ztripez ztripez commented Jan 24, 2026

Copy link
Copy Markdown

Fixes #5363

What does this PR do?

Fixes memory leaks in session handling that cause unbounded memory growth during long conversations.

Key fixes:

  1. Provider caches - Replace unbounded Maps with LRU eviction (100/50 entry limits) to prevent SDK object accumulation
  2. Prompt loop clone - Remove unnecessary deep clone of entire message history on every turn, use selective shallow copying instead
  3. Session cleanup - Add cleanup for FileTime and ACP session state when sessions end
  4. Bus subscriptions - Convert permanent subscriptions to use Instance.state() disposal pattern to prevent listener leaks
  5. Compaction output deletion - Actually delete tool output text from storage instead of just marking it compacted (critical fix - output was staying in JSON files)
  6. Pending request timeouts - Add 5-minute timeout to permission/question requests to prevent hanging promises in abandoned sessions
  7. Processor map cleanup - Clear toolcalls map when handling aborted tools to prevent accumulation
  8. String concatenation - Use array accumulation + join instead of += for streaming text/reasoning/bash output to avoid creating intermediate string objects

How did you verify your code works?

  • Passes existing typecheck
  • Changes follow existing patterns in codebase (Instance.state disposal, LRU pattern already used elsewhere)
  • Most critical fix (5 compaction) is straightforward - replaces output string with placeholder before saving instead of after
  • Timeout pattern (6) matches existing timeout implementations in other tools
  • String accumulation (8) is standard optimization, uses join() only when needed for updates

Testing recommendations:

  • Long sessions with many tool calls to verify compaction reduces storage size
  • Monitor memory usage over time with session lifecycle
  • Verify abandoned sessions clean up pending requests after 5 minutes

Sorry, something went wrong.

Uh oh!

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

All reactions
Ztripez von Matérn
fix memory leaks in session handling
271faef
- add LRU eviction to provider caches
- remove deep clone in prompt loop
- add session cleanup for FileTime and ACP
- fix bus subscriptions to use Instance.state disposal
- delete tool output on compaction instead of just marking
- add timeout to pending permission/question requests
- clear processor maps on error
- use array accumulation instead of string concat for streaming
@github-actions

github-actions Bot commented Jan 24, 2026

Copy link
Copy Markdown
Contributor

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

Potential Related PRs Found

Here are PRs that may be related to or duplicate aspects of PR #10392:

  1. feat(util): Add bounded LRU cache utility #9141 - feat(util): Add bounded LRU cache utility

    • Related to the LRU cache implementation mentioned in fix feat: compact and other improvements #1 (provider caches)
  2. fix(memory): Fix timeout, interval, and subscription cleanup #9148 - fix(memory): Fix timeout, interval, and subscription cleanup

    • Directly related to subscription cleanup and timeout patterns (fixes [readme] [bug] cant install #6 and feat: add configuration persistence for model selections #4 in this PR)
  3. fix(disposal): Complete Instance disposal chain for plugins and caches #9149 - fix(disposal): Complete Instance disposal chain for plugins and caches

    • Related to the Instance.state() disposal pattern mentioned throughout this PR
  4. fix: clean up pending permissions when session is deleted #7154 - fix: clean up pending permissions when session is deleted

    • Related to session cleanup when sessions end (fix feat: model config persistence #3 and [readme] [bug] cant install #6)
  5. fix(core): add dispose functions to prevent subscription memory leaks #7032 - fix(core): add dispose functions to prevent subscription memory leaks

    • Related to subscription leak prevention and disposal pattern
  6. fix(memory): Fix event listener leaks in TUI and Slack bot #9147 - fix(memory): Fix event listener leaks in TUI and Slack bot

    • Related to listener leak prevention (fix feat: add configuration persistence for model selections #4)

These PRs may contain overlapping solutions or address the same underlying issues. You may want to review them to ensure no duplicate effort or check if this PR should incorporate/reference those fixes.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Thejuampi

Thejuampi commented Jan 25, 2026

Copy link
Copy Markdown

tested this but no luck for me , that is after a few hours on a java project with jdtls LSP
image

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions github-actions Bot mentioned this pull request Jan 27, 2026
fix: memory leaks and hanging issues #10846
Closed
@thdxr
thdxr force-pushed the dev branch from cbab81f to 2d3c7a0 Compare January 30, 2026 04:49
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 00637c0 to 71e0ba2 Compare January 30, 2026 14:32
@thdxr
thdxr force-pushed the dev branch 4 times, most recently from f1ae801 to 08fa7f7 Compare January 30, 2026 14:37
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 22, 2026
fix: cleanup SDK event listeners to prevent memory leaks #14635
Closed
@Mte90

Mte90 commented Feb 26, 2026

Copy link
Copy Markdown

any hope for this?

All reactions

Sorry, something went wrong.

Uh oh!

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

@binarydoubling binarydoubling mentioned this pull request Mar 9, 2026
Multiple memory leaks cause unbounded RAM growth during extended TUI usage #16697
Closed
@github-actions github-actions Bot mentioned this pull request Mar 9, 2026
fix(session): clear compacted tool output #16785
Closed
3 of 6 tasks
@binarydoubling binarydoubling mentioned this pull request Mar 9, 2026
fix: resolve multiple memory leaks causing unbounded growth #16695
Closed
3 of 6 tasks
@github-actions github-actions Bot mentioned this pull request Mar 16, 2026
fix(run): await loop() to prevent premature instance disposal and state leak #17819
Closed
1 task done
@github-actions github-actions Bot mentioned this pull request Apr 7, 2026
fix: bash tool memory leak #21321
Closed
3 tasks done
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 2f2ed11 to 9f201d6 Compare April 16, 2026 21:55
@github-actions github-actions Bot mentioned this pull request Apr 25, 2026
fix(opencode): resolve heap unlimited + orphan processes on Linux #24297
Closed
7 tasks done
@github-actions

github-actions Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions github-actions Bot closed this Apr 28, 2026
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.

opencode eating 70gb of memory?

Uh oh!

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

3 participants

@ztripez @Thejuampi @Mte90
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.