fix(v2): scope runtime ownership per project directory - #99
Open
BobbyNooby wants to merge 2 commits into
Open
BobbyNooby wants to merge 2 commits into
BobbyNooby wants to merge 2 commits into
Conversation
Contributor
|
hi @BobbyNooby thanks for this PR, will have a look |
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.
TL;DR
On OpenCode 2, loading a new project directory silently disposes the supermemory plugin instance of every previously loaded directory. The
supermemorytools vanish and auto-capture stops working in all but the most recently loaded project — with no error anywhere. Fix: scope runtime ownership per project directory instead of per process.Impact
supermemory/supermemory_recalltool calls fail in every directory except the last-loaded one (the tool is no longer registered).session.context,session.compaction, and event hooks that inject memories and auto-capture transcripts are disposed too, so recall and capture silently stop for those projects.Steps to reproduce (2.0.15)
v2 plugin init.Easy to miss because with a single project directory (the common case) everything works — and even with several, the directory you're currently using tends to be the surviving one.
Root cause
The V2 plugin assumes one instance per process — the old comment says so verbatim: "Only one instance is active per process, so a hot-reloaded plugin replaces (and cleans up) the previous generation."
But the OpenCode server instantiates the plugin once per project directory in the same process. Since ownership was keyed by a single process-wide symbol:
every new directory's
setupV2()saw the previous instance as its "previous" and disposed it (previous?.cleanup()→#active = false+ disposal of all tracked registrations). Only the last-loaded directory kept a living runtime.Fix
Scope the owner key per directory (+9/−3):
Verification
bun run typecheckandbun test(34 pass) — including a new regression test added in this PR (test(v2): cover per-directory runtime ownership) that pins the per-directory ownership contract: two directories stay active, a same-directory reload bumps only that directory's generation, and cleanups remove their registry entries. The test fails against the pre-fix code and passes with the fix.generation: 1and both keep working; a fresh-sessionsupermemoryadd succeeds where it previously reported the tool as missing.