Skip to content

A user erasure keeps the user's cancel on another writer's open ingest job, without the user's identity - #362

Merged
zlareb1 merged 10 commits into
mainfrom
fix/erasure-keeps-others-cancels
Nov 7, 2026
Merged

zlareb1 merged 10 commits into
mainfrom
fix/erasure-keeps-others-cancels

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 7, 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):

Erasing a user no longer un-cancels another writer's document ingest that the user had cancelled: the cancel is kept without the user's identity.

Why

A row of loom.knowledge_ingest_cancels carries the canceller's identity, not the job owner's, and ingestions.cancel_requested matches on (org, namespace, ingestion_id) alone. delete_ingestions_by_user deleted every cancel row with the erased user_id. So when writer A cancelled writer B's pending or processing ingest and A was then erased, the cancel went with A's rows and B's job ran on and published the document.

delete_ingestions_by_user now first copies A's cancels on jobs that another writer owns and that are still pending or processing (read from loom.knowledge_ingestions FINAL), keeping only org, namespace, ingestion_id and requested_at. agent, user_id and session_id take their '-' defaults and actor '', so the copy names nobody and holds no content. Then A's rows go as before. Cancels on A's own jobs, or on jobs that already ended, go with no copy. The copy runs under sequential_reads(): a replica behind the cancel or the job would copy nothing while the replicated delete still takes the cancel. OPEN_STATES moves from knowledge.store.ingestions to knowledge.domain.ingest_states, which erasure.store may import, and the new statement binds it as a parameter; DONE_STATES, which nothing read, is gone. The queries that spelled the open states before this change (_USERS_OWN_ORIGINALS, the ingest queue's due and HELD_SQL) are left as they are.

The saga trace stub (tests/unit/erasure_saga_stub.py) counted any INSERT into a table as a rewrite of the scope's rows there, which made the following count read zero and skip the delete. It now counts every INSERT as a rewrite except this copy (steps_memory._KEEP_OTHERS_CANCELS).

The copy names no principal, so its actor is empty, and the table has no source_class column; docs/architecture/memory-architecture.md (erasure saga) says so, next to the feature page.

Scope and risk

User-scope erasure of ingestion rows only. One extra INSERT ... SELECT per user erasure. A retried step may copy the same cancel twice; cancel_requested reads LIMIT 1, and the table's 30-day TTL drops both.

Compatibility, rollout and rollback

  • Wire: none. Schema: none.
  • Build N-1 erasing a user still drops such a cancel, as before.
  • Operator steps: none. Rollback: revert.

Tests

  • tests/unit/test_erasure_ingest_cancels.py (clickhouse-local), which also checks the copy runs under sequential_reads(): Alice's cancels on Bob's pending job, Bob's cancelled job, her own processing job and an agent's job with no end user; after delete_ingestions_by_user(org, "alice") only Bob's open job and the agent's read cancelled, each by a row with no identity whose every column is compared (its requested_at kept), and Alice's ingestion is gone. Fails on main, passes here.
  • tests/unit/test_erasure_step_order.py: the user saga's documents.tombstone trace now holds the copy before the deletes, and still deletes loom.knowledge_ingest_cancels.
  • test_erasure_documents.py, test_package_contracts.py, test_erasure_repo.py, test_erasure_audit_actor.py, test_new_mutations_bind_parameters_only.py, test_knowledge_inspect_ingest_sql.py, test_namespace_tune_documents_sql.py, test_doc_links.py, test_public_copy.py: pass on this head.

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 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.
  • 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 bumps both plugin manifests' version.
  • The frontend builds 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.
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 10 commits November 7, 2026 13:21
…t job, without the user's identity

delete_ingestions_by_user deleted every loom.knowledge_ingest_cancels row the
user wrote. A cancel row carries the canceller's identity, not the job owner's,
and cancel_requested matches on (org, namespace, ingestion_id) alone, so erasing
a writer who cancelled another writer's pending or processing job un-cancelled
it: the job ran on and published the document.

Before the user's rows go, the step now copies the user's cancels on jobs that
another writer owns and that are still pending or processing, with only org,
namespace, ingestion_id and requested_at; agent, user_id and session_id take
their '-' defaults and actor ''. The copy holds no identity and no content.

The saga trace stub counted any INSERT into a table as a rewrite of the
scope's rows there; a copy whose column list leaves out user_id now is not.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…s from knowledge.domain

The copy now runs under sequential_reads(), so a replica behind the cancel
or the job cannot copy nothing while the replicated delete still takes the
cancel. The open states move from knowledge.store.ingestions to
knowledge.domain.ingest_states, which the erasure store may import, and are
bound as a parameter instead of spelled again. The test fixes requested_at,
compares every column of the copies, and covers a job an agent owns with no
end user.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… query is as on main

The previous commit put {open:Array(String)} into _USERS_OWN_ORIGINALS,
whose callers bind no open parameter, and left the cancel copy spelling
the states. ingest_states keeps only OPEN_STATES; DONE_STATES had no reader.

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]>
…ames the one copy it lets through

_USERS_OWN_ORIGINALS spelled the open states again; it now binds
OPEN_STATES like the cancel copy, so the two cannot drift apart. The saga
stub keeps every INSERT a rewrite except the cancel copy itself.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…is tested and its write is named in the erasure saga's design

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ames the empty actor plainly

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…nd both pages list the identity columns in table order

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the fix/erasure-keeps-others-cancels branch from 40575c8 to 98421de Compare November 7, 2026 13:22
@zlareb1
zlareb1 merged commit 6811414 into main Nov 7, 2026
104 of 106 checks passed
@zlareb1 zlareb1 mentioned this pull request Nov 12, 2026
3 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