Skip to content

The namespace.tune test compares a FINAL snapshot, so a merge or an extractor pass does not read as a write - #230

Merged
zlareb1 merged 5 commits into
mainfrom
fix/tune-test-counts-final
Nov 3, 2026
Merged

zlareb1 merged 5 commits into
mainfrom
fix/tune-test-counts-final

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Why

tests/integration/test_namespace_tune.py::test_tune_drafts_from_the_rows_and_changes_nothing fails at random: assert (10, 0) == (12, 0). Its counts() helper reads count() from loom.memory and loom.categories without FINAL. Both are ReplacingMergeTree(version), so the raw count moves without namespace.tune writing anything. A background merge between the "before" and "after" counts collapses row versions (12 to 10). The entity extractor, on by default, also writes a new version of a row it tags (apply_entities_batch), which can raise the count the other way.

The fix: the check compares a FINAL snapshot of the fields a write would change instead of a raw count: per memory row its agent, key, id, content_sha256, status, pinned, tags, tombstoned_at, actor, source_class and reinforcement_count, and per category its name, id, description and tombstoned_at. A merge cannot move it, the extractor's new versions do not touch those columns (version and entities are left out), and a revision, tombstone, pin, reinforce, re-stamp or new category still fails the check, as the module docstring promises. The cited row's version is compared with >= for the same reason: the entity extractor may write a newer version of it between namespace.tune and the memory.get that checks the citation; its id and content_sha256 must still match exactly.

Scope and risk

One test helper. No server code changes.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none.
  • Rollback: none needed.

Tests

tests/integration/test_namespace_tune.py against a local server and ClickHouse, three runs: 1 passed, 1 skipped each time. Those runs cannot show the race is gone, since forcing a merge or an extractor pass at the right moment is not practical here; the argument is that a FINAL snapshot of those columns is the same whatever versions exist. The failure above appeared on an unrelated PR's integration job.

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 both tables' engines in schemas/schema.sql.

  • 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.
  • 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 3 commits November 3, 2026 17:54
… does not read as a write

counts() read loom.memory and loom.categories (both ReplacingMergeTree) without FINAL; a merge between the two counts collapsed versions and failed the 'changes nothing' check (12 rows before, 10 after) with no write in between.

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

A FINAL count would miss a revision or tombstone of an existing row; the snapshot leaves out version and entities, which the entity extractor moves.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1 zlareb1 changed the title The namespace.tune test counts rows with FINAL, so a background merge does not read as a write The namespace.tune test compares a FINAL snapshot, so a merge or an extractor pass does not read as a write Nov 3, 2026
zlareb1 and others added 2 commits November 3, 2026 18:03
@zlareb1
zlareb1 merged commit 706d56d into main Nov 3, 2026
18 checks passed
@zlareb1
zlareb1 deleted the fix/tune-test-counts-final branch November 3, 2026 19:31
@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