feat(memory): provenance metadata and origin filtering#8
Merged
Conversation
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>
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
metadata.provenance = { origin, source_session?, derived_from?, confidence? }, withorigindefaulting toagent_inferredunless the caller explicitly claimsuser_asserted.search_contextgainsfilter_origin, implemented as an in-service post-filter (same pattern as the existingvalid_atpost-filter) — no new Firestore composite index. Documents with no provenance never match whenfilter_originis set, which also covers legacy documents pre-backfill.fetch_context/remember_context/search_contextJSON responses now also exposevalid_from,valid_until,supersession_reason, andinitiatorwhen present (previously stored but never surfaced).functions/scripts/backfill-firestore-provenance.mjs(npm --prefix functions run backfill:provenance, dry-run by default,--writeto apply) stampsmetadata.provenance = { origin: "legacy_import" }on existing docs missing provenance, following the same CLI conventions as the existing TTL backfill script.metacortexplan.mdINVEST docs: update GEMINI_MULTIMODAL_MODEL default to gemini-3.1-flash-lite #3 status → Implemented 2026-07-11;CLAUDE.mdtool/data-flow descriptions updated for the new contract.Test plan
npm --prefix functions run build— compiles cleannpm --prefix functions test— 70/70 tests pass, 74.66% coverage (≥60% requirement)service.test.ts: origin defaults toagent_inferred, explicituser_assertedpassthrough,source_session/derived_from/confidencepassthrough and omission,filter_originmatch/non-match/no-provenance-excluded,buildFetchPayloadexposesvalid_from/valid_until/supersession_reason/initiator/provenancemcp.integration.test.ts:remember_contextwithoriginover MCP,search_contextwithfilter_originover MCP,fetch_contextresponse includes temporal + provenance metadatanode --check functions/scripts/backfill-firestore-provenance.mjs— syntax valid🤖 Generated with Claude Code