Skip to content

feat(memory): temporal validity and supersession reasons#6

Merged
chrishonson merged 1 commit into
mainfrom
feat/temporal-validity
Jul 11, 2026
Merged

feat(memory): temporal validity and supersession reasons#6
chrishonson merged 1 commit into
mainfrom
feat/temporal-validity

Conversation

@chrishonson

Copy link
Copy Markdown
Owner

Summary

Implements INVEST #2 from metacortexplan.md (Temporal Validity / Fact Versioning), including the design-review split of supersession into two semantically distinct reasons:

  • changed (default) — the old fact was true of its era (e.g. a job switch). Sets valid_until on the deprecated document; it remains true-of-period for valid-time slices covering that window.
  • corrected — the old record was never true (e.g. a mistyped date). Retracts it on the belief axis (supersession_reason: "corrected") without closing a valid-time window, excluding it from valid-time results while keeping it in the audit trail.

Changes:

  • MemoryMetadata gains optional valid_from, valid_until (epoch ms), supersession_reason ("changed" | "corrected"), and initiator ("user" | "agent").
  • deprecate_context accepts optional supersession_reason (default "changed") and initiator; response payload now includes item.supersession_reason.
  • search_context accepts optional valid_at (epoch ms); implemented as a service-layer post-filter after the vector search returns (no new Firestore composite indexes required). A document matches iff (valid_from absent or <= valid_at) AND (valid_until absent or > valid_at) AND supersession_reason !== "corrected".
  • remember_context/storeContext accept optional valid_from/valid_until passthrough at the type level (not yet exposed as an MCP input on remember_context, per the agreed scope).
  • All new fields are optional — fully backward compatible with existing callers.
  • Docs: metacortexplan.md INVEST Add Claude Code GitHub Workflow #2 status → Implemented 2026-07-11; CLAUDE.md tool table and data-flow descriptions updated for the new deprecate_context/search_context contracts.

Test plan

  • npm --prefix functions run build — zero errors
  • npm --prefix functions test — 56/56 passing, 73.27% overall coverage (≥60% required)
  • New unit tests in service.test.ts: default reason + valid_until, corrected does not set valid_until, initiator recorded, valid_at window filtering (inside/before/after), corrected exclusion, absent-fields-always-match
  • New end-to-end test in mcp.integration.test.ts: deprecate_context with supersession_reason/initiator over real MCP Streamable HTTP transport, search_context with valid_at for both "corrected" exclusion and "changed" window behavior
  • InMemoryMemoryRepository fake mirrors the real FirestoreMemoryRepository.deprecate() behavior exactly

🤖 Generated with Claude Code

Split supersession into two semantically distinct reasons so agents can
distinguish "the world changed" from "the old record was never true":
deprecate_context now accepts supersession_reason ("changed" default sets
valid_until on the old record; "corrected" retracts it on the belief axis
without closing its valid-time window) and an optional initiator for audit.
search_context gains an optional valid_at post-filter (service-layer only,
no new Firestore indexes needed) so callers can query facts as of a point
in time. All fields are optional and backward compatible.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@chrishonson chrishonson merged commit 7227e7d 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