Skip to content

feat(context): add provenance metadata to injected memories - #422

Closed
Phototonic wants to merge 1 commit into
tickernelz:mainfrom
Phototonic:provenance-in-memory-context
Closed

Phototonic wants to merge 1 commit into
tickernelz:mainfrom
Phototonic:provenance-in-memory-context

Conversation

@Phototonic

@Phototonic Phototonic commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When the memory plugin injects remembered knowledge into a session, those memories used to be anonymous: the agent had no way to say which memory it was relying on, how old it was, or where it came from. This change gives every injected memory a visible identity — its id, creation date, and project — and tells the agent it may cite that id when leaning on a memory, so "I remember that we chose libSQL" can become "I remember that we chose libSQL (mem_1792183254076_wxsig8s9y, recorded 2026-10-16)". The same provenance is attached to the memories restored into a session after compaction, and the ids match what the Memory Explorer web UI shows, so a cited memory can be found and inspected later.

Details:

  • Provenance in the injected memory block, so agents can cite what they "remember":

  • Each <memory> tag in the injected <memory_context> block now carries id, created (UTC YYYY-MM-DD), and project attributes when present. Rows without provenance keep the exact previous tag shape.

  • The block header tells agents they may cite a memory by its id when relying on it.

  • Compaction's ## Restored Session Memory headings gain the same provenance: ### Memory N (mem_… · created YYYY-MM-DD · project), suffix omitted entirely when absent.

  • Shared helpers live in a new pure module (src/services/memory-provenance.ts). This keeps the mocked context.js export surface intact — several scenario tests mock.module that file with a minimal surface, so src/index.ts must not import new exports from it.

Session-title lookup was intentionally descoped per the issue (project name stands in).

Test plan

  • Exercised the change locally — a live session quoted its injected block verbatim: <memory relevance="100%" id="mem_…" created="2026-10-20" project="opencode-mem"> plus the new header sentence (the issue's acceptance criterion)
  • Noted any follow-up or known limitations — exact-format unit tests for both blocks in tests/memory-provenance.test.ts; three low-severity follow-ups from the pre-push review round are recorded in a comment below

Checklist

  • Branch is based on main (rebased onto 6289ac4; single commit)
  • bun test passes (787 pass / 3 fail — all three pre-existing on Linux main: plugin-bundle-boundary, user-profile-learning-confidence, config storagePath shape)
  • bun run typecheck passes
  • bun run check passes (format + lint + typecheck)
  • Docs / README updated — N/A: the injected block format is not documented in README, so no doc surface changes

@Phototonic

Copy link
Copy Markdown
Contributor Author

Pre-push review round (independent read-only reviewer over the full diff): APPROVE WITH COMMENTS — no blockers. Findings and disposition:

  1. Low — formatMemoryCreatedDate accepts timezone-free strings (2026-10-20T00:30:00 parses relative to local TZ; 2026-02-30 normalizes to Mar 2). Not reachable from current callers — they supply epoch-ms or Z-suffixed ISO (safeToISOString / raw created_at). Follow-up candidate: treat unzoned input as UTC + focused tests.
  2. Low — the compaction suffix renders id/projectName verbatim, so a project name containing embedded newlines could disturb the Markdown heading. IDs are plugin-generated (no newlines) and memory bodies already enter these prompts verbatim, so this is formatting hardening only. Follow-up candidate: collapse control whitespace in display metadata.
  3. Low — header wording states every memory carries an id/date while legacy rows intentionally omit them. Kept as originally proposed; happy to soften to "when available…" if maintainers prefer.

Reviewer validation: 46 targeted tests across six files + typecheck passed. Full suite rerun before push: 787 pass / 3 pre-existing Linux main failures (plugin-bundle-boundary, user-profile-learning-confidence, config storagePath shape).

Supersedes #421 (same change, renamed branch).

@Phototonic Phototonic closed this Oct 20, 2026
@Phototonic
Phototonic deleted the provenance-in-memory-context branch October 20, 2026 04:29
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.

1 participant