Skip to content

fix(v2): retain and rebuild automatic memory context - #362

Merged
EyJunge1 merged 1 commit into
tickernelz:mainfrom
Phototonic:fix/v2-memory-context-lifecycle
Oct 3, 2026
Merged

EyJunge1 merged 1 commit into
tickernelz:mainfrom
Phototonic:fix/v2-memory-context-lifecycle

Conversation

@Phototonic

Copy link
Copy Markdown
Contributor

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:

  • Retain each session's first context across later user turns and model steps; refresh on each authored turn in "always" mode.
  • Rebuild a cold session's context from the canonical memory store on its next context hook, including a resumed request without a new user prompt. Apply the existing project, current-session, and age filters without recording a synthetic prompt.
  • Honor disabled/unconfigured injection, suppress internal/filtered/blank prompts, discard stale context on empty or failed refreshes, and invalidate the affected cache after compaction.
  • Preserve V1 synthetic-part injection and history-based policy, and document the v2 lifecycle.

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

  • Exercised the change locally (or N/A for docs/meta-only)
  • Noted any follow-up or known limitations

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 check passes (format, lint, typecheck).
  • bun run build passes; one warning remains in the unchanged web/src/lib/components/ui/bordered-panel.svelte.
  • bun test: 639 pass, 4 skip, 1 fail across 97 files. The failure is OpenCode plugin loader bundle boundary > does not pull local embedding transformer internals into the plugin-loader bundle (Could not resolve local service imports). The same test fails on a separately compiled, unmodified checkout of base 2bf1a939f8b28bbfbdd4e3f1e9e76cd800974c6f, with the same locked dependencies and Bun version. The other two bundle-boundary tests pass. The full-suite checkbox below is intentionally unchecked.

Checklist

  • Branch is based on main (do not open PRs from commits already on main)
  • bun test passes (or N/A)
  • bun run typecheck passes (or N/A)
  • bun run check passes (format + lint + typecheck; or N/A)
  • Docs / README updated when behavior or contribution process changes

@EyJunge1
EyJunge1 merged commit 6fa18e1 into tickernelz:main Oct 3, 2026
6 checks passed
@EyJunge1 EyJunge1 mentioned this pull request Oct 3, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants