Repository navigation
observe-extract marks an observation done from its head after the replay, so a delete, relabel or erasure made during it holds - #202
Merged
Conversation
…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]>
…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]>
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]>
… done 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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
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.
Changelog category (leave one):
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_messagesand the event and note calls (seconds to minutes), and then re-emits every observation taggedcrystallize:done. Each DONE row was a copy of the row read before the model calls, stamped with a freshnext_version(). If, during the replay, the writer calledmemory.deleteon 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 underFINALor re-inserted the row: the observation was live again with its original text and label. (memory.redactrefuses 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_batchalready avoids this: it draws its version, then re-reads the heads right before the insert.Fix: right before the DONE insert,
_distill_sessionre-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:content_sha256moved) is left un-DONE, so a later pass that picks it up again (READY or the buffer threshold) replays what it now holds;high, the READY tag fromobserve.crystallize) is carried, since the DONE row is built from the head;namespace_version) moves as for any other write.Scope and risk
Touches only the DONE rewrite in
server/memory/workers/observe_extract.py. One extraFINALread per distilled session, by exact keys inPREWHERE.observations_consumednow 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.crystallizewrite 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_batchaccepts 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
Tests
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 onmain(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_extractionnow 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
mainfirst.I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed. (format, lint, typecheck and the area unit tests ran locally; the full suite runs in CI)main; no merged migration is edited.frontend/changed: not changed.docs/describe the system as it now is.git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code