Skip to content

feat(memory): provenance metadata and origin filtering#8

Merged
chrishonson merged 1 commit into
mainfrom
feat/provenance
Jul 11, 2026
Merged

feat(memory): provenance metadata and origin filtering#8
chrishonson merged 1 commit into
mainfrom
feat/provenance

Conversation

@chrishonson

Copy link
Copy Markdown
Owner

Summary

  • Add memory + action lineage tracking (INVEST docs: update GEMINI_MULTIMODAL_MODEL default to gemini-3.1-flash-lite #3): every write now records metadata.provenance = { origin, source_session?, derived_from?, confidence? }, with origin defaulting to agent_inferred unless the caller explicitly claims user_asserted.
  • search_context gains filter_origin, implemented as an in-service post-filter (same pattern as the existing valid_at post-filter) — no new Firestore composite index. Documents with no provenance never match when filter_origin is set, which also covers legacy documents pre-backfill.
  • Closes a response-payload gap from the prior temporal-validity PR: fetch_context/remember_context/search_context JSON responses now also expose valid_from, valid_until, supersession_reason, and initiator when present (previously stored but never surfaced).
  • New backfill script functions/scripts/backfill-firestore-provenance.mjs (npm --prefix functions run backfill:provenance, dry-run by default, --write to apply) stamps metadata.provenance = { origin: "legacy_import" } on existing docs missing provenance, following the same CLI conventions as the existing TTL backfill script.
  • Docs updated: metacortexplan.md INVEST docs: update GEMINI_MULTIMODAL_MODEL default to gemini-3.1-flash-lite #3 status → Implemented 2026-07-11; CLAUDE.md tool/data-flow descriptions updated for the new contract.

Test plan

  • npm --prefix functions run build — compiles clean
  • npm --prefix functions test — 70/70 tests pass, 74.66% coverage (≥60% requirement)
  • New unit tests in service.test.ts: origin defaults to agent_inferred, explicit user_asserted passthrough, source_session/derived_from/confidence passthrough and omission, filter_origin match/non-match/no-provenance-excluded, buildFetchPayload exposes valid_from/valid_until/supersession_reason/initiator/provenance
  • New end-to-end tests in mcp.integration.test.ts: remember_context with origin over MCP, search_context with filter_origin over MCP, fetch_context response includes temporal + provenance metadata
  • node --check functions/scripts/backfill-firestore-provenance.mjs — syntax valid

🤖 Generated with Claude Code

Add memory + action lineage tracking (INVEST #3) so agents can distinguish
user-asserted facts from agent-inferred ones and audit where an inference
came from. Every write now records metadata.provenance, defaulting origin
to agent_inferred unless the caller explicitly claims user_asserted, since
that claim must never be silently upgraded.

search_context gains filter_origin as a post-filter (same pattern as the
existing valid_at post-filter) to avoid a new composite Firestore index.
Docs missing provenance never match a filter_origin query, which also
covers legacy documents until the backfill script runs.

Also closes a response-payload gap from the temporal-validity work: fetch/
remember/search responses were missing valid_from, valid_until,
supersession_reason, and initiator despite storing them.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@chrishonson chrishonson merged commit bbd1633 into main Jul 11, 2026
1 check passed
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