Repository navigation
Description
Component
Background workers
Describe what's wrong
memory_expiry_sweep can overwrite a memory that a concurrent update already saved.
The pass loads expired candidates, plans tombstone, demote or anonymize from those rows, and inserts that plan with version_over at insert time. On the ClickHouse authority, authority_heads returns the scanned rows and does not load a newer head. The insert is the same plain insert_versions_over_heads a lock uses. A renewal or edit that committed after the scan and before the insert has the lower version, so the sweep's copy becomes the head. The copy still has the value from the scan, then applies the expiry action (a tombstone, a demoted confidence, or the anonymized marker).
_still_expired would keep a newer head only when that head is still expired. On ClickHouse it never sees a newer head, because authority_heads returns the scanned row.
With LOOM_STORAGE_AUTHORITY=postgres, a head that moved raises AdmissionContendedError and the pass leaves that key for the next scan.
Run on commit 5fbc62c with Postgres disabled. authority_heads was given a scanned row proposed at version 100 and returned that same row. It did not read a newer head. The sweep insert itself was not run against ClickHouse.
Does it reproduce on the latest release or main?
Yes
How to reproduce
Default settings (LOOM_STORAGE_AUTHORITY=clickhouse). One memory whose expires_at is in the past.
- Start one expiry pass and pause it after
find_expired_candidates, before the version insert. memory.updatethat key: set the value torejectedand clearexpires_at(or change only the value). Wait until the update returns.- Let the pass insert.
memory.get then shows the sweep's version, built from the scanned row, not the update that returned. A tombstone action deletes the key. A demote or anonymize action keeps the scanned value.
No migration was read; ClickHouse was not queried.
Expected behavior
Expiry applies to a head that is still the expired row the pass judged. A head renewed or rewritten since the scan stays as the update left it, and the next pass decides again. That is what the Postgres path does when the head moved. docs/architecture/storage-authority.md describes the ClickHouse copy as a plain insert that overtakes a write of a lower version.
Environment
Source: ClickHouse/loom main, commit 5fbc62c21a, package version 1.3.0
Python: 3.14.6
Platform: macOS arm64
LOOM_STORAGE_AUTHORITY: clickhouse (the default)
ClickHouse: not queried
Related issues and pull requests
Related: #142
How this was found
An AI tool found it, and I have not reproduced it myself
Additional context
What was executed is authority_heads on the ClickHouse authority, plus the insert path shared with lock. The two-caller interleaving was not run against ClickHouse.
Redaction
- I removed tokens, keys, passwords and personal or customer data from everything above.
Activity
zlareb1 commentedon Nov 20, 2026
Related: #1028
Lock, unlock and verify use the same plain insert. A moved head is refused only when
LOOM_STORAGE_AUTHORITY=postgres.