Repository navigation
fix(v2): retain and rebuild automatic memory context - #362
Merged
EyJunge1 merged 1 commit intoOct 3, 2026
Merged
Conversation
3 tasks
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.
Summary
On OpenCode v2, automatic memory context disappears on the second user turn with the default
chatMessage.injectOn: "first". The adapter deletes its session cache before every prompt, while the shared V1 hook correctly skips reinjection once history contains an authored user message. Since v2 system parts are transient request context, the original block is then absent from subsequent model requests. Host/plugin reloads also lose the cache, leaving resumed sessions without automatic context until a new eligible injection.This change separates authored-prompt capture from context construction and exposes an internal bridge for the v2 adapter:
"always"mode.Context remains in the model's system request and is not written into authored prompts, transcripts, or a second persistent plugin store. After reload, reconstruction uses current memories/profile rather than a byte-for-byte copy of the original block.
Test plan
Regression tests drive the real shared plugin and v2 adapter with isolated dependencies. The original code fails the later-turn and cold-reload cases; the patch passes retention, both injection modes, resume with/without a new prompt, session isolation, filtering, empty/error recovery, disabled/internal guards, compaction location isolation, and V1 compatibility. These are hook-level integration tests; no live provider requests or running user sessions were used.
Validation with Bun 1.3.14:
bun run checkpasses (format, lint, typecheck).bun run buildpasses; one warning remains in the unchangedweb/src/lib/components/ui/bordered-panel.svelte.bun test: 639 pass, 4 skip, 1 fail across 97 files. The failure isOpenCode plugin loader bundle boundary > does not pull local embedding transformer internals into the plugin-loader bundle(Could not resolvelocal service imports). The same test fails on a separately compiled, unmodified checkout of base2bf1a939f8b28bbfbdd4e3f1e9e76cd800974c6f, with the same locked dependencies and Bun version. The other two bundle-boundary tests pass. The full-suite checkbox below is intentionally unchecked.Checklist
main(do not open PRs from commits already onmain)bun testpasses (or N/A)bun run typecheckpasses (or N/A)bun run checkpasses (format + lint + typecheck; or N/A)