Skip to content

A lock, unlock or verify replaces a write that already returned #1028

Closed

Description

@zlareb1

Component

Memory and search

Describe what's wrong

On the default ClickHouse memory authority, memory.lock, memory.unlock and memory.verify replace a memory.update that has already returned.

Each op reads the head and inserts a full version through insert_versions_over_heads. With LOOM_STORAGE_AUTHORITY=clickhouse that insert does not check that the head is still the row that was read. version_over is taken when the copy is built, so the copy's version is later than an update committed from the same head a moment earlier. loom.memory is ReplacingMergeTree(version), so the copy becomes the head and still carries the value from the read.

strong=True on the head read waits out a lagging replica. It does not stop a writer that commits between the read and the insert.

With LOOM_STORAGE_AUTHORITY=postgres, the same insert commits only when the head is still that version (heads_unchanged(exact=True)). A moved head raises 503 ADMISSION_CONTENDED. The ClickHouse path does not.

Run on commit 5fbc62c with pg.enabled() false. handle_memory_lock read a head whose value was proposed at version 100. version_over of that head was taken first, standing in for an update that had already returned. The lock insert that followed stored proposed at a higher version. Two HTTP clients against ClickHouse were not run.

Does it reproduce on the latest release or main?

Yes

How to reproduce

Default settings (LOOM_STORAGE_AUTHORITY=clickhouse). Auth is not required for this sequence.

  1. memory.set a key to proposed.
  2. Start memory.lock on that key and pause it after the head read, before the insert.
  3. memory.update the same key to rejected and wait until that call returns.
  4. Let the lock insert finish.
  5. memory.get the key.

The get returns proposed, with the lock columns. The update already returned success for rejected.

memory.unlock and memory.verify do the same thing: build_memory_version_row from the head they read, then insert_versions_over_heads. No migration was read; ClickHouse was not queried.

Expected behavior

A write that has returned stays the head, unless a later write read that new value. docs/architecture/storage-authority.md says a copy on the ClickHouse authority is a plain insert, and a write with a lower version that lands between the read and the insert is overtaken and nothing reports it. The Postgres path refuses that copy. Lock, unlock and verify should refuse or retry when the head has moved, on both authorities.

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

The in-process lock insert is the reproduction. It shows the copy that ReplacingMergeTree(version) would keep. It is not two concurrent HTTP calls.

Redaction

  • I removed tokens, keys, passwords and personal or customer data from everything above.

Activity

  1. added
    bug
    on Nov 20, 2026
  2. zlareb1 commented on Nov 20, 2026

    @zlareb1
    MemberAuthor

    Related: #1029

    The expiry sweep builds its version from the scanned head and inserts it through the same insert_versions_over_heads path.

  3. self-assigned this
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions