Skip to content

memory.reject writes version rows, leaving no patch part on memory_embeddings - #213

Merged
zlareb1 merged 6 commits into
mainfrom
fix/analyzer-patch-probe
Nov 3, 2026
Merged

zlareb1 merged 6 commits into
mainfrom
fix/analyzer-patch-probe

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 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.reject and negative-outcome quarantine no longer switch off the codes-first vector read for every namespace. They now write the rejected status as a new row version instead of an in-place update.

Why

Failing case: on main, tests/integration/test_search_statements_pass_analyzer.py::test_patch_part_probe_and_reemit_reads_pass_the_analyzer fails with assert 1 == 0. The probe statement passes the analyzer. It then reads one active patch part on loom.memory_embeddings, where the test expects none. The statement passed on the two earlier main runs checked. The commit just before the failing run changed nothing near this table.

Pattern: integration tests run in a random order (pytest-randomly is installed and the integration step does not turn it off). The probe reads 1 whenever a test calling memory.reject (test_memory_import.py, test_cross_principal_leakage.py) runs first and no merge has applied the patch yet. _quarantine_by_identity ran UPDATE loom.memory_embeddings SET status = 'rejected', a lightweight UPDATE. On a local 26.10 server that statement on one row leaves exactly one active patch part.

The CI failure points at a production problem. While memory_embeddings has any patch part, patch_free() is False and the fact leg drops vector_search_use_quantized_codes = 1 for the whole table. One reject in one namespace therefore turned the codes-first read off for every tenant until a merge applied the patch. The docs listed this as the one exception to "no in-place updates on vector tables". This PR removes the exception.

Fix: reject_by_identity in server/memory/store/lifecycle.py reads the identity's live rows (every session of (org, namespace, agent, user_id, memory_key), as before). It then re-emits them with status = 'rejected' and the reason through write_versions_by_ids, the path supersession and conflict marks already use. Its status mirror writes the vector rows as new versions. Both memory.reject and the negative-outcome threshold call it. _quarantine_by_identity and its ALTER UPDATE fallback are deleted.

Scope and risk

  • Touches the two reject paths only. The usage fold's lightweight UPDATE on loom.memory stays: that table has no codes-first read.
  • The rejected status is visible as soon as the insert returns, the same as with the lightweight UPDATE. The id read, the memory row read and the status mirror's vector read are sequentially consistent, so a reject right after a memory.set finds both rows on any replica. write_versions_by_ids(strong=True) now also reads the mirror's vector rows sequentially (mirror_status_to_embeddings(sequential=True)). That applies to every caller that asks for strong.
  • The rows now carry a new version, one next_version() drawn before the id read, and land in memory_versions like every other lifecycle change. The old in-place edit left no history row. A memory.set that lands during the reject draws a higher version and stays the head, the same outcome as a set just after the old UPDATE. The drawn version also sits above any vector row a metadata copy left at read + 1 (the conflict resolver's judged stamp, entity tags, verify), so the status mirror does not skip it. A reject at read version + 1 would have skipped it.
  • A failed vector write now raises to the caller (write_versions_by_ids(strict=True) passes strict to the status mirror), as the failed UPDATE did. Without it the op would answer rejected=True while recall still served the row. A retried reject re-emits and mirrors again.
  • The statement corpus now drives the usage fold's UPDATE loom.memory SET .... The block-column check in tests/unit/test_table_settings.py reads its table list from the corpus, and the two reject UPDATEs were the only entries.

Compatibility, rollout and rollback

  • Wire: none. memory.reject takes and returns the same fields.
  • Operator steps: none.
  • Rollback: reverting restores the lightweight UPDATE. Rows already rejected stay rejected as version rows.

Tests

  • tests/unit/test_status_mirror.py::test_reject_writes_version_rows_and_updates_no_embeddings_part failed first on the two UPDATE statements. With the fix it passes: no execute, and the key's rows in two sessions are re-emitted rejected at one drawn version. Each vector row starts one version above its memory row and is re-emitted at that drawn version. test_reject_raises_when_the_vector_rows_are_not_written covers the strict mirror.

  • tests/unit/test_negative_escalation.py runs the threshold path through the real reject and checks the rejected memory and vector rows, the reason, and that no UPDATE is issued.

  • tests/analyzer/shapes.txt was regenerated (python -m tests.analyzer.corpus --write): the two reject UPDATE shapes are gone, and the id read and the usage fold's UPDATE are added.

  • Full unit suite (pytest tests/unit -p no:randomly) on the first head: 25667 passed, 1 failed (test_table_settings, fixed in the second commit).

  • Against a local ClickHouse 26.10 and a server from this branch: pytest -p no:randomly tests/integration/test_memory_import.py tests/integration/test_search_statements_pass_analyzer.py::test_patch_part_probe_and_reemit_reads_pass_the_analyzer passed 18 of 18, with the reject test first. Afterwards system.parts showed 0 patch parts on memory_embeddings. On the same server, the old statement on one inserted row left 1 active patch part.

  • make format lint typecheck, plus the unit tests around reject, outcome, write scope, import, mutation inventory, package contracts, public copy, agent instructions, doc links and the analyzer corpus: 570 passed.

  • Full unit suite on the rebased head (pytest tests/unit -p no:randomly): 25801 passed.

The one red check on the head is a failure main already has, which #179 fixes: tests/integration/same_key/test_retirement_ch.py (two tests, alias_merges() got an unexpected keyword argument 'cap'). The rest of the integration job passed, test_patch_part_probe_and_reemit_reads_pass_the_analyzer included.

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 cause was checked against the CI log, the patch-part count on a local server, and the doc that named the exception.

  • 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 regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • 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 (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • 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; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 6 commits November 3, 2026 14:29
…beddings

memory.reject and negative-outcome quarantine flipped status with a
lightweight UPDATE on loom.memory and loom.memory_embeddings. On the
embeddings table that leaves an active patch part, and while one exists
the patch-parts probe keeps the fact leg's codes-first read off for the
whole table. The integration test that runs the probe on the CI table
read 1 whenever a reject ran before it in the random order.

reject_by_identity in the lifecycle store now reads the identity's live
rows and re-emits them with status 'rejected' through
write_versions_by_ids, whose status mirror writes the vector rows as new
versions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The reject row takes its read version + 1, so a memory.set drawn after
the read stays the head. write_versions_by_ids passes strict to the
status mirror, so a failed vector write reaches the caller instead of
answering rejected=True while recall still serves the row. The
statement corpus drives the usage fold's lightweight UPDATE of
loom.memory, which the block-column table-settings gate reads. Tests
cover every session's row, the vector version and the outcome path's
inserts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
At read version + 1 the status mirror skipped a vector row a metadata
copy had already moved to read + 1 (the conflict resolver's judged
stamp, entity tags, verify), so recall kept serving a rejected row.
One next_version() drawn before the id read sits above every earlier
read + 1 copy, and a write drawn after it still stays the head.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
write_versions_by_ids passes strong to mirror_status_to_embeddings as
a sequentially consistent vector read, so a reject on another replica
finds a vector row written just before it. The docs no longer call
quarantine a lightweight update, and reject_by_identity is imported
from its module only.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the fix/analyzer-patch-probe branch from 8486b62 to 708d920 Compare November 3, 2026 14:34
@zlareb1
zlareb1 merged commit b53bfc8 into main Nov 3, 2026
21 of 22 checks passed
@zlareb1
zlareb1 deleted the fix/analyzer-patch-probe branch November 3, 2026 15:46
@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