Skip to content

memory.update_by_id leaves a hash-only audit row, and memory.update's no longer holds the value - #242

Merged
zlareb1 merged 10 commits into
mainfrom
fix/update-by-id-audit-row
Nov 4, 2026
Merged

zlareb1 merged 10 commits into
mainfrom
fix/update-by-id-audit-row

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in a release)

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

memory.update_by_id now leaves an audit row, and the memory.update audit row no longer contains the new value. Both rows hold only the key, memory id, content hash, source class, version and verdict.

Why

Failing case: memory.update_by_id(memory_id=X, value="new") writes a new version with a new content_sha256, and loom.audit_log gets no row. The op was declared audit=False and its handler (server/memory/app/update.py) wrote no row of its own. memory.update runs the same _update_live_row and was audited by the transport, so a revision was audited or not depending on how it was addressed.

Pattern: the transport audit for memory.update had no audit_subject, so its subject was the whole input, with the new value in it. It was also written on a not_found answer, which changes nothing. The memory-plane rule says every write that creates or changes memory leaves one hash-only audit row. memory.bulk_set and the embedded path of memory.set write their row in the handler. update_by_id cannot use a transport row, because its request carries no namespace and the row would be stamped -.

Fix: the shared revision path (_write_revision) writes the row as soon as the version row is in, beside the memory.revised event (_record_revision). So a revision whose version landed is audited even when a later step (embedding insert, supersession, edges) fails. Everything in the row comes from the written version row: event_type = the op name, that row's namespace, the caller as actor (as memory.set names it; - with no token), the request id, and a subject of memory_key, memory_id, content_sha256, source_class, version and the verdict the write was checked with. Under if_match_sha256, that row is built from the head re-read under the key lock. Both ops are now audit=False, so the transport writes no second row.

Scope and risk

Touches only the two revision ops. Out of scope: memory.set's plain-insert path (non-embedded types and high rows) writes no audit row; that is a separate fix. Each revision now awaits its audit row's waited insert inside the handler; for memory.update that wait used to fall after the measured handler time. So both base budgets and their webhook shapes rise by one ch_batched_insert_wait_max_ms (memory.update 170 / 220, memory.update_by_id 130 / 180). The row's verdict is duplicate for a version written as one (as memory.set records it), else the conflict check's, before post-write marking, because the row is written as soon as the version lands. The audit page says so. The audit write is fail-open (audit.emit), as it is for memory.set, so a failed insert never fails the revision. memory.touch (an expiry-only rewrite, audit=False) is left as it is: whether an expiry change counts as changing memory is a separate design question.

Compatibility, rollout and rollback

  • Wire: no op or field changes. The latency budgets above change. The audit flag of memory.update in the op table and SDK OPS changes from true to false, because the handler now writes the row. The subject of a memory.update audit row changes from the input body to the hash-only shape. A reader that parsed value or reason from it no longer finds them. Its actor changes from the bare token subject (anonymous with auth off) to kind:subject (- with no token), as memory.set's row already names it. In-process revisions (the decision extractor's tag rewrite through memory.update_by_id) now leave a row too.
  • Operator steps: none.
  • Rollback: reverting brings back the old behaviour. Rows already written keep their shape: memory.update rows written before this change hold the input value in subject, and erasure does not reach loom.audit_log (the census lists it as holding no memory content). This change stops new ones. What to do with the existing tamper-hashed rows is left to a follow-up.

Tests

  • tests/unit/test_memory_update_by_key.py::test_a_revision_leaves_one_hash_only_audit_row_in_the_rows_namespace[memory.update|memory.update_by_id] checks that exactly one loom.audit_log row is written, with the row's namespace, the bound request id and the exact hash-only subject, and that the value does not appear. Both cases failed before the fix (no row).
  • test_a_conditional_revision_audits_the_head_it_wrote_from: under if_match_sha256, the subject's source_class is the re-read head's.
  • test_a_revision_that_fails_after_its_version_lands_is_still_audited: a supersession failure after the insert still leaves the row.
  • test_a_revision_written_as_a_duplicate_is_audited_as_one[merge|duplicate]: the subject's verdict is duplicate.
  • test_a_revision_that_is_not_conflict_checked_is_audited_with_no_verdict[episodic|high]: no conflict check ran, so the verdict is empty.
  • test_a_revisions_audit_row_names_the_caller_not_the_earlier_writer[token|no-token]: the actor is the caller's (- with no token), never the row's earlier writer.
  • test_an_update_that_finds_no_row_leaves_no_audit_row: an id that does not resolve writes no row.
  • Ran make format lint typecheck, the memory update, write-lock, revision, conflict, scoped-token, toolset, audit-subject, public-copy and doc-link unit tests, and the SDK and docs reference generators.

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. I checked the audit path end to end (transport post_handler_rows, audit.emit, the namespace a by-id request carries) and the generated table diffs.

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

Checklist

  • make format-check, make lint and make typecheck pass; the targeted unit tests above pass locally, and CI runs the full unit and integration suites.
  • Generated files are regenerated in this PR, not by hand.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • 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 10 commits November 4, 2026 00:46
… no longer holds the value

memory.update_by_id was declared audit=False and its handler wrote no row,
so a revision by id left no trace in loom.audit_log. memory.update, on the
same write path, was audited by the transport with the whole input as the
subject, the new value included, and also on a not_found answer that wrote
nothing.

The shared revision path now writes one row after the version lands:
key, memory id, content_sha256, source_class, version and verdict, never
the value, in the row's own namespace (an update_by_id request carries
none). Both ops are audit=False so the transport adds no second row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…at row

The row now goes out beside the memory.revised event, so a revision whose
version row is in leaves it even when a later step (embedding insert,
supersession, edges) fails. Its namespace, actor, source_class, version and
hash come from the version row written, which under if_match_sha256 is built
from the head re-read under the key lock. It carries the request id, as the
transport row did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…s its verdict

Each memory.update / memory.update_by_id now awaits its audit row's waited
insert inside the handler, so both base budgets and their webhook shapes
rise by one ch_batched_insert_wait_max_ms. The audit page says the row's
verdict is the conflict check's, before post-write marking.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…as memory.set records it

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…n unchecked revision's empty verdict is documented and tested

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
With no token the row says '-', as memory.set's does; the version row keeps its own fallback to the previous author.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…rite's own row names its actor

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…'s actor; a decision-extract test comment matches the handler-written row

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit c6fe72e into main Nov 4, 2026
22 checks passed
@zlareb1
zlareb1 deleted the fix/update-by-id-audit-row branch November 4, 2026 13:15
@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