Repository navigation
Erasing a code namespace removes its cached code.ask answers - #1585
KaloyanNaumov wants to merge 5 commits into
Conversation
The erasure step for cached code.ask answers deleted only those that quoted the erased namespace's memories (`memory_namespace`). An answer asked in the erased code namespace carries the repository's code in its text and was left in `loom.code_answers`, uncounted by the residue census. After a re-index of the same commit it was served again, since the cache invalidates only when a cited file changes. The step and the census now match a row by `namespace` as well as `memory_namespace`. The delete stays a lightweight delete read sequentially, and the census still skips a tombstone that holds no text. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
The architecture doc still said an answer drawn from the code index alone stays; a namespace erasure now deletes it with the code namespace it was asked in. The module docstring of the answer-cache erasure tests, the `namespace_tables` docstring and one test docstring described the old predicate, and the comment on `KEEP_TABLES` now says only what is not purged there. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
zlareb1
left a comment
There was a problem hiding this comment.
Namespace erasure reaches existing code-only answers. The cache writer also needs to prevent a concurrent ask from restoring erased text.
|
Thanks for the review. Converting to draft while I address it; a new head and the replies will follow, so no need to look at this head again. |
… ones An ask can finish synthesizing after the namespace delete and the final census. The answer cache skipped its erasure check when the answer quoted no memory, so a code-only answer could land in the erased namespace. Run the before-and-after write guard for every answer, and delete a code-only answer that lands after the mark by its own key. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
zlareb1
left a comment
There was a problem hiding this comment.
The synthesis and branch-reuse paths now check erasure around cache writes. Negative cache entries still need the same protection.
|
Thanks, I've seen the new comments. Back to draft while I address them; a new head and the replies will follow. |
…ounted by its census An abstaining ask that overlapped a namespace delete could recreate its cached question afterwards: the negative entry was written without the erasure check, and the census skipped it because its answer and citations are empty. The negative write now runs the same before-and-after guard as a synthesized answer, and the namespace census counts a row that holds a question. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…nly guard Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
zlareb1
left a comment
There was a problem hiding this comment.
Namespace erasure deletes positive and negative cache entries, including rows that hold only the question. The write guards cover a concurrent erasure. All 142 focused tests passed with ClickHouse 26.11.2.4.
Closes: #1579
TL;DR: Erasing a code namespace left the cached
code.askanswers asked in it inloom.code_answers, because the erasure step and the residue census matched only the memory an answer quoted. Both now also match the namespace the answer was asked in.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 erasure of a code namespace now deletes the cached
code.askanswers asked in it, and the residue census counts them. Before, they stayed inloom.code_answerswith the question, the answer text and the citations of the erased repository, and a re-index of the same commit served them again.Why
code_answers.delete, the saga step that ownsloom.code_answers, deleted bymemory_namespace = {ns:String}. That column names the memory namespace an answer quoted (migration 086),''for an answer drawn from the code index alone. So an erasure removed the answers that quoted the erased namespace's memories, in whichever code namespace they were asked, and no answer asked in the erased code namespace. The census row for the table used the same predicate, so it counted what the step deleted and the saga passed with the rest still there. The code index purge skips the table (KEEP_TABLES), so nothing else took them.What stays is the question, the answer text the LLM wrote from the repository's code, and the cited paths, line spans and symbols. After a re-index of the same commit the cited files hash as they did, so the cache serves the answer again: it invalidates only when a cited or shown file changes (
_files_current).The fix is one predicate,
ANSWER_NS_EQ = (namespace = {ns:String} OR memory_namespace = {ns:String}), used by the step and by the census row'sns_pred:sequential_reads) and still runs a lightweightDELETE: the table carries a vector column a mutation would rewrite. Every version goes, tombstones included, as before.INthrough the existingns_list_predicate(it replacesnamespace = {ns:String}insidememory_namespacetoo), so the step and the census read one predicate for a list.answer != '' OR citations != '' OR question != ''). A negative entry, which an abstaining ask caches, holds only its question, so it counts; a tombstone keeps the question too, and counts until the same step deletes every version. The user-scope census still reads answer text and citations alone.This reverses a position the code states. The comment on
KEEP_TABLESinserver/code/app/index/retire.pyreads: "Telemetry stays: what a caller searched and what was answered is the deployment's audit trail, keyed by namespace but not the repository's content." Our argument against it:copy_residue(server/erasure/store/provider_copies.py:55-60) already counts a rebuild copy of this table bynamespace IN ... OR memory_namespace IN ..., so main's own copy census treats an answer asked in the namespace as residue. The main-table census was the outlier._files_current), which an audit trail should not do.The evidence is thin on one side: the one row we found was a fake-LLM echo with no repository code, and the re-serve comes from reading the code, not from observation. If answers are meant to stay as an audit record, the smaller change keeps the rows but stops serving them once their namespace is erased, and states in the docs that the residue claim does not cover them; we will implement whichever you prefer. The comment on
KEEP_TABLESnow says only what is not purged there.Alternatives:
answers-purge --applyafter an erasure is today's workaround. It is an operator step the erasure runbook does not name, it tombstones rather than deletes, and it runs after the saga has reported residue 0. Purging the table incode_index.purgeas one more content table would split one table across two steps, and itscode_answers.deleteownership in both scopes would still have to stay for the memory side.Scope and risk
server/erasure/store/predicates.py(one constant),steps_graph.py(the step),census.py(the census row and its comment), the comment onKEEP_TABLESinserver/code/app/index/retire.py,server/code/app/answers_cache.pyandserver/code/store/index/answers.py(the write guard reaches every answer, with a delete by entry key), two sentences indocs/architecture/memory-architecture.mdandstorage-layout.md, and the tests. No wire, setting, migration or SDK change. A user-scope erasure andmemory.redactare untouched.The delete takes more rows than before, all of them cache: the next ask in a re-created namespace synthesizes again.
An ask in flight while the saga runs can store an answer after the delete. The fence that handles this (
_rememberbefore the store,_check_storedafter it, both reading the erasure ledger) now runs for every answer, not only one that quoted memory, and for the negative entry an abstain writes: a code-only answer is not cached while an erasure of the org had not completed when the ask began, and one that lands after the census is tombstoned and deleted by its own key (delete_answer_entry, one lightweight delete). The same check guards the copy a release branch makes of its trunk's entry. The cost is one ledger read per stored answer. The redaction stamp is still read only for an answer that quoted memory keys. During a mixed rollout an N-1 replica's asks stay unguarded for a code-only answer; the census still catches such a row, the saga fails atverify.residue,steps_to_reopenre-openscode_answers.delete, and the recovery worker deletes it on its next try.Compatibility, rollout and rollback
loom code answers-purgeis no longer needed after one. An erasure completed on N-1, or before the upgrade, keeps its answers, andloom erasure-re-verifydoes not reach this table, so runloom code answers-purge --namespace <ns> --all --applyfor each code namespace erased before then.code_answers.deleteand N resumes fails one census atverify.residueon the answers asked in the namespace; the next attempt re-opens the step and completes, within the worker's attempt limit. A saga that N started and N-1 resumes passes N-1's narrower census.How this was found
Found and reproduced on our deployment with AI assistance. Fixed on a fork, PR submitted.
Tests
tests/unit/test_erasure_code_index_purge.py, three CH-free cases on the step and the census row, with a recording ClickHouse stub. They assert the count and theDELETE FROM loom.code_answersfilter onnamespaceitself, not onlymemory_namespace, for one namespace and for a list, and that the census predicate matches both columns. Onmainall three fail (3 failed, 6 passed). On this branch the file passes (9 passed).tests/unit/test_erasure_census_tail.py: the namespace census predicate for the table includesquestion != ''(CH-free; fails without it).tests/unit/test_erasure_code_answers.py, cases onclickhouse-localwith the real table: an answer asked in the erased namespace is counted by the census, deleted by the step with the other versions, and an answer of another code namespace stays; a negative entry holding only its question is counted and deleted; a tombstone with no answer text counts in the namespace census through its question and not in the user census. These cases were not run here: the host has noclickhousebinary, so the module skips. It is written to the module's existing fixture shape and needs a run in CI or on a host withclickhouse.tests/unit/test_code_ask_cache_v2.py:test_a_code_only_answer_is_not_cached_while_an_erasure_may_have_missed_it(an unfinished or unreadable erasure ledger keeps a code-only answer out of the cache) andtest_a_code_only_answer_stored_before_an_erasure_marks_is_deleted_again(the ledger reads clean before the store and marked after it, standing for a write that lands after the census: the row is tombstoned and no version keeps the text). Both fail without the guard on every answer;test_an_answer_with_no_memory_reads_no_erasure_ledgeris replaced by the first. The same pair covers an abstain:test_an_abstain_is_not_cached_while_an_erasure_may_have_missed_it(an unfinished or unreadable ledger keeps the negative entry out of the cache) andtest_an_abstain_stored_before_an_erasure_marks_is_deleted_again(the row is tombstoned and deleted by its key); both fail without the guard on the negative write.pytest tests/unit/test_erasure_code_index_purge.py tests/unit/test_erasure_code_answers.py tests/unit/test_erasure_step_order.py tests/unit/test_erasure_verify.py tests/unit/test_storage_layout_rows.py tests/unit/test_public_copy.py tests/unit/test_tunable_constants.py tests/unit/test_doc_links.py tests/unit/test_provider_copy_residue.py tests/unit/test_erasure_cache_key_axis.py tests/unit/test_erasure_repo.py tests/unit/test_cell_scan_tables.py tests/unit/test_erasure_census_tail.py tests/unit/test_code_ask_cache_v2.py -q -p no:randomly -n 2gives 503 passed, 22 skipped (the skips are theclickhouse-localcases).ruff check,ruff format --checkandmypypass on the touched files, and prettier passes on the changed docs. The full unit suite was not run here; CI runs it.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 wrote the diff and the tests. Checked: I reviewed the whole diff and its tests; the runs listed under Tests are the agent's, against
mainat the same commit.I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make test-unitand applicable integration results are reported by CI; a full local run is not required before pushing.main; no migration is added.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version: no plugin file changed.npm --prefix frontend run build) and its tests pass, iffrontend/changed: it did not.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.Note
Medium Risk
Changes erasure deletion scope and answer-cache write paths for all orgs with in-flight erasures; behavior is intentional but touches compliance-sensitive data retention.
Overview
Fixes a gap where namespace erasure only removed cached
code.askrows matched bymemory_namespace, leaving answers asked in the erased code namespace (code-only or not) inloom.code_answersto be served again after re-index.Erasure and census now share
ANSWER_NS_EQ(namespaceORmemory_namespace), and the namespace census treats rows with only a question (negative/abstain entries) as residue untilcode_answers.deleteruns.Caching renames the guard to
_answer_may_be_goneand applies the unfinished erasure ledger check to every memoized answer and negative entry—not only memory-quoting answers. Post-store cleanup candelete_answer_entrybyquestion_idwhen there are no memory keys. Docs andKEEP_TABLEScomments are aligned with answers being deletable cache, not retained audit telemetry.Reviewed by Cursor Bugbot for commit fbbc2a5. Bugbot is set up for automated code reviews on this repo. Configure here.