fix(disposal): Complete Instance disposal chain for plugins and caches #9149
+140
−12
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.
Summary
Complete the Instance disposal chain to ensure plugins and cached resources are properly cleaned up when instances are disposed.
Fixes #9157
Depends on #9141 (LRU cache utility)
Problem
When
Instance.dispose()is called:Solution
1. Plugin Dispose Hook
Add
dispose()method to plugin Hooks interface.2. LRU Cache onEvict Callback
Use the LRU cache's
onEvictcallback to dispose instances when evicted.3. Bootstrap Cleanup
Add cleanup in bootstrap to dispose plugins before process exit.
Changes
packages/plugin/src/index.ts- Adddispose()to Hooks interfacepackages/opencode/src/plugin/index.ts- Call plugin dispose() on instance disposalpackages/opencode/src/project/instance.ts- Add onEvict callback for cache evictionpackages/opencode/src/project/bootstrap.ts- Add cleanup for plugins on exitpackages/opencode/src/provider/provider.ts- Use LRU cache for SDK instancespackages/opencode/src/util/cache.ts- Add iterator support (from feat(util): Add bounded LRU cache utility #9141)Testing
bun turbo typecheck)Note: Manual plugin disposal testing was not performed. This requires creating a test plugin with cleanup logic and verifying it's called.
Stacking
This PR includes commits from #9141 (LRU cache utility). After #9141 is merged, this PR can be rebased to only include the disposal-specific changes.