Skip to content

Expiry actions refuse stale source heads - #1057

Merged
zlareb1 merged 10 commits into
mainfrom
fix/issue-1029
Nov 20, 2026
Merged

zlareb1 merged 10 commits into
mainfrom
fix/issue-1029

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Closes: #1029
Related: #1038

Draft stacked on PR1038. This diff contains eight expiry-related files above its parent; shared writer-fence code is supplied by PR1038. Full CI begins after rebasing and retargeting to main.

Changelog category (leave one):

  • Critical Bug Fix (data loss, cross-tenant read, auth bypass)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

Expiry actions refuse a memory changed after its source head is selected for planning. The sweep retries unchanged candidates and leaves moved heads for a later pass.

Why

The sweep planned a full-row copy from an expired candidate and inserted it at a higher version. An update that completed between the scan and insert could be overwritten. Both expiry insert attempts request exact-head admission under the shared memory writer fence. A read outside that fence would leave another check/insert race. Postgres can refresh a scan to a renewed head with the same version, so eligibility is checked independently before planning.

Scope and risk

The shared writer fence is merged. This branch applies only the ten expiry commits on top of the merged fixes. The concrete writer-drain and bounded-send cutover procedure remains linked from the storage-authority guide.

The change covers tombstone, demote and anonymize actions, including same-version authored changes and partial-batch retries. Before planning, the sweep rechecks expiry on every authoritative source, including equal-version renewals. Postgres still replans from rewritten heads that remain expired. The exact comparison applies after that selection. Acknowledged actions keep their announcements and mirrors even when cancellation repeats during those follow-ups, then raise the original cancellation. Refused candidates produce no search mirror or webhook event. The exact comparison excludes recall_count, evidence_count and last_recalled_at; their in-place usage updates remain outside this fence. The moved_skipped field description covers both storage authorities and unchanged candidates left by a second whole-batch refusal. Dry runs and empty scans still write nothing. Tests cover an update after the scan, a writer arriving inside the protected check/insert window, and a head moving during retry.

Compatibility, rollout and rollback

  • Wire: no operations, fields or defaults change; the generated moved_skipped description drops the obsolete ClickHouse-zero claim.
  • Operator steps: no settings, backfill or schema changes in this PR. Replace all old API and worker processes, drain remaining old writers and settle their outstanding inserts before relying on the writer fence. The unchecked race persists with unfenced legacy writers during the transition; in-place counters and redaction mutations remain outside the guarantee.
  • Rollback: reverting the expiry admission checks restores the prior sweep behavior; no stored-data conversion is needed.

Tests

  • Earlier preparation: 1,036 focused expiry, callback, admission, publication, Postgres, API-contract and documentation tests pass with two workers. The expiry change remains within its eight-file scope.
  • Six event-driven cases fail before the repeated-cancellation fix: cancellation during an owed announcement or mirror skips committed follow-ups for each of the three actions. They pass after protecting the full sequence, preserving the original cancellation; the three pre-admission no-side-effect controls pass throughout. The earlier single-cancellation regression also remains covered.
  • Historical private ClickHouse evidence on the prior reviewed parent: all 12 two-client cases and all 12 analyzer cases passed, covering newer and same-version rewrites and renewals across all three actions. These live cases were not rerun for this expiry follow-up update. The history assertion counts distinct version stamps because equal stamps share a merge key, and reads with sequential consistency so a lagging replica cannot undercount the renewal.
  • Historical benchmark-harness unit evidence: all 251 tests passed before this rebase; no paid benchmark ran.
  • Thirty production-helper cases cover cleared/future renewals at equal and newer versions, still-expired authoritative rewrites, read-only/no-delete/lapsed locks and existing pin policy. The six equal-version renewals fail before the eligibility filter; all controls pass. No rejected renewal produces a commit, announcement or mirror.
  • The retry regression includes an unchanged third candidate: two heads move across the two attempts, and all three candidates are counted as skipped without an insert or follow-up.
  • The earlier focused group includes the parent absolute-deadline suspension regressions and expiry admission/cancellation paths. Lint, typecheck, all generator checks, formatting and prose checks pass.
  • Final merged-main composition: 530 focused expiry, Postgres-authority, lease and publication tests pass. Format, lint, typecheck and generator checks pass. Expiry runtime code and both expiry test files match the independently reviewed source byte for byte. Full hosted CI and a fresh review of this rebased composition are incomplete at merge.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated: Codex wrote the change and regression tests. Validation covers stale scans, retry contention, the shared-funnel inventory, and real ClickHouse readback.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are current; the operation reference reflects the field-description correction.
  • No migration is required.
  • No plugin files changed.
  • No frontend files changed.
  • Architecture docs describe admission, retry and rollout requirements.
  • Repository prose passes public-copy checks.
  • Commits are signed off.

@vercel

vercel Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Nov 20, 2026 8:56pm UTC

Request Review

@zlareb1
zlareb1 changed the base branch from fix/issue-1028 to stack/issue-1029-parent-6cb861a1 November 20, 2026 17:56
Check expiry plans under the shared memory writer fence before inserting their versions. Recheck refused batches and retry only the unchanged candidates.

Signed-off-by: Lareb Zafar <[email protected]>
Construct complete persisted rows so the two-client regression runs against ClickHouse.

Signed-off-by: Lareb Zafar <[email protected]>
Record each accepted batch before holder cleanup and retain its mirror and announcement in cancellation cleanup. Cover same-version authored changes and cancellation before and after acknowledgement.

Signed-off-by: Lareb Zafar <[email protected]>
Writes with equal version stamps share the history sort key. Assert the distinct source and renewal versions so background merges do not change the expected count.

Signed-off-by: Lareb Zafar <[email protected]>
A strong head read applies only to that statement. Read the version history in its own consistency scope so a lagging replica cannot hide the committed renewal.

Signed-off-by: Lareb Zafar <[email protected]>
ClickHouse expiry can refuse moved heads, so its reported count is no longer always zero.

Signed-off-by: Lareb Zafar <[email protected]>
Protect the full announcement and mirror sequence with the existing cancellation helper, then preserve the original cancellation. Document authoritative source selection before admission, including the still-expired Postgres head refresh.

Signed-off-by: Lareb Zafar <[email protected]>
Postgres keeps equal-version authoritative heads without rechecking expiry. Qualify candidate selection separately from exact admission so the documentation does not promise that every renewal is skipped.

Signed-off-by: Lareb Zafar <[email protected]>
Recheck expiry on every selected source before planning. Postgres permits equal-version replacements, so exact admission alone can accept a plan built from an already renewed head. Keep shared head selection and still-expired replanning intact.

Signed-off-by: Lareb Zafar <[email protected]>
A second refusal leaves unchanged candidates in the remaining batch too. Document that accounting and extend the retry control to retain an unchanged third head.

Signed-off-by: Lareb Zafar <[email protected]>
@zlareb1 zlareb1 changed the title Expiry actions leave concurrently updated heads unchanged Expiry actions refuse stale source heads Nov 20, 2026
@zlareb1
zlareb1 changed the base branch from stack/issue-1029-parent-6cb861a1 to main November 20, 2026 20:54
@zlareb1
zlareb1 marked this pull request as ready for review November 20, 2026 20:54
@zlareb1
zlareb1 merged commit c9c3284 into main Nov 20, 2026
1 of 2 checks passed
@zlareb1
zlareb1 deleted the fix/issue-1029 branch November 20, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The expiry sweep overwrites a memory updated during its scan

1 participant