Skip to content

Bi-temporal memory: what applied at V, as Loom had recorded it at K - #30

Closed
zlareb1 wants to merge 76 commits into
mainfrom
feat/bitemporal-memory
Closed

zlareb1 wants to merge 76 commits into
mainfrom
feat/bitemporal-memory

Conversation

@zlareb1

@zlareb1 zlareb1 commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Closes #25.

Loom can now answer which assertions applied at valid time V, according to what it had recorded at knowledge time K. Corrections, deletes, merges and erasure keep earlier beliefs readable, except where erasure must remove them. Architecture page: docs/architecture/bitemporal-memory.md.

Bi-temporal memory is opt-in (off by default)

Owner decision (2026-10-17): the journal ships behind LOOM_MEMORY_BITEMPORAL_ENABLED (setting memory_bitemporal_enabled), default off, and with it off nothing is affected: the server behaves exactly as main. This overrides, for this feature only, the "one way to do each thing" rule. Main's code that the journal replaces is kept as the off path.

Why off by default (measured locally; details in docs/features/memory/bitemporal.md and on #25):

  • a journaled memory.set is ~2.1× main's p50 (~142 ms vs ~68 ms), from about 16 extra serial ClickHouse round trips (a Keeper lease, plan reads, the commit and its read-backs, the erasure fence);
  • storage grows per revision rather than per key: ~0.6 KB of commit and assertion plus a historical vector per revision (~6 KB at 1,024 dimensions, ~18 KB at 3,072);
  • reads that don't ask for a past time cost the same either way (~35 ms search p50 in both).

What off means

  • Schema: migration 039 carries -- requires-setting: memory_bitemporal_enabled and stays dormant (not applied, not reported pending). schemas/schema.sql is byte-identical to main's, and schemas/schema_temporal.sql is the on state; CI checks both. instances.schema_version and /v1/admin/schema.status leave the dormant file out.
  • Writes: the write funnel takes main's path (no journal hook, fence or journal_version). The journal worker is off, and the erasure saga is main's step for step unless the journal's tables exist.
  • Wire: main's. Journal-only fields are marked in server/core/feature_modes.py: inputs are ignored and named in ignored_args, outputs are absent, and the MCP listing omits them. The journal ops (memory.amend, memory.intervals, memory.temporal_diff, memory.temporal_status) answer 404, aren't listed, and aren't in /v1/operations. as_of / as_of_basis, the version-row namespace.rollback, main's clear, redact, quarantine and relabel, and the SDK's as_of arguments are restored.
  • Temporal features (valid_at, as_of, memory.timeline, temporal search) are main's in both modes.

Turning it on: set the variable on every process, run loom migrate (039 applies then), and restart. Keys written before have no journal history and are seeded on their next write. Writes made while it was off are adopted by the projection worker's sweep, which starts from the journal's first commit.

Verification

  • Main's own integration suite against main: 927 passed. Against this branch with the journal off: final run in progress.
  • A 23-request workload issued main's statements with zero journal tables touched.
  • A switch harness, off → on (migrate) → off → on, passes 33 checks.
  • Unit tests are green, and CI runs integration and the mixed-version gate in both modes.

Research summary and design rationale

This touches foundational shapes: a new authority table, a publication protocol, and the current-state table becoming a projection. The rationale below is also in docs/architecture/bitemporal-memory.md.

What prior systems teach.

  • SQL:2011 application-time tables get bounded corrections right (UPDATE … FOR PORTION OF splits a row into before / corrected / after). But their system time is a per-row transaction time, which needs real transactions.
  • Log-as-authority bitemporal stores get the ordering right: knowledge time comes from log order, never a row timestamp. But a valid-time write with no end silently runs to the next version, which assumes continuity.
  • Immutable-fact databases show transaction metadata working as provenance, but they have no valid time.
  • Event-sourced systems contribute contiguous projection watermarks and disposable, rebuildable projections.
  • Temporal knowledge graphs for agent memory close intervals on contradiction, but arrival-ordered and inferred. An old conversation arriving late can therefore close a newer fact, and "as known at K" is approximate.
  • Update-in-place agent memories lose the earlier belief from serving.

What Loom takes from each.

  • An append-only journal is the authority (one immutable commit per key change).
  • Knowledge time is the commit sequence, allocated under one publisher per namespace.
  • A correction copies only the touched segments, avoiding the quadratic growth of full-timeline copies.
  • Projections publish a contiguous watermark.
  • Valid time has an explicit basis (stated | extracted | inferred | unknown); continuity is never assumed.

ClickHouse constraints that shape the design.

  • There are no multi-statement transactions, so one synchronous single-block insert is the publication boundary.
  • Incremental MVs never see mutations, so memory_versions can't be the authority.
  • ReplacingMergeTree … FINAL is right for the current projection only if every re-emission carries every column.
  • ANN search applies its limit before selective filters, so historical search fixes the eligible set first, then ranks exactly.
  • Mutations are async, so erasure is enforced by a read-time cut, not by cleanup succeeding.

Value.

  • Agents can tell a transition from a corrected mistake (U01), and late evidence fills the past without reverting the present (U02).
  • "What did we believe on the 12th" is answerable separately from "what was true on the 7th".
  • Exposure receipts name the exact revisions an agent was shown.
  • Answers carry their cutoff and coverage gaps instead of answering confidently over an incomplete history.

Measured cost (local single node, fake embedder, p50):

  • Current-state reads are within about 10–20 % of main (get 13 vs 10 ms, list 20 vs 18, search 40 vs 34).
  • Historical reads are about 2× current (get 27–31 ms, list 47, search 44).
  • Sequential writes to one namespace drop from about 27/s to about 6/s. That is the price of a single serialized publisher, whose 7–9 round trips run under the namespace lock. Batching them is the next step if write throughput per namespace matters; across namespaces, writes are parallel.

Deliberately out of scope for this PR.

  • History planes for documents, digests, code and tracker. search.query reports them as not_historical.
  • Branches and counterfactuals (U24).
  • Distributed publisher failover.
  • Repeatable historical ranking. Answers disclose ranking_current.

Design

Authority: a commit journal. loom.memory_temporal_commits is a MergeTree. One immutable row is one complete change to one logical memory: the assertion ids it retires and the full assertions it adds. Each row also carries:

  • the operation and change kind;
  • actor, source class and source resource;
  • request and idempotency identity;
  • a semantic payload hash;
  • the erasure generation.

An assertion has a half-open valid-time span and a validity basis (stated | extracted | inferred | unknown, never the ingest clock). It also has a temporal kind (state | event | snapshot | rule), modality, qualifiers, status, attestation and evidence ids, with parent and origin lineage.

The pure reducer lives in server/memory/domain/temporal_model.py. It implements assert, correct (bounded: keeps the supported segments around the corrected span), transition, retract and assess. It is checked against the issue's oracle, the interval scenarios and a randomized pointwise reference model.

Publication. There is one serialized publisher per namespace. The lock is a KeeperMap lease when a Keeper exists, else an in-process lock. Under the lock the publisher:

  1. reads the namespace head and what the batch's keys serve;
  2. builds one commit per changed key;
  3. allocates commit_seq, with recorded_at strictly rising;
  4. inserts synchronously. That insert is the publication boundary.

loom.memory stays the current-state compatibility projection, written after the commit.

Every writer is covered from one place. insert_memory_versions is the single loom.memory funnel, and a hook registered in server/wiring.py journals each batch first. A row that carries the head's content forward is an assessment, so a verify after a correction keeps every segment. A changed value is an assertion. A tombstone, redaction or unserved status is a retraction. The in-place mutators (memory.clear, memory.reject) journal their retractions before mutating.

Failure handling:

  • Uncertain insert: reconcile by commit id, then retry the same rows. A successor is never published while an outcome is unknown.
  • Integrity: a publisher that lost a sequence race withdraws its own commits. A sequence still carrying two payloads is a break: readers serve only the prefix below it. The next write repairs it under the lock (the projection worker does so for idle namespaces), keeping the first-landed commit (server-stamped inserted_at) and deleting the rest.
  • Durable idempotency: the request's scoped key rides on each commit, past the 24 h replay cache. One batched lookup per plan; what the request already committed is kept on its request bag, so gathered child tasks share it.
  • Erasure fence: a write whose request began before an erasure of its scope is refused.

Projections.

  • memory_temporal_assertions (ReplacingMergeTree(projected_seq), born and retired sequences). A read at cutoff C admits born_seq <= C < retired_seq, then V. Filters run after the set is fixed.
  • A contiguous watermark. Readers reduce a lagging tail; the memory_temporal_projection worker replays it without skipping gaps.
  • Model-keyed historical vectors, keyed by the embed-text hash.

Reads. valid_as_of, known_as_of, read_token and validity_policy work on:

  • memory.get and get_by_id (resolved through the journal, so a memory deleted since is found at an earlier K);
  • memory.list (the live filters: prefix, type, tags, contains, user, proposed/duplicate statuses, preview; options the journal cannot answer, such as score sort, quotas, tombstones and count-only, are a 422);
  • memory.search (exact eligible set, then exact cosine with a lexical fallback for pending vectors);
  • memory.ask;
  • search.query (per-plane coverage; planes without history say not_historical).

New ops: memory.amend, memory.intervals, memory.temporal_diff (world vs belief), memory.temporal_status. Facts and records take the same pair (valid_as_of replaces their as_of).

Answers carry their cutoff: cutoff_seq, head_seq and history_from, complete, and named gaps. Bi-temporal reads write exposure receipts carrying the exact assertion ids and value hashes, plus the cutoff.

Writes gain change_kind (transition, correct), effective_at, temporal_kind, modality, valid-date text, precision and timezone, qualifiers and expected_revision. Write outputs gain commit_seq and read_token.

One path per mode. With the journal on, it is authoritative from a namespace's first write: every memory write publishes or fails, with no shadow mode or best-effort reconstruction of pre-journal history, and the single-axis as_of / as_of_basis replay is ignored (named in ignored_args). With it off, that replay and every other main path serve unchanged (see "Bi-temporal memory is opt-in" above). Writes with the journal on need a Keeper, which main requires anyway.

Cross-plane.

Plane Change
Shared memory shared_versions MV; historical shared search
Records memory.record.query known_as_of, matched against each revision's own fields
Graph recorded_at and closed_at on edges and triples; facts.* known_as_of
Exposure ledger revision receipts

Planes with no historical reader yet (documents, digests, code, tracker) get no history writer; search.query marks them not_historical.

Erasure, redaction, retention.

  • The memory_temporal.delete and history_mirrors.delete saga steps hard-delete every journal, projection, vector and mirror row in scope. The census counts them.
  • memory.redact names a value by a historical version or a journal assertion_id (text only the journal holds), then takes one path: lock check, refuse a value the journal still serves, scrub every historical version, every journal assertion found in the commit payloads (projected or not), the projection, unused vectors, and derived embedding, chunk and cache rows. Hashes stay.
  • Retention follows loom.memory's rule: an assertion expires at its expires_at, else after the backstop; a commit outlives every assertion it added (retain_until); a vector goes with its last assertion.

Alternatives rejected

  • Full timeline copy per edit: quadratic write volume. Corrections copy only the touched segments.
  • memory_versions as the authority: one row per version cannot represent a multi-segment correction atomically, and in-place mutations bypass its MV. It stays the per-row history memory.history, redaction and rollback read.
  • Per-key time_ns versions as publication order: they give no cutoff a reader can name across keys and no crash contract. One sequence per namespace gives both.
  • A ClickHouse MV for the assertion projection: a retirement needs the retired row's content, which an MV can't look up.
  • Distributed publishers with lease-timeout takeover: a timeout alone is not fencing. This release fails closed instead, and integrity breaks are detected at read.

Existing bugs fixed along the way

  • as_of valid-time replay ignored valid_to, and as_of point reads served the head row, not the version current at T. Both are gone with the replay; valid_as_of / known_as_of answer from the journal.
  • The records plane used an inclusive valid_to, so at a supersession boundary both the old and the new record held. It is now half-open (record_validity_predicate).
  • close_triples' valid_to-only close and the edge repair recorded no close time. A graph read at an earlier K could not know a close came later. They now stamp closed_at.
  • The exposure ledger recorded keys only. It now records revisions, hashes and the cutoff.

Review follow-up (external review of the first commit, then rounds 6–8)

An external review of 10fcd4bcb raised 25 findings. Four were already fixed in rounds 1–4: redaction of temporal copies, checkpoints (removed), historical list, and one memory id for amend on a new key. The lease-takeover finding is covered by the post-insert read-back, with the ceiling on self-managed replication named in code and docs. The rest are fixed in e9cf80c85, d5d57765b and f324bec98:

  • The journal decides the current row. The projection worker reconciles loom.memory to what the journal says applies now: a version insert that failed after its commit, a row an amend could not write, a scheduled transition coming due. It skips a scope with a running or still-retried erasure. memory.set writes only what applies now; future transitions and corrections of another span go through memory.amend.
  • Writes:
    • Embedding rows land only after the journal accepted the version row.
    • Retries match on the idempotency body hash and replay the original receipt. A retry after the key moved on writes nothing.
    • The erasure fence runs under the lock, for worker passes too, and while a saga runs.
    • Sequences survive erasure and expiry (the published watermark row).
    • A repair re-plans, and replay stops below an integrity break.
    • The saga deletes the journal before tombstoning current rows.
  • Historical reads:
    • Today's high-sensitivity fence applies per key.
    • The live session, exclude, quality and minimum-similarity filters are honoured. run_id, entity_filter and a hard category return 422.
    • Type and tag filters apply before the row limit.
    • Attestations bind content.
    • Hashes are canonical.
    • get_by_id resolves through the journal.
    • A strict policy alone selects the temporal path.
    • A historical ask reads only its cutoff: no widening, completion, knowledge, record fallback, run notes, precedent, deep pass or code enrichment. It returns its cutoffs.
  • Reducer: claims under different qualifiers never supersede each other. A transition's bound is stated. A declared shape on unchanged content is a revision. Belief diffs report assessment changes with the journal's change kind.
  • Layering: the erasure-ledger queries moved into the erasure package (server/erasure/app/fence.py).
  • Wording: "competitor" and "competing" are gone from code, docs and tests (7ee472302). The product-name lint stays; it stores salted digests.

Reviewer rounds: 6 → 6 findings, 7 → 2, 8 → NO FINDINGS.

Second external review (of f324bec98), then rounds 9–12

A second external review raised 16 findings. All are fixed in 6b8f6812b; follow-up rounds landed in cdc4414ed, 707972d12 and 423b0647f.

  • Erasure versus background writers:
    • The saga deletes the journal before the derived tables.
    • Projection replay, the vector fill and the current-row reconciler re-check the journal after they write. A write that lost the race undoes itself.
    • One "held scope" predicate fences both publishers and the reconciler.
    • Publishers check it again after inserting.
  • Allocation:
    • A batch's sequence is recorded durably before its insert, and a failed record fails the write. A sequence is never handed out twice.
    • Reads cut at the committed head.
    • A trailing allocation whose insert never landed is stepped over once settled.
  • Retention: a retraction is kept as long as what it retracts.
  • Batches: an assertion retired in its own batch keeps its real birth sequence and time.
  • Recovery:
    • Driven by durable cursors (per-namespace checked sequence, plus a global valid-time cursor paged on whole instants) instead of a one-day window.
    • Compares serving metadata (pin, lock, sensitivity, attestation, expiry, confidence), not just values.
    • A namespace an erasure holds keeps its own single pending place and catches up later, without holding back other tenants.
  • Reads:
    • Today's high fence also reads the current row and unprojected commits.
    • Reads group per identity, and snapshots per qualifier.
    • Graph times are converted to UTC.
    • Belief diffs order undated bounds safely.
    • verification matches the current read.
    • A historical list sorts by recency and records exposure receipts.
  • Amend: keeps the key's expiry, pin, lock and tags.
  • Readability: the assertion↔row mapping is its own module (temporal_rows.py).

Reviewer rounds: 9 → 2 findings, 10 → 1, 11 → 1, 12 → NO FINDINGS.

Known, not from this PR: current-state memory.get_by_id intermittently misses conflicted rows, about 20% of reads in a probe. The miss rate is the same on the commit before this work, and it makes test_conflicts_resolve_cannot_reach_another_namespaces_rows flaky.

Third external review (of 423b0647f), then rounds 13–15

A third external review raised 12 findings. Its central point was that recovery inferred publication state from age and table presence, then relied on compensating deletes succeeding. The answer, in f3c9a2996, is two invariants enforced at read time:

  • Erasure cut. Content recorded before an erasure of its scope was requested is never served: not from commits, projection rows, history, the retry lookup or planning. That holds whatever a failed or overtaken cleanup left. A batch is stamped before its fence check, so any erasure requested later postdates every commit in it. Current rows are re-fenced after insert and removed again, rows and vectors, if an erasure overtook them.
  • On time. A commit belongs to the journal only if it landed within two minutes of its stamp. A late insert is ignored by reads, replay and retries. A publisher that sees its own insert land late withdraws it and fails the write.

Also fixed in that commit:

  • The allocation records its recording time, so time keeps rising with the sequence.
  • Today's high fence reads every unprojected commit, with no tail bound.
  • The reconciler waits for the projection to cover what it checks, catches held namespaces up to the advanced cursor, and fingerprints everything the current row serves.
  • memory_type and entities are assessed on a same-value write.
  • A retry keeps the committed memory id.
  • Belief diffs compare whole assertion state.
  • memory.amend had been writing validity dates as local time; it now writes UTC.

Follow-ups in 4be1c28a0, 3bdbc25d2 and 33816c8cb:

  • One clock (ClickHouse's) for every compared time.
  • A namespace erasure restarts the projection at the published head.
  • Erasure times read the ledger first and scan only erased users.
  • The reconciler can be scoped to one namespace (the tests use this).

Reviewer rounds: 13 → 4 findings, 14 → 1, 15 → NO FINDINGS.

Fourth external review (of 33816c8cb), then rounds 16–17

Fixed in 56795009e:

  • The after-insert erasure re-check runs whenever the current-row insert returns, even when it or the embedding write failed (the rows may have landed); the first error is raised after.
  • The erasure cut is read from the ledger alone. Filtering by which users a table holds ran in another snapshot than the content read.
  • A ClickHouse clock behind the journal's last commit no longer gets stamped past: a batch dated after an erasure its fence missed would be served.
  • Retry receipts carry the full identity, so a batch with one key under several users keeps each one's committed id.
  • memory.set takes the committed retry id right after the insert, so links, settle and audit name it. The plain path also answers a moved-on retry instead of retiring the live row's vectors.
  • The metadata recovery test builds its stale row instead of relying on merges.

Round 16 (0c123734d): a gap of a second or less (replica clock skew) is waited out; only a larger one refuses retryably.

Reviewer rounds: 16 → 1 finding, 17 → NO FINDINGS.

Fifth external review (of 1230a613a)

Fixed in f4efcdc62:

  • P1: a request cancelled during its loom.memory insert skipped the after-insert erasure fence (CancelledError is not an Exception). The insert and the fence now run in their own shielded task.
  • A durable retry whose key had not moved on rewrote its row with a freshly computed expiry, renewing the TTL with no commit. The row now takes the expiry its commit recorded, as it already took the memory id.
  • The journal hash and the vector fill used a procedural value's JSON, but memory.set embeds its situation, name and steps. One helper (stored_embedding_texts) serves the hash, the fill and the reindex.
  • The reconciler's serving-state fingerprint now includes verified_at.
  • The held-namespace integration test fixes its transition time just before the one amend that needs it, not before ten writes.
  • The analyzer corpus regenerates unchanged on this head (the merge refreshed it).

CI on the merge head, fixed in c30fcae40:

  • The provider rebuild failed on memory_temporal_vectors: invalidate_cache was honoured only for the table named embedding_cache. The checks now key on the declared action. A rebuild empties the vectors, the same state a model-label change leaves.
  • Integration tests still passed the removed as_of. Pydantic drops unknown fields, so two of them silently read the present.
  • server/memory/store/ was below its coverage floor: the journal store had 3/82 branches unit-covered. test_temporal_store.py brings it to about 72/82.

Review rounds 18–19 (two external reviews of e6b476c4a / 41a5a0204, in-house reviewer rounds 1–2)

The rounds closed these, among others:

  • Stable cutoffs: a cut never sits above an allocation still in doubt, so an acknowledged answer cannot change.
  • Clear and reject write versioned rows through the one funnel, so the journal retracts exactly what is removed.
  • Row versions are stamped under the lock, so loom.memory's merge and the journal agree on the latest.
  • Plain writes keep history: a dated write corrects its span, late evidence fills the past, and an undated write revises the current state.
  • The current row is what applies now, or the latest begun; it is never a plan.
  • The reconciler is bound to its cutoff and waits only on gaps that affect the head.
  • Durable retries are answered before guards meant for a new write.
  • Redaction runs entirely under the publisher lock.
  • Historical record queries match each revision's own typed field rows.
  • The leakage walk covers both temporal axes.

Release note: LOOM_MEMORY_TEMPORAL_PUBLISHER=process replaces this PR's earlier single-writer flag. The removed single-axis as_of on memory reads is served with ignored_args; use valid_as_of / known_as_of.

Later review rounds (in-house rounds 3–23, external reviews of a51ffcd65 and 35870e8ec)

  • Preconditions: a conditional write is checked against the row the handler checked. A metadata-only change since then (tags, pin, lock) no longer refuses it forever.
  • memory.move: a key with a scheduled change is not moved (409 SCHEDULED_CHANGE, with how to cancel the plan). The publisher re-checks under its lock, so a plan that lands mid-move cannot revive the source behind its redirect. Duplicate marks from the conflict judge are not affected.
  • memory.amend:
    • It takes the key's pin, tags, entities, type, whole lock and expiry from the claims it is planned against, not from an earlier head read.
    • A lock taken since that read refuses it.
    • The key's char_limit binds it.
  • namespace.rollback: it is planned and committed in the journal. Each key whose claims, as known at as_of, differ from what it serves now gets one commit that serves those claims again as they were, replacing what the key serves now. Spans, plans, snapshots and qualifiers come back as they were. A change that lived only in the journal, such as a past-span correction, is undone too. A key whose lock or a blacklist refuses the change is left out, and a redacted or erased value is never served again. The head-row planner and its loom.memory_versions reads are removed.
  • Current-row repair: the repair's last freshness check and its insert run under the publisher's namespace lock. Its version is the instant the projected state began (the key's latest commit, or a plan come due or a span ended), above every version the key holds. A write acknowledged meanwhile is never overwritten, and history and rollback read versions as recording times.
  • Write policy: memory.set and memory.amend share one classification policy (classify_value): the tier, its retention window and post-action, attribute tags and the level label. An amended value never keeps a tier lower than what it reads as.
  • Historical search:
    • It honours bodies (full, excerpt, none) and refuses unit and source.
    • With a scoped token it stops at the first namespace with a confident hit, as a current search does.

Final review rounds (in-house rounds 24–31, external reviews of 8bf3e8c82, 40b31a2a8 and 50c271505)

  • Publication ordering: a projection lands rows without moving the sequence, so the publisher re-reads each key's newest loom.memory version under the lock and raises the batch's rows (and the claims they add) above it, rather than replanning.
  • Historical asks take no pending turns from after their cutoff, and their hits carry the tags their assertion recorded, so the tag belt never checks today's.
  • Retries: memory.amend answers a durable retry from its commit, latest or not, before the guards for a new amendment (a lock or a blacklist rule added since).
  • Journal-only keys: memory.clear and memory.delete retract a key only the journal holds (a plan not yet due) and project the retraction. The delete finds it as the row lookup finds a row: exact identity first, then the newest match for the user, inside the request's read scope and the member-write author check.
  • Rollback vs redaction: under the lock, the rollback re-reads each value it restores from the journal's payloads and refuses if a redaction scrubbed one since planning.
  • Keeper-less ClickHouse: /v1/health and loom doctor name memory_writes_refused when the publisher would refuse every write, and that refusal carries no retry hint.
  • Pushed back: a stored value whose literal text is [REDACTED] cannot be rolled back to (the read model cannot tell it from a scrub; withholding is the safe side). Deferred: historical shared-scope search has no tag filter, because shared_versions has no tags column.

The final in-house round (31) reported no findings at any severity, and CI is green.

Operator note: migration renumbered to 039

Main took 028–038, so this PR's migration is 039_bitemporal_memory.sql. On earlier heads of this branch it was 027_bitemporal_memory.sql, then 028, 031, 032 and 033_bitemporal_memory.sql. Its new tables carry non_replicated_deduplication_window = 1000 themselves, as main's 032_table_settings.sql asks of tables created after it. A database that applied an earlier head of this migration lacks its later columns; rebuild it, or run: ALTER TABLE loom.memory_temporal_commits ADD COLUMN IF NOT EXISTS request_slot Int32 DEFAULT -1 AFTER request_sha256; ALTER TABLE loom.memory_temporal_commits ADD COLUMN IF NOT EXISTS request_outcomes String DEFAULT '' AFTER request_slot; ALTER TABLE loom.memory ADD COLUMN IF NOT EXISTS journal_version UInt64 DEFAULT 0; ALTER TABLE loom.memory_versions ADD COLUMN IF NOT EXISTS journal_version UInt64 DEFAULT 0; and the ALTER TABLE loom.memory_versions_mv MODIFY QUERY at the end of 039. No production database has run any of them.

The file was also edited after earlier heads were applied; for example, restated_assertion_id was added later. Its statements are IF NOT EXISTS, so a table an earlier head created would not gain the later columns. A dev or test database that ran an earlier head therefore needs to be rebuilt, not just migrated. At minimum, drop the journal tables and delete the stale ledger rows, then run loom migrate:

ALTER TABLE loom._migrations DELETE WHERE filename IN ('027_bitemporal_memory.sql', '028_bitemporal_memory.sql', '031_bitemporal_memory.sql', '032_bitemporal_memory.sql', '033_bitemporal_memory.sql');

If the ledger rows are left in place, loom migrate --strict exits 1 on the old filenames.

Tests

  • Unit:
    • test_temporal_model.py: oracle, U01–U06, U09, U14, U16, U18, U25, pointwise property test.
    • test_temporal_capture.py.
    • test_temporal_publisher.py: in-memory journal covering order, projection, uncertain insert, retry identity, strict fencing, erasure fence, tail reduction.
    • test_temporal_projection.py, test_temporal_settings.py, test_history_mirrors.py.
    • The erasure step-order and census goldens are updated.
  • Integration (test_bitemporal_memory.py):
    • the oracle over HTTP;
    • U01 transition vs correction (world and belief diffs);
    • U04 episodes and U22 delete history;
    • U08 / U14 / U06 modality, assessment and dispute;
    • U23 retry and reused key;
    • U25 a read ahead of the journal is disclosed as not ready;
    • historical search and unified coverage;
    • namespace erasure of every revision;
    • cross-tenant isolation;
    • verify-after-correction keeps segments;
    • clear / reject journaled;
    • the shared history mirror;
    • redaction of amend-born text by assertion id, across history, and refused on a locked key;
    • historical list filters match the live list;
    • the next write repairs an integrity break;
    • a key made high withholds its history; session filters; canonical hashes and strict policy; get_by_id through the journal; memory.set refuses future changes; the reconciler repairs lost and due rows; a historical ask stays at its cutoff; namespace erasure never reuses a sequence.
  • Latest run: unit 16,816 passed; integration (bi-temporal 37/37, plus erasure, idempotency, bulk, redaction, cross-tenant leakage) 81 passed; lint, typecheck and the schema check are clean.

🤖 Generated with Claude Code

Merge with main #32 (Keeper required)

Main now requires a Keeper everywhere, so the publisher's single-process mode is gone: LOOM_MEMORY_TEMPORAL_PUBLISHER, the second-writer check, memory.temporal_status.publisher and the memory_writes_refused problem are removed, and a namespace's commits are serialized by leases.cluster_lease.

Rolling upgrade: writes by a build that does not journal

During a rollout the previous build (N-1) writes loom.memory with no commit. Without care this build would serve the older value from the journal and its reconciler or a rebased write would put it back.

  • loom.memory.journal_version is the version this build stamped on its row (the insert funnel sets it). N-1 carries unknown columns forward (rolling-upgrade rule 2), so its rows keep an older stamp: a row whose version differs, newer than everything the key's journal names, is a write the journal has not seen.
  • The publisher journals such a row as a memory.observed commit (the change it made against what the journal serves, with no write-time policy) before the batch's own change; the reconciler adopts first and never rewrites over a foreign or newer head; while an older schema is live in loom.instances (plus a 15-minute tail) a sweep adopts the rest from a durable cursor, so temporal reads catch up.
  • An amendment (rollback, amend) replans when such a row lands between its plan and the lock, and adopts it first. namespace.rollback adopts the namespace's foreign rows drawn after as_of before it plans, so it undoes them. A key the journal learned of late from a row older than as_of (an adopted write, or a seed of a key created by then) is left out and named in the answer: the adoption was planned against a later state, so what the key held at as_of was never recorded as known then. Restoring those would change the knowledge-time rule for every reader, for a rollout-window case.
  • The mixed-version gate checks that one build's value survives the other's tags-only update, both ways.

A bulk request's first commit also records how it answered each entry that made no commit (request_outcomes), so a retry answers those exactly as before, never re-judged against the gate, the blacklist or the verdicts as they stand later. A bulk request that committed nothing at all records no outcome; its retry runs as a new request (it wrote nothing either way).

@zlareb1
zlareb1 force-pushed the feat/bitemporal-memory branch from 05595b7 to b9a6cb6 Compare October 15, 2026 07:40
zlareb1 and others added 2 commits October 15, 2026 14:38
…wn at K

Memory writes overwrote what they replaced: a correction rewrote what an agent
had been told, late evidence reverted the present, and a transition looked like
a correction. loom.memory_temporal_commits is now the authority. Every
insert_memory_versions batch is journaled first, under a per-namespace
publisher lock that allocates commit_seq; the publication is that insert.
loom.memory and the assertion projection are derived from the journal and
repaired from it.

Reads take valid_as_of and known_as_of on every memory read op, with
read-your-write tokens, coverage, gaps and exposure receipts. memory.amend
makes bounded corrections and transitions. Plain writes follow a narrow rule
set: an undated write revises the state that holds now, a dated write fills its
own span bounded by later states, and a row is written only when its claim is
current. Concurrent writes resolve as loom.memory's merge does (the later draw
wins). A row copied from a head merges over the journal (a three-way merge on
the columns it did not change), so a lock, pin, expiry or value committed
since is never undone. A key written before the journal is seeded at its first
write. Erasure cuts every read at the request time, and redaction reaches the
journal, the projection and the vectors.

Migration 028 adds the journal, assertion, watermark and vector tables, the
shared-memory history mirror, graph recording times and exposure receipt
columns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…k merges whole

A column-by-column merge read too much into "equal to what I read": a naive
whole-second expiry never equalled the journal's, so a read_only memory with a
TTL could not be unlocked; a replan merged an already-merged row; a set took on
a concurrent writer's sensitivity, a deletion or another claim's text. Now the
writer's changes are computed once, from the row it built, comparing as
loom.memory stores values. A write of a new value keeps its content and removal
and takes only the lock from the journal; a metadata write whose content moved
under it is left out, as is one whose text holds under several qualifier sets;
the expiry sweep holds only while what it read is unchanged. The lock (mode,
deadline, reason, by, at) is journaled and merges as one unit, and a lock binds
only what holds now. The reconciler compares a lock's deadline and always
checks keys that hold events.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zlareb1
zlareb1 force-pushed the feat/bitemporal-memory branch from 87f0aaa to bd6c36d Compare October 15, 2026 09:17
zlareb1 and others added 2 commits October 15, 2026 15:26
… from a copied row

Reading intent off which columns of a copied row differed kept finding new
holes: an equal value under new qualifiers was dropped, a key with one text
under two qualifier sets became unwritable, a stale write dropped a lock or
took on high sensitivity, a lock could loosen another. Writers now say what
they mean. A metadata write declares the columns it sets, and its row is built
from the journal's state with only those set; its assessment changes only
those, on what holds now and that content's history. A value write keeps its
own row; the lock is the journal's, a read_only lock refuses a new value, and
memory.set and bulk never replace a value pinned since their read. memory.lock
only tightens the journal's lock in force. An embedding row lands only with a
memory row the journal left embedded. The merge, its claim selection and the
"ambiguous" refusal are gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…value write only what it states

A restore wrote as metadata over a key nothing held, so the reconciler undid
it; it is a value write again. A metadata write planned when nothing holds now
is left out (never revives a key deleted under it), and an attestation of text
that no longer holds is left out. A metadata write assesses only claims of the
content its row shows; a restatement only what holds now, so the same text's
past and plans keep their sensitivity and pin; an expiry removes only the text
it found expired. A value write states what it sets (memory.set from its
input); its unstated pin, expiry, attestation and a sensitivity floor come from
the journal, not from its read. update_by_id that keeps the value is a metadata
write, and its vector lands only with the text it embedded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zlareb1 and others added 23 commits October 15, 2026 17:00
…rits is only what still holds

A pin inherited from the journal authorized replacing the pinned value, a new
value inherited an expiry that had already passed or a TTL meant for the
present, a server-computed retention window was overwritten, and the expiry
sweep on one text under two qualifier sets stalled. Now the pin guard reads the
caller's own pin before anything is inherited; a pin carries to the same text,
or for an update edit of a pinned value; an expiry carries only while it is
ahead and the write's own claim holds now; a handler states an expiry it
computes; the sweep proceeds on the claim it read and retracts only what has
expired, and a key whose last held claim went is removed, not shown as its
history. A metadata write on a recreated memory is left out. Updates declare
only the fields they supply, compare vectors by content and answer from the
accepted row. The retention test cleans every managed table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…its successor

existing=True checked only that the key still held claims, so an update paused
across a delete and a re-create wrote its value under the deleted memory's id
onto the new one. Every write that targets the memory it read is left out when
what holds now belongs to another memory id.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sed sensitivity keeps its window

The reconciler wrote a newly due plan under the old head's memory id, so the
memory-id checks then refused every delete, lock and update of that key. It now
writes the shown claim's own memory id. A row the sensitivity floor raises into
a sensitive tier takes that tier's retention window; a plan or late evidence
never inherits the present's expiry; an assessment always shows the revision of
the claim its row was built from; the pin guard reads the caller's own request,
not the pin a handler kept; a removal leaves the row the reconciler would
choose; and a stopped process's commits no longer refuse a restarted one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r a rebase follows the accepted row

An empty sensitivity, a null TTL, clear_expiry=false and a null tags list mean
"detect" or "keep", but their mere presence stated them, so a stale write could
lower a concurrent high classification or clear a deadline. A field now counts
as stated only when it carries a change. When an update's metadata landed on
text other than the one it read, its conflict verdict described the wrong text
and its search rows kept the old metadata: the verdict is dropped before any
peer change or settlement, and the accepted text's search rows take the
metadata the update set.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
When the claim holding now expired, the key fell back to its latest ended fact
in get and list, while search hid it: a TTL means "forget this value", not
"revert to the previous one". Removing what holds now now removes the current
row, and the reconciler never revives a removed row from ended history alone;
that history stays readable through valid_as_of and memory.intervals. Late
evidence with no end is judged by the span the journal stores, so it no longer
takes the present's TTL. A sensitivity raised by the floor keeps its label tag,
and a rebased concepts update mirrors its concepts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s claim's exact start

The reconciler read the head without tombstoned rows, so its guard against
reviving a removed row from ended history never saw one. An update copied the
row's validity, which loom.memory keeps to the second, as if stated: a claim
starting at .600 was revised from .000 and filed as the past while the answer
said updated. A revision of the memory it read now takes its claim's exact
validity, and a write journaled only for the past answers updated=false. An
amend's plan or past span no longer takes the present's TTL, and a raised
sensitivity replaces the old label instead of adding to it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An update states no validity or qualifiers of its own, so it took the row's:
truncated to the second, ended while a due plan waited for the reconciler (a
422), or unqualified on a key held under several qualifier sets (a new claim
beside the one it meant). It now revises the claim the current row shows, with
that claim's exact validity and qualifiers. A sensitivity level's label
replaces another level's, and leaves a user's own sensitivity tags alone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…aim's metadata

An update resolved the qualifiers of the claim it revises only after deciding
what it inherits, so it took another qualifier's pin or expiry; and its
if_match_sha256 was checked against the row, which behind a due plan still
showed an ended value. The shown claim is now resolved first, and the expected
hash is checked against what the journal holds when the update is planned. One
helper relabels sensitivity tags everywhere (update, bulk, consolidation, the
sweep, set), and a user's level tag on unlabelled content is not kept as a
label.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A set's if_match was checked against the row only, and a tags-only update's
not at all; the read-only guard compared a new value with every claim's text,
not the claim being changed; an empty restatement left the row's version
naming no assertion, so the claim it showed was guessed from content; a later
claim under other qualifiers bounded a write's expiry; char_limit:null kept the
cap. Now the target claim is resolved once and every hash precondition and
lock is checked against it in the journal, a restatement re-records its claim
at the row's version, only a same-qualifier successor bounds an expiry, the
search-tag mirror is stamped at the accepted version, and level labels match
case-insensitively everywhere, bulk's embedding included.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and a precondition is the row the caller checked

Re-recording a restated claim gave it a new id on every same-value re-set, so
expected_revision failed and the claim's birth moved. A restatement is an empty
commit again, and names the claim its row shows (restated_assertion_id), which
the planner reads for the current row. A conditional write is held to the row
its handler checked the hash against (the journal's claim must be the one that
row shows), rather than comparing hashes the journal computes differently for
normalised types: procedure.evolve's round trips 409'd. A refusal refreshes the
key's current row so a re-read sees what holds; a write naming new qualifiers
under a read_only lock is a new value; an expiry's peers are the qualifiers the
write inherits; a move copies what holds now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Its description still said text search (ILIKE over message content), while the
op ranks messages by embedding similarity, with thread, run and role filters and
substring matching only when the embedder is unavailable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… and a key with a scheduled change is not moved

A conditional write checked its hash against a row whose version a later
tag or pin had moved, and was refused forever; the claim that row shows is
the one checked. A move copied the current value while a plan not yet due
stayed on the source, which the plan would later revive behind its redirect.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n a plan has landed on the source

memory.move checks for plans before it writes, but an amend landing between that
check and the redirect revived the source behind its duplicate_of once the plan
came due. The publisher re-plans when the head moves, so checking there sees
every commit before the redirect's. The refusal now names the way out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…usal names the key left behind

The plan check keyed on duplicate_of, which the conflict judge's duplicate marks
also set: a near-duplicate on a key with a plan stayed unmarked. A move now says
it redirects through its write intent. A refused move left the destination
written under a memory id the caller never sees; the message names the key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Main took migrations 028-030, so the bi-temporal migration moves to 031. The
historical search legs use main's fan-out (namespaces_to_search) and report the
namespaces they skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…guards and shapes ordinary writes do

An amendment copied the key's pin, tags and lock mode from a head read before it
was planned, so a pin or tags committed meanwhile were lost, a timed lock lost its
deadline and reason, and a lock taken meanwhile did not refuse it; it now takes
them from the claims it is planned against, and the key's char_limit binds it.

Rollback reinstated a dated value as a restatement of its old span, so the key
kept today's value; a reinstated value is now a transition at the rollback. Its
search projections were written for rows the publisher refused; they now follow
the accepted rows, and the counts reported are the applied ones. A reconciled row
was stamped one nanosecond after its head, so a rollback to before an amendment
found nothing to undo; versions stay recording times.

A historical search ignored bodies, and with a scoped token read every fanned-out
namespace where a current search stops at the first confident one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…red with publication, and an amendment takes its tier's policy

A rollback re-emitted head rows as a state transition, which dropped a reinstated
value's own span, cancelled plans that existed at as_of, left a newer snapshot
served beside the older one, and could not undo a change that lived only in the
journal. It now plans from the claims each key served as known at as_of and
commits them again as they were, replacing what it serves now; the head-row
planner and its version-history reads are gone.

A current-row repair checked for newer commits before it drew a version and
inserted without the publisher's lock, so a write acknowledged in between was
overwritten; stamped at wall-clock time it also outranked a memory.set still in
flight. The check and the insert now run under the namespace lock, and the row is
stamped at the instant its state began.

An amendment kept the key's tier even when its value read higher, and copied the
old tags and expiry without the tier's retention window, post-action and label.
memory.set and memory.amend now share one classification policy, and a claim
under new qualifiers inherits nothing of another's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rollback no longer reinstates mirror rows; the journal never serves a redacted
value again, which test_namespace_rollback covers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zlareb1 and others added 23 commits October 16, 2026 23:44
…as_of, and an amendment replans over one that lands before the lock

The journal knows another build's write only once it adopts it, and a rollback
planned from the journal alone: during a rollout it reported success while
undoing none of the previous build's deletes or new keys. It now adopts the
namespace's foreign rows drawn after as_of before it plans. Older ones are not
adopted there, because an adoption is known from when it is made and the
rollback would undo a value served at as_of; the rule that leaves out such keys
now covers adoptions as well as seeds, and a seed of a key created after as_of
is rolled back (it held nothing then).

An amendment-only batch (rollback, amend) returned before the foreign-landed
check, so a previous-build write between plan and lock was overwritten in the
answer but left in place. Every batch now replans over it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ld changed before as_of

A change the previous build made before as_of is adopted after it, planned
against what the journal served then, so what the key held at as_of was never
recorded as known at as_of. Reconstructing it would mean re-planning the
adoption against an earlier state for every reader of knowledge time; the
rollback instead names the key as left out, as it does for a seed of a key
created by then. The test pins that branch of recorded_late, which no test ran.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ad stops growing with the namespace

memory.set measured p50 ~200 ms against ~70 ms without the journal: ~25 serial
round-trips, and the integration job ran past its timeout. The head read took
max over every commit of the namespace, twice per write (47 ms at 2M commits);
it now reads the newest commit in key order and the break window above it
(8 ms, same answers on all 994 local namespaces). The lease is inserted first
(read only once found held) and released after the section, off the caller's
path, with this process's queue opening once the release lands. Under the lock
the head, the clock and the landed versions are read in one round, the
in-doubt checks run together, and the refence reuses the stamp's clock. The
projection runs alongside the loom.memory insert (readers whose watermark lags
already reduce the tail). Measured p50 ~142 ms against ~68 ms.

The integration job's bound follows the ~170 tests this change adds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The plan snapshotted the head as allocated, which counts a sequence the
publisher has marked but not yet inserted. A plan reading in that window
missed the commit, and under the lock the head equalled its snapshot, so the
touched-keys check was skipped and the batch committed beside the claim it
should have retired: the key served two values. The head now also returns
the highest sequence that landed, and a plan snapshots that, so the commit it
could not read moves the head past it and the batch plans again. Sequences are
still allocated from the published head, so none is reused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…main

The setting, migration 039 dormant while it is off (applied once it is turned
on), the insert funnel's off path as main's write, the temporal worker gated,
journal_version owned by the journal alone, and wire fields marked for the side
of the flag they belong to (feature_modes: inputs reset and named in
ignored_args, outputs left out, MCP listing filtered). Restoring main's code
paths for the off side follows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
memory.amend, intervals, temporal_diff and temporal_status answer as an op main
does not have (HTTP 404, MCP unknown tool) and no listing names them while
memory_temporal_enabled is off; the contract tests run with it on, so every op
the registry holds stays covered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The plan read in five serial rounds; it now reads the head, the erasure state
and the projection's watermark in one (the watermark still ahead of the rows it
vouches for), then every per-key read, the retry lookup and the restated claims
in another. After the commit insert, its read-backs and the erasure fence run
together; the projection uses the plan's watermark (it only rises: one that
reached the batch's first sequence still does, one behind leaves the advance to
the worker) and runs from the row insert's start to the end of the after-insert
fence, which reuses the stamp's clock (an earlier time only widens its window).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ck again

The flag's contract is that off behaves exactly as main, and with migration 039
unapplied the journal planner has nothing to plan from. So the handler dispatches
on temporal_on() right after the future-as_of check: off runs main's head-state
rollback (domain plan, version-row reads, apply through insert_memory_versions)
restored verbatim in namespace_rollback_rows, with main's output fields and
sample shape; on keeps the journal path. Main's unit tests, the redact-revival
test and the analyzer legs for the restored readers come back with it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the journal off its migration is dormant, so a fresh replay produces
exactly main's schema: schemas/schema.sql is that again, and
schemas/schema_temporal.sql is the dump with the journal's migration applied.
Tests read an object from the default dump, or the journal's for an object only
it has; the RMT classification covers both. Generated SDKs and references
follow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The owner's rule for memory_temporal_enabled is that off behaves exactly as
main. The branch had deleted main's single-axis as_of replay from every read
leg, so an off-mode memory.get / get_by_id / list / search / ask / facts.* /
memory.record.query silently ignored as_of (the transport now hands handlers
main's as_of field when the journal is off). This brings main's replay back as
the off path: the as_of / status / tombstone predicates, the as_of plumbing of
the memory-table reads, the fact, chunk, summary, observation, graph and
records legs, the list cache key and duplicate follow, the ask's synthesis
"now", the synthesize-route skip and the PR-temporal gate. Pure-removal files
are main's verbatim; where the branch added journal paths, as_of sits beside
them (facts and records keep main's closed intervals, the journal keeps its
half-open record test).

Off-mode code also stops reaching journal-only pieces: the ask pipeline, pool
and code grounding check temporal_on() before temporal_requested() /
valid_as_of, and the exposure ledger writes its receipt columns only when the
journal's migration (039) is applied, since an off deployment's
memory_exposures table lacks them and every receipt insert failed.

Main's as_of unit tests come back (and pass against this code with the flag
off); the analyzer corpus regains its as_of variants, so shapes.txt again
covers main's replay statements.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
schema.sql is a replay with the default settings (the journal's migration
dormant), byte for byte main's; schema_temporal.sql is the replay with the
journal on. dump_schema writes and checks the file of the mode it runs in, and
CI turns the journal on after the default check to prove its migration applies
on top and matches its dump. `migrate --status` names a dormant file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The SDK's reads carry main's `as_of` (and `as_of_basis` on ask) again beside
`valid_as_of` / `known_as_of`: a server reads its mode's side and names the other
in ignored_args. The integration suite runs in the server's mode
(LOOM_MEMORY_TEMPORAL_ENABLED, set for both): `journal` tests need it on,
`no_journal` tests (main's as_of replay) need it off, the rest run in both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ing it off

The journal now ships behind LOOM_MEMORY_TEMPORAL_ENABLED, off by default, and
with it off Loom behaves as it did before the journal. Pages the journal PR had
rewritten as if it were always on would have told readers that every write is
journaled, that as_of is gone and that namespace.rollback plans in the journal,
none of which is true on a default deployment. Those pages carry main's text
again for the default, with the journal's behaviour kept in passages marked
"with bi-temporal memory on". A new feature page says what the journal adds,
what it costs per write (the reason it is off), what changes on the wire in
each mode, and the operator steps to turn it on and off; the latency and size
figures are placeholders to be filled from measurements. The migrations page
names the requires-setting directive that keeps migration 039 dormant, and
llms.txt is regenerated for the new page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Off (the default) keeps the required checks' names; a journal-on run of each
migrates the dormant migration and runs in that mode. The gate hands the mode to
both builds it launches.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With memory_temporal_enabled off, migration 039 never runs, so a write path
that still retracted through the journal, stamped its columns or read its
tables would either fail against missing tables or answer differently from
the build before the journal. Each write the branch rerouted now takes main's
path when the flag is off and keeps the journal's when it is on:

- memory.clear tombstones in place again (bulk_tombstone_scope, restored);
  delete, unpin, touch, lock, unlock, expiry and move redirect insert the
  version row they build, with no journal-only lookups or retractions.
- memory.set skips the valid-span 422 and the durable replay, counts a
  LoomServerError as infrastructure again, and labels sensitivity by
  appending (update, bulk, consolidation and the sweep likewise); bulk_set
  skips the retry read and gathers its two inserts as before.
- reject/negative escalation flip status in place; redact scrubs the one
  named row; procedure contention is a RuntimeError again.
- graph rows and the exposure ledger leave out the 039 columns; retention
  and the provider rebuild leave out the journal's tables.
- the drawn dedup token wins again except on the journal's commits table.
- erasure deletes and counts the journal's tables whenever they exist
  (residue of an earlier period with the flag on), and skips them otherwise.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…h names no dormant migration

The journal's steps and census rows ran (and asked system.tables) on every saga
whatever the mode. They now run while the journal's tables exist (the flag on, or
its migration in the ledger the server already caches for health and the schema
guard), so a deployment that never turned it on runs main's saga, step for step,
with no query of its own; one that turned it on and off still erases its rows.
schema_status leaves a dormant migration out of `pending`, so /v1/health no longer
reports the journal's migration as missing while it is off. main's erasure tests
run as the off contract; the branch's as the on one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
/v1/operations listed memory.amend and the other journal ops whatever the mode;
off, it now lists exactly main's ops (codegen still reads the full registry).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… are main's

/v1/admin/schema.status expected the dormant migration's tables and reported them
missing, and instances advertised schema 39 (the dormant file's number), which the
rolling-upgrade logic reads as a newer build than main's 38. Both now leave out a
dormant migration the ledger lacks; one applied while the journal was on is still
expected. The opt-in page carries the measured storage cost.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zlareb1 and others added 2 commits October 17, 2026 13:41
…'s either way

"Temporal" named main's own features too (valid_at, as_of, the timeline,
temporal search), which work the same with the journal on or off; the setting,
its knobs and the code's mode helpers now say bi-temporal. Table names are kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n again

The foreign-write sweep's first cursor sat five minutes before its first pass, so
a key written during a longer off period (or before a worker first ran) stayed
invisible to bi-temporal reads until written again. With no cursor yet it now
starts at the journal's first commit: every row drawn since that the journal did
not see is adopted, and anything older is pre-journal, seeded on its next write.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zlareb1
zlareb1 marked this pull request as draft October 17, 2026 08:34
@zlareb1 zlareb1 added the hold label Oct 17, 2026
@zlareb1

zlareb1 commented Oct 17, 2026 •

Copy link
Copy Markdown
Member Author

Putting this on hold for now. It works, and it's off by default behind LOOM_MEMORY_BITEMPORAL_ENABLED, but I want to think more about the design first. Journaled writes are about 2x slower than main, and keeping both paths adds a lot of code. I'd rather not take on that complexity until people actually need it. Details on #25.

@zlareb1 zlareb1 closed this Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: full bi-temporal memory and knowledge retrieval

1 participant