Repository navigation
Conversation
zlareb1
force-pushed
the
feat/bitemporal-memory
branch
from
October 15, 2026 07:40
05595b7 to
b9a6cb6
Compare
…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
force-pushed
the
feat/bitemporal-memory
branch
from
October 15, 2026 09:17
87f0aaa to
bd6c36d
Compare
… 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]>
…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]>
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]>
…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]>
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]>
9 tasks
…'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
marked this pull request as draft
October 17, 2026 08:34
Member
Author
|
Putting this on hold for now. It works, and it's off by default behind |
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.
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(settingmemory_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.mdand on #25):memory.setis ~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);What off means
-- requires-setting: memory_bitemporal_enabledand stays dormant (not applied, not reported pending).schemas/schema.sqlis byte-identical to main's, andschemas/schema_temporal.sqlis the on state; CI checks both.instances.schema_versionand/v1/admin/schema.statusleave the dormant file out.journal_version). The journal worker is off, and the erasure saga is main's step for step unless the journal's tables exist.server/core/feature_modes.py: inputs are ignored and named inignored_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-rownamespace.rollback, main's clear, redact, quarantine and relabel, and the SDK'sas_ofarguments are restored.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
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.
UPDATE … FOR PORTION OFsplits a row into before / corrected / after). But their system time is a per-row transaction time, which needs real transactions.What Loom takes from each.
stated | extracted | inferred | unknown); continuity is never assumed.ClickHouse constraints that shape the design.
memory_versionscan't be the authority.ReplacingMergeTree … FINALis right for the current projection only if every re-emission carries every column.Value.
Measured cost (local single node, fake embedder, p50):
main(get 13 vs 10 ms, list 20 vs 18, search 40 vs 34).Deliberately out of scope for this PR.
search.queryreports them asnot_historical.ranking_current.Design
Authority: a commit journal.
loom.memory_temporal_commitsis 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: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 implementsassert,correct(bounded: keeps the supported segments around the corrected span),transition,retractandassess. 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:
commit_seq, withrecorded_atstrictly rising;loom.memorystays the current-state compatibility projection, written after the commit.Every writer is covered from one place.
insert_memory_versionsis the singleloom.memoryfunnel, and a hook registered inserver/wiring.pyjournals 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:
inserted_at) and deleting the rest.Projections.
memory_temporal_assertions(ReplacingMergeTree(projected_seq), born and retired sequences). A read at cutoff C admitsborn_seq <= C < retired_seq, then V. Filters run after the set is fixed.memory_temporal_projectionworker replays it without skipping gaps.Reads.
valid_as_of,known_as_of,read_tokenandvalidity_policywork on:memory.getandget_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 saynot_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_ofreplaces theiras_of).Answers carry their cutoff:
cutoff_seq,head_seqandhistory_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,qualifiersandexpected_revision. Write outputs gaincommit_seqandread_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_basisreplay is ignored (named inignored_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.
shared_versionsMV; historical shared searchmemory.record.query known_as_of, matched against each revision's own fieldsrecorded_atandclosed_aton edges and triples;facts.* known_as_ofPlanes with no historical reader yet (documents, digests, code, tracker) get no history writer;
search.querymarks themnot_historical.Erasure, redaction, retention.
memory_temporal.deleteandhistory_mirrors.deletesaga steps hard-delete every journal, projection, vector and mirror row in scope. The census counts them.memory.redactnames a value by a historical version or a journalassertion_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.loom.memory's rule: an assertion expires at itsexpires_at, else after the backstop; a commit outlives every assertion it added (retain_until); a vector goes with its last assertion.Alternatives rejected
memory_versionsas 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 historymemory.history, redaction and rollback read.time_nsversions as publication order: they give no cutoff a reader can name across keys and no crash contract. One sequence per namespace gives both.Existing bugs fixed along the way
as_ofvalid-time replay ignoredvalid_to, andas_ofpoint reads served the head row, not the version current at T. Both are gone with the replay;valid_as_of/known_as_ofanswer from the journal.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 stampclosed_at.Review follow-up (external review of the first commit, then rounds 6–8)
An external review of
10fcd4bcbraised 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 ine9cf80c85,d5d57765bandf324bec98:loom.memoryto 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.setwrites only what applies now; future transitions and corrections of another span go throughmemory.amend.publishedwatermark row).run_id,entity_filterand a hardcategoryreturn 422.get_by_idresolves through the journal.stated. A declared shape on unchanged content is a revision. Belief diffs report assessment changes with the journal's change kind.server/erasure/app/fence.py).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–12A second external review raised 16 findings. All are fixed in
6b8f6812b; follow-up rounds landed incdc4414ed,707972d12and423b0647f.verificationmatches the current read.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_idintermittently misses conflicted rows, about 20% of reads in a probe. The miss rate is the same on the commit before this work, and it makestest_conflicts_resolve_cannot_reach_another_namespaces_rowsflaky.Third external review (of
423b0647f), then rounds 13–15A 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:Also fixed in that commit:
memory_typeandentitiesare assessed on a same-value write.memory.amendhad been writing validity dates as local time; it now writes UTC.Follow-ups in
4be1c28a0,3bdbc25d2and33816c8cb:Reviewer rounds: 13 → 4 findings, 14 → 1, 15 → NO FINDINGS.
Fourth external review (of
33816c8cb), then rounds 16–17Fixed in
56795009e:memory.settakes 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.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:loom.memoryinsert skipped the after-insert erasure fence (CancelledErroris not anException). The insert and the fence now run in their own shielded task.memory.setembeds its situation, name and steps. One helper (stored_embedding_texts) serves the hash, the fill and the reindex.verified_at.CI on the merge head, fixed in
c30fcae40:memory_temporal_vectors:invalidate_cachewas honoured only for the table namedembedding_cache. The checks now key on the declared action. A rebuild empties the vectors, the same state a model-label change leaves.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.pybrings 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:
loom.memory's merge and the journal agree on the latest.Release note:
LOOM_MEMORY_TEMPORAL_PUBLISHER=processreplaces this PR's earlier single-writer flag. The removed single-axisas_ofon memory reads is served withignored_args; usevalid_as_of/known_as_of.Later review rounds (in-house rounds 3–23, external reviews of
a51ffcd65and35870e8ec)memory.move: a key with a scheduled change is not moved (409SCHEDULED_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:char_limitbinds it.namespace.rollback: it is planned and committed in the journal. Each key whose claims, as known atas_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 itsloom.memory_versionsreads are removed.memory.setandmemory.amendshare 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.bodies(full,excerpt,none) and refusesunitandsource.Final review rounds (in-house rounds 24–31, external reviews of
8bf3e8c82,40b31a2a8and50c271505)loom.memoryversion under the lock and raises the batch's rows (and the claims they add) above it, rather than replanning.memory.amendanswers a durable retry from its commit, latest or not, before the guards for a new amendment (a lock or a blacklist rule added since).memory.clearandmemory.deleteretract 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./v1/healthandloom doctornamememory_writes_refusedwhen the publisher would refuse every write, and that refusal carries no retry hint.[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, becauseshared_versionshas 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 was027_bitemporal_memory.sql, then028,031,032and033_bitemporal_memory.sql. Its new tables carrynon_replicated_deduplication_window = 1000themselves, as main's032_table_settings.sqlasks 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 theALTER TABLE loom.memory_versions_mv MODIFY QUERYat 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_idwas added later. Its statements areIF 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 runloom migrate:If the ledger rows are left in place,
loom migrate --strictexits 1 on the old filenames.Tests
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.test_bitemporal_memory.py):🤖 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.publisherand thememory_writes_refusedproblem are removed, and a namespace's commits are serialized byleases.cluster_lease.Rolling upgrade: writes by a build that does not journal
During a rollout the previous build (N-1) writes
loom.memorywith 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_versionis 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.memory.observedcommit (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 inloom.instances(plus a 15-minute tail) a sweep adopts the rest from a durable cursor, so temporal reads catch up.namespace.rollbackadopts the namespace's foreign rows drawn afteras_ofbefore it plans, so it undoes them. A key the journal learned of late from a row older thanas_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 atas_ofwas never recorded as known then. Restoring those would change the knowledge-time rule for every reader, for a rollout-window case.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).