Repository navigation
feat: introduce a temporal oracle for bitemporal memory replay - #873
Gardenia-zx wants to merge 38 commits into
Conversation
| merged.apply(event); | ||
| } | ||
| for (MemoryEvent event : right.eventSnapshot()) { | ||
| merged.apply(event); |
There was a problem hiding this comment.
Swapping the left and right histories can turn a valid merge into an overlap error. Could you combine both histories, deduplicate identical events, reject conflicting events with the same ID, and sort before replaying? Please add a regression test that swaps the two inputs.
There was a problem hiding this comment.
Fixed in 8fc3a70. The merge now deduplicates and sorts the combined history before replay, rejects conflicting event IDs, and has a regression test that swaps the two inputs.
| List<MemoryFactVersion> affected = new ArrayList<>(); | ||
| for (MemoryFactVersion version : versions) { | ||
| if (isCurrent(version) | ||
| && version.getFact().getId().equals(event.getFactId()) |
There was a problem hiding this comment.
This path matches by factId without checking targetVersionId, so a retraction targeting a nonexistent version can remove a different one. Please reject targeted retractions here or route them through normalized replay. Add a test that confirms an invalid target leaves the state unchanged.
There was a problem hiding this comment.
Fixed in e0bcc3f. The legacy path now rejects targeted retractions. The regression test verifies that an invalid target leaves both the state and event history unchanged.
| TemporalQueryService service = new TemporalQueryService(); | ||
| List<MemoryFactVersion> matches; | ||
| if (mode == QueryMode.CURRENT) { | ||
| matches = service.current(snapshot.getState(), factKey, validAt); |
There was a problem hiding this comment.
Writes normalize FactKey to NFC, but queries and candidate lookups use the raw key. Please reuse the write-side normalization in both lookups and add a regression test showing that the composed and decomposed forms return the same result.
There was a problem hiding this comment.
Fixed in 0317aec. Writes, queries, and candidate lookups now share the same NFC normalization. The regression tests verify that composed and decomposed keys return the same results.
What changes were proposed in this pull request?
OSPP 2026 project context
This PR is the Phase 1 milestone delivery of my Open Source Promotion Plan (OSPP) 2026 project for Apache GeaFlow, under the broader Dynamic Context Memory proposal described in #683.
The overall OSPP project explores how GeaFlow can support evolving contextual memory for AI applications. Phase 1 focuses on establishing a correctness-first Temporal Oracle: a deterministic reference implementation for representing, normalizing, replaying, querying, comparing, and recovering bitemporal memory state.
The Temporal Oracle is intended to serve as the correctness baseline for later integration, scalability, and performance work.
Phase 1 deliverables
ADD,CORRECT, andRETRACTMemoryGraphArchitecture overview
The main processing flow is:
MemoryEvent→EventNormalizer→NormalizedMemoryEvent→FullReplayOracle/IncrementalTemporalIntegrator→TemporalState→CanonicalSnapshotThe resulting canonical snapshot can then be:
SnapshotComparator;MemoryGraphrepresentation.Main changes
ADD,CORRECT, andRETRACTevents, including interval splitting and tombstones.SUPERSEDES,DUPLICATE_OF, andCONFLICTS_WITHrelations between fact versions.MemoryGraphmodel.Core semantics and invariants
[start, end).Addressed high-priority pre-PR review findings
Instantnanosecond precision during event normalization and payload hashing.Suggested review order
The implementation can be reviewed in the following order:
temporal/model: domain objects, interval rules, and invariants.temporal/semantics: event normalization, ledger behavior, and temporal state.temporal/oracleandtemporal/query: replay rules and bitemporal queries.temporal/integration: incremental integration, aggregation, serialization, and recovery.temporal/adapter: snapshot-to-MemoryGraphround trip and graph validation.Scope and boundaries
This is an additive Phase 1 correctness/reference implementation.
org.apache.geaflow.ai.temporalpackage.geaflow-ai/pom.xml.This PR intentionally contains the complete Phase 1 vertical slice so that replay equivalence, state recovery, and graph round-trip invariants can be reviewed together.
It does not represent completion of the entire OSPP project. Later work may build on this correctness foundation to address production-facing APIs, distributed temporal processing, retrieval integration, scalability, and performance evaluation.
Because this milestone is larger than a typical feature PR, it is intentionally opened as a Draft PR for early architecture and correctness review. In particular, feedback is welcome on:
If maintainers prefer smaller PRs, the implementation can be split into:
MemoryGraphadapter and graph validation.How was this PR tested?
Validation completed:
geaflow-aimodule test suite: 181 tests, 0 failures, 0 errors, and 2 platform-specific skips on Windows.TemporalStateRecoveryTestunder WSL/Linux: 8/8 passed.