Skip to content

observe-extract marks an observation done from its head after the replay, so a delete, relabel or erasure made during it holds - #202

Merged
zlareb1 merged 12 commits into
mainfrom
fix/observe-done-fresh-head
Nov 3, 2026
Merged

zlareb1 merged 12 commits into
mainfrom
fix/observe-done-fresh-head

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

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):

An observation deleted, relabelled or erased while the observe-extract worker distilled its session no longer comes back with its old text or label when the worker marks it done.

Why

Failing case: the observe-extract worker reads a session's observations, runs the replay through memory.set_from_messages and the event and note calls (seconds to minutes), and then re-emits every observation tagged crystallize:done. Each DONE row was a copy of the row read before the model calls, stamped with a fresh next_version(). If, during the replay, the writer called memory.delete on an observation (a tombstone at a lower version), the sensitivity sweep relabelled it, or an erasure saga hard-deleted it, the DONE copy outranked that write under FINAL or re-inserted the row: the observation was live again with its original text and label. (memory.redact refuses a live head, so a redaction reaches an observation only after a delete, which is the first case.)

Pattern: a read-modify-write whose read is far older than its write, with a version drawn at write time. apply_entities_batch already avoids this: it draws its version, then re-reads the heads right before the insert.

Fix: right before the DONE insert, _distill_session re-reads the heads of the session's observations by exact identity key (memory_rows_by_identity_keys, sequentially consistent) and builds each DONE row from the head, at a version drawn before that re-read:

  • a key deleted or erased since the read is absent from the re-read and gets no DONE row;
  • a key whose text changed since (its content_sha256 moved) is left un-DONE, so a later pass that picks it up again (READY or the buffer threshold) replays what it now holds;
  • any other change since (a relabel to high, the READY tag from observe.crystallize) is carried, since the DONE row is built from the head;
  • the version is drawn before the re-read, so a write that draws its stamp after it stays above the DONE row, and the stamp is fresh, so the namespace's change watermark (namespace_version) moves as for any other write.

Scope and risk

Touches only the DONE rewrite in server/memory/workers/observe_extract.py. One extra FINAL read per distilled session, by exact keys in PREWHERE. observations_consumed now counts the rows marked DONE.

Residual window: any write to these keys that lands between the worker's re-read and its insert can still lose. A delete or relabel that drew its stamp before the worker's ranks below the DONE row; an erasure's hard delete has no version to rank by, and the DONE insert re-creates the row (the saga's residue census then fails it closed); an observe.crystallize write lands over DONE and the row is replayed once more. The window is one round trip plus the other writer's draw-to-insert time, down from the whole replay; apply_entities_batch accepts the same one. Closing it fully would need a key lock shared by the worker and every writer, which this change does not add. A head written after the stamp (the READY tag, a relabel) gets its DONE copy at that head's version + 1, since the copy carries what it holds.

A row whose text changed during the replay is replayed on the next pass, which costs one more extraction for that row. Two overlapping passes that both re-read before either inserts write two DONE copies of the same head; that is harmless, the later stamp wins with the same content.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none.
  • Rollback: reverting leaves no rows or schema behind.

Tests

  • New tests/unit/test_observe_replay_compact.py::test_done_is_built_from_the_head_as_it_is_after_the_replay: five observations, of which one is deleted, one given new text, one relabelled and one tagged READY during the replay. It fails on main (the deleted and rewritten copies are re-emitted with their old text, the relabel is lost) and passes with the fix (DONE rows from the unchanged, relabelled and READY heads, at one stamp drawn before the re-read, or above a head written after it).
  • tests/unit/test_observe.py::test_worker_promotes_ready_observation_via_existing_extraction now stubs the re-read and compares every column of the DONE row with the head's, with only tags and a newer version changed.
  • make format lint typecheck; the observe, extraction-policy, model-call switch and package-contract unit tests pass.

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

  • AI-generated (an agent wrote most of the diff): Claude Code. The failing case was checked by reading the worker, the redaction mutation and the version stamps, and the new test was run against main first.

  • 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. (format, lint, typecheck and the area unit tests ran locally; the full suite runs in CI)
  • Generated files are regenerated in this PR, not by hand: none affected.
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version: no plugin file changed.
  • The frontend builds and its tests pass, if frontend/ changed: not changed.
  • Docs under docs/ describe the system as it now is.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 2 commits November 3, 2026 10:10
…lay, so a delete, redaction or erasure made during it holds

The DONE rewrite re-emitted the copy read before the model calls at a fresh
version, which outranked a tombstone or redaction made during the replay and
re-inserted an erased row. It now re-reads each head right before the insert,
skips a key that is gone or whose version moved, builds the DONE row from the
head and writes it at the head's version + 1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…espace watermark moves

head.version + 1 kept a later write above the DONE row but left max(version)
unchanged, so known_version pollers and the cached list counts missed it. Draw
the stamp before the re-read, as apply_entities_batch does. Drop the in-place
redaction case: memory.redact refuses a live head. The worker test compares
every column of the DONE row with the head's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1 zlareb1 changed the title observe-extract marks an observation done from its head after the replay, so a delete, redaction or erasure made during it holds observe-extract marks an observation done from its head after the replay, so a delete, relabel or erasure made during it holds Nov 3, 2026
zlareb1 and others added 10 commits November 3, 2026 10:36
…rows it marks

A version move alone (the READY tag, a relabel) is carried from the head
instead of costing another extraction. observations_consumed counts the rows
marked DONE. The comment names the window that is left.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The re-read can return a head written after the stamp (the READY tag, a
relabel); the DONE row copies it, so it is written at that head's version + 1
instead of losing under FINAL. Comments trimmed; the docstring names the hash
the rewrite compares.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Keyed through the worker's own helper, the test could not catch a key the
store does not match. The DONE row's version is named before the call.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 4aec8d9 into main Nov 3, 2026
22 checks passed
@zlareb1
zlareb1 deleted the fix/observe-done-fresh-head branch November 3, 2026 18:02
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
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.

1 participant