fix(opencode): evict idle per-directory instances to bound serve memory#33713
Open
Evgen1000end wants to merge 1 commit into
Open
fix(opencode): evict idle per-directory instances to bound serve memory#33713Evgen1000end wants to merge 1 commit into
Evgen1000end wants to merge 1 commit into
Conversation
serve cached one InstanceStore entry per directory (x-opencode-directory) and never freed it, so a server seeing many distinct directories (e.g. one per session) accumulated an instance each — file watchers, LSP/MCP subprocesses, plugins and bus subscriptions — until OOM. Adds opt-in idle-TTL + LRU eviction with an in-flight pin so a busy instance is never evicted mid-turn. Disposing only frees runtime resources; the session is in the DB and re-loads on the next request. Default behavior is unchanged when the env vars are unset. Related to anomalyco#33213
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The problem is relevant. Very necessary for our development |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue for this PR
Closes #33720
Related to #33213
Type of change
What does this PR do?
servecaches oneInstanceStoreentry per directory (x-opencode-directory) and never frees it — no TTL/LRU/idle eviction. A server that sees many distinct directories (e.g. one directory per session) accumulates an instance each, with its own file watchers, LSP/MCP subprocesses, plugins and bus subscriptions, so RSS climbs until OOM.Adds opt-in eviction:
lastUsed+ anactivein-flight counter;active==0) older thanOPENCODE_INSTANCE_IDLE_TTL_MS, and/or trims LRU ones aboveOPENCODE_INSTANCE_MAX;ensuring), so an in-flight request is never evicted mid-turn;With neither env var set the sweeper never starts; behavior is unchanged.
How did you verify your code works?
test/project/instance-eviction.test.ts): an idle instance is evicted after the TTL; an acquired one is not until released. Existing instance tests pass andbun typecheckis clean.Checklist