Skip to content

feat(retrieval): validity transitions, TRANSITIONS and the retrieval indexes (format 9) - #115

Merged
venkat1701 merged 12 commits into
mainfrom
feature/temporal-retrieval
Nov 23, 2026
Merged

venkat1701 merged 12 commits into
mainfrom
feature/temporal-retrieval

Conversation

@venkat1701

Copy link
Copy Markdown
Collaborator

This adds the storage the remaining retrieval work needs and two ways to ask what changed over time: in validity time (when a membership holds) and in generation time (what was committed).

Storage format 9. All new indexes land in this one format change, so later retrieval PRs add no storage. Directories written by format 8 are refused with the usual "export and reload it" message.

Slot What it holds
2 (changed) each reverse-index posting now carries the membership's validity interval; postings-tree summaries carry time bounds and role bits
47 to 49 each hyperedge's signature (edge type plus the multiset of its members' types), the hyperedges per signature and tenant, and a name list that detects key collisions
53 per tenant, edge type and side, the instants at which non-default membership intervals start or end
56 the child hyperedges of each parent, with roles, weight, validity and position in the summaries

Slots 47 to 49 and 56 are only written here. Structural matching and hierarchical retrieval read them in the next PRs.

Validity time

  • INCIDENT TO x VALID AT t and Temporal.activeEdges now read only x's postings and skip subtrees whose summary rules out t. Finding the one edge valid at an instant among 5,000 visits 4 pages instead of 25.
  • MATCH EDGE c:T WHERE c VALID AT a AND NOT c VALID AT b (literal a != b) gets a ValidityTransition plan from slot 53. Both conjuncts still verify every candidate, so results match the type scan.

Generation time. A new statement; the syntax is open for renaming before merge:

transitions = "TRANSITIONS" "EDGE" identifier [ ":" identifier ]
              "FROM" instant "TO" instant ( "APPEARED" | "DISAPPEARED" ) [ "MEMBERS" ] [ "LIMIT" integer ] ;
instant     = "GENERATION" integer | string ;
  • Retained generations are diffed.
  • Older windows are folded over the change feed, keeping the first and last change per key and skipping other branches' events through the branch lineage.
  • A window older than the feed is an error, and a window over budget fails as a whole.
  • Results go through the same tenant and type checks as every other read, so readers can run it.

Fixes found along the way

  • Branch merges: a merge replayed memberships before adopting atoms the branch created. A merge could also never complete when the target had deleted a member the branch added; such memberships are now member-deleted conflicts and are skipped.
  • Concurrent deletes: replaying a commit after a concurrent delete of a member is now a retryable conflict.
  • Change-feed timing: awaitPublished could return before the feed held the reader's newest commit. A new FEED_APPEND fault point makes that testable.

Testing

  • Full build: engine 269, database 180, server 41, all passing.
  • Randomized and mutation tests: every new index and query path has a randomized comparison against a brute-force or snapshot baseline with fixed seeds, and each has a mutation check: breaking the code on purpose (dropping a decrement, ignoring an update, skipping the lineage filter, the tenant check, or the span order) makes the test fail.
  • Live server test: a server built from this branch, two tenants over the wire protocol. 300/300 validity-transition queries and 480/480 TRANSITIONS queries per tenant matched a Python model, before and after a SIGKILL and recovery. A deliberately wrong model is caught (156/300 and 365/480).
  • Independent review: found three important issues (type grants in TRANSITIONS, the feed race, merges with deleted members) and three smaller ones I graded up (time instants inside a history gap, two times with no commit between them, the replay error type). Each has a test that failed before its fix.

Not done here

  • Falling back to the feed when a retained generation is trimmed between the check and the diff.
  • A type check inside Reader.validityEndpoints; its only caller already checks.
  • A meter on the feed scan behind time-based instants.

ServerTest#hostileConnectionsAreClosedEarly failed once in three runs on unchanged server code while the machine's load average was over 100. That looks like a timing race in the test itself.

… postings

Each reverse-index posting now carries the membership's validity interval,
and the postings tree's summaries carry time bounds and role bits, so a scan
of a member's postings can skip subtrees by time or role. A validity-only
membership update rewrites the posting. An unbounded interval end is not
stored, so a default membership costs one byte more than before.

The storage format is now 9; directories written by format 8 are refused.
No issue tracks this work.
Reader.incidentAt walks a member's postings, skips postings-tree subtrees
whose summary rules out the instant, and filters on the interval each
posting now carries. Temporal.activeEdges and INCIDENT TO ... VALID AT use
it, so they no longer read every incident edge's member tree. Edges of
another tenant are still dropped before they are returned.

No issue tracks this work.
Slot 53 keeps, for every tenant, edge type and side, the instants at which
non-default membership intervals start or end, with a count of matching
incidences per edge. ValidityIndex lists the edges with an endpoint in a
window and counts them from summaries. Memberships with the default
interval are never indexed.

The property index's directory schema is now a factory, shared with the new
slot.

No issue tracks this work.
A merge replayed deltas in id order, so a membership could name an atom
the branch created but the merge had not adopted yet. Memberships are now
applied after every created atom and before deletions, so derivations
that read a member's record see it.

No issue tracks this work.
Slots 47 to 49 keep each hyperedge's signature (its edge type and the
multiset of its members' types), the hyperedges of each signature per
tenant, and the tenant and signature behind each signature key, so a
colliding key is detected and filtered. Slot 56 lists the child
hyperedges of each parent with the child's roles, weight, validity and
position; its summaries carry weight, time and role bounds.

Both are kept by derivations on membership changes. The docs describe
storage format 9 and the new slots. Randomized tests now use a fixed seed.

No issue tracks this work.
A typed edge match whose top-level conjuncts are 'x VALID AT a' and
'NOT x VALID AT b', with literal a != b, gets a ValidityTransition
candidate: the edges with a validTo (disappeared) or validFrom (appeared)
in the window, read from slot 53 through tenant-scoped Reader methods and
estimated from its summaries. Both conjuncts still verify every candidate,
so results match the type scan; EXPLAIN names the new path.

No issue tracks this work.
…tions

TRANSITIONS EDGE e[:T] FROM ... TO ... (APPEARED | DISAPPEARED) [MEMBERS]
lists what was present at one generation and absent at the other on the
session's branch. Retained generations are diffed; older windows are folded
over the change feed, which keeps the first and last change per key and
skips other branches' events through the branch lineage. The fold waits
until every commit up to the reader's generation is published, since the
feed is appended just after publication. A window before the feed's first
event is an error, and a window over budget fails as a whole.

Results are tenant-scoped by each edge's and member's stamped tenant, so
readers can run it. TransactionManager.awaitPublished is now public.

No issue tracks this work.
A generation becomes current before its commit event is appended to the
change feed, so awaitPublished could return while the reader's newest
commit was still missing from the feed. It now always waits for the
commit's publication to finish. A FEED_APPEND fault point lets tests hold a
commit between the two steps.

No issue tracks this work.
A branch that added a member which the target branch had since deleted
could never be merged: the new indexes need the member's record. Such
memberships are now reported as member-deleted conflicts and skipped under
every policy, including when an ordered edge's sequence is copied. When a
commit is replayed after a concurrent delete of a member, the indexes
raise a retryable conflict instead of an invalid-schema error.

No issue tracks this work.
TRANSITIONS returned edges and members of types the reader may not read;
records now go through the same tenant and type check as every other read.
A time instant only resolves through retained history when the next
generation is retained too, so a gap left by a pinned generation no longer
widens the window; otherwise it is resolved through the feed. Two times
with no commit between them return no rows instead of an error.

No issue tracks this work.
TRANSITIONS built a branch's lineage from active branches only, so the
history of a branch whose parent had since been merged or dropped lost
the parent's events and returned too little. Lineage now reads every
branch record, closed ones included.

No issue tracks this work.
Reader.typeOf and Reader.edgeAtom answer from the catalog record with the
reader's tenant and type checks, without building an Atom. The retrieval
operators that build on this branch use them.

No issue tracks this work.
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