Skip to content

loom instance export and import move orgs into a deployment that serves others - #2151

Open
zlareb1 wants to merge 24 commits into
mainfrom
feat/instance-consolidation
Open

zlareb1 wants to merge 24 commits into
mainfrom
feat/instance-consolidation

Conversation

@zlareb1

@zlareb1 zlareb1 commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Related: #2146
Related: #159

Changelog category (leave one):

  • New Feature

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

loom instance export writes one deployment's orgs into a bundle, and loom instance import lands it in another deployment that already serves other teams, by a plan the operator reviews. Accounts land claimable under their old password, grants move under mapped subjects, and the plan refuses any name or subject that would land on someone else's.

Why

Teams try Loom on a deployment of their own and then move to a shared one. The tools before this copy rows unchanged (dev/backup_loom.py), so a source account or namespace that shares a name with a target one replaces it (ReplacingMergeTree folds the two rows), and a grant to alice reaches whoever is alice on the target. This is step 1 of #2146: plan, map and apply for namespaces, accounts, grants, memories and documents, which covers one or more source orgs into a live target.

Design:

  • Two commands, run with the CLI where each deployment's servers run. export only reads. import without --apply is the plan: it reads the target, prints every decision, and exits non-zero while any problem stands. Each problem names the map entry that settles it, and the run prints those entries as YAML. --apply needs --expect-plan <digest>, so a target or map that changed after review refuses the write; a clean dry run prints that whole line. The digest binds the bundle, the decisions and sso_same_issuer. The target orgs are declared to the cell gate only once the reviewed digest matches.

  • The bundle is a directory: one gzip JSONL file per section, originals under originals/<sha256>, and a manifest written last with every section's row count, size and SHA-256. A cut-off or altered section is refused when each run opens the bundle; the digest is the SHA-256 of the manifest bytes that run read, so an edited manifest changes the plan and --expect-plan refuses it. The bundle is the operator's own 0700 directory, so a file changed while a run reads it is their change, not a damaged copy. The dry run reads every original back with its hash checked, and an apply that finds one changed since stops and says to run it again. The manifest's content names the namespaces whose content the bundle holds: an account a --namespace export brings for its grants or ownership is a row only. It brings the accounts a grant names by handle, and those it names by email (contact or single sign-on link): single sign-on on the source admits no one by an address a revoked or password account names, and the plan needs the account to land the grant the same way. The bundle holds password hashes and high memories, so the writer makes its directories 0700 and its files 0600, whatever the umask. Like dev/backup_loom.py, the export is an operator's dump and writes no audit row per high memory it reads (docs/architecture/security.md says so). It reuses nothing from namespace.snapshot's single-response payload, which has no paging and no documents.

  • Names never fold. A source namespace or account handle the target already holds (a namespace or a released alias), or a name in single sign-on's form, refuses the plan with a rename or claim proposal; a name the map gives is checked as a new namespace's name is. Two source orgs mapped to one target org share its names. Apply also refuses a name that holds data with no namespace row (directory().in_use).

  • A landing is the import's own only while its row is. A landed name counts as this source's (not a collision) while its namespace row is active and keeps the source row's created_at, which the import writes and a name registered since cannot have. The landing's audit row records that created_at, so a later plan and the apply decide it from that one value, whichever bundle they read (TargetOrg.holds). A run stopped between its audit row and the namespace row leaves the name free: if someone takes it before the rerun, the plan refuses it with a rename or claim proposal, or, when the new account signs in with the person's email, a drop proposal. With no row the apply checks the name's use and access again, and writes the row with the recorded created_at.

  • A claimed handle holds no access yet. Password login builds roles from the bare handle, and grants fold case, so an account landing as admin where LOOM_PLATFORM_ADMINS=admin, or as bob where a token subject bob holds grants, would take that access. The plan runs self-signup's own check (refuse_empowered, made public here) for each claimed handle and proposes {claim: <handle>-legacy}; the apply runs it again under the account claim.

  • Subjects are mapped, never matched by guess.

    • An account lands as a claimable password account under its handle. The argon2id hash carries no deployment secret, so the existing sign-in, and the first-SSO password check, work on the target.
    • An account whose email already signs in to a target account is refused with a drop proposal, and the problem names that account: map it there only if it is the same person in the same org. Nothing proves a target account's contact email, so the printed entries never hand an account to it. Only the import's own landing of that account, under the handle the map now gives, is excused. So is a second account of the bundle, in any source org, that would land with an email another one lands with, since single sign-on refuses an email two accounts hold.
    • An SSO account has no password to prove the person, so it needs a mapping, or sso_same_issuer: true, which also carries its links. With that flag each link's email counts in the check above. An account single sign-on made on the source lands without its oidc-jit tag, so the target's sign-in never finishes its provisioning with an owner grant the source revoked.
    • An account the source revoked, by an operator or by SCIM (its \0scim: key, any case), lands with no password, no contact email and no links, and its grants stay behind. An active row with an empty hash and an email is what single sign-on resolves by email, so leaving the email would let whoever proves it at the target's identity provider in. Since none of its emails lands, the plan checks none of them, and the dry run says it lands revoked. When the source revoked it after an earlier bundle landed it as an account that signs in, the plan refuses, whatever the map now does with it (drop, or a claim under another handle), until the target revokes that landing (loom revoke-token --subject <handle>): only the target's revocation also ends the tokens and sessions it has had there since. The problem text and the docs say that revocation reaches the handle in every org of the deployment; deleting the landed account ends the refusal too, ending only its sign-in (for an unfinished landing the plan then proposes another handle). It reads earlier landings only in the target org each source org lands in now.
    • A grant to a revoked account's email (its contact email or a link's) is dropped, and mapping one is refused. On the source single sign-on admits no one by an address an account names, so the grant admits no one there; on the target no account would name it, so the first sign-in with it would make a fresh account the grant admits.
    • Any other email grant admits whoever proves the address at sign-in, as on the source. It lands under the handle of a target account that verified the address, as grants.create writes it, and stays an email grant otherwise; it is never tied to an account whose email the source did not verify.
    • user: is kept in a target org only this import lands in. A mapping names an end user's id: one onto user:- or user: would land them beside the rows with no user, and is refused. In one that serves others it may name another person, so it needs keep, a user: mapping or drop. Memory user_ids follow that decision, and two end users of one source org landing as one refuse the plan. Across source orgs one person may hold an id in each, so the map decides.
    • group:, agent: and everyone hold grants on collections only (grants.create refuses them elsewhere), and collections do not move, so such a subject on a moved namespace is refused with a drop proposal. A mapping can turn it into a person's grant; a mapping onto one of them is refused.
    • sa: subjects are dropped. Any other unknown subject refuses the plan. keep runs the same checks as no rule.
    • Only the subjects a landing needs are decided: a created namespace's grants, owner and end users; a merged one's end users, and its grant subjects when it carries its grants (the target keeps its own owner); none of a skipped one's. A created namespace whose owner the map drops, or that has none, is owned by the import, and the dry run says so.
    • A map entry that names no org, namespace or subject of the bundle refuses the plan, so a typo never leaves a decision silently unmade.
  • Who can join. In a target org that serves others, a namespace anyone in the source org could join at once (public with inherit, or open) lands with join_policy: approval, so its content is not readable by everyone in the target org.

  • Writes go through the existing writers.

    • Created namespaces: memories go through the restore path (restore_rows, checked_rows, without_erased, insert_version_rows), keeping every column and created_at, with source_class=imported and the command as actor. Its verifier and locker (verified_by, locked_by) name a subject as the plan maps it, and no one where the plan drops it or never planned it, so no source subject's act lands as a target subject's. As in a merge, a key the namespace holds or has held is left as it is, so a fact someone wrote there before a rerun is never replaced by the source's. Per-type settings, policies (which only restrict) and guide revisions land too.
    • Merged namespaces: memories go through memory.bulk_set, so admission (blacklist, conflict surfacing, pinned peers) holds, with the settings memory.import uses for outside facts: every entry checked whatever bulk_conflict_check_max_entries caps a call at, each call oldest first (the later of two statements of one attribute in a call retires the earlier), no update detection, and no reinforcement, which each rerun would add again. A merge only adds: a key the target namespace holds or has held under the same agent, user and session is left as the target has it, so it never revises the target's fact or revives one its owners deleted. Each memory.bulk_set call reads the target's keys of its entries again just before it, and each document its address, so a key or address the target's owners write while the run goes on stays theirs too. Under newest_wins, where a same-key write retires the older rows in every session of its user (of anyone, for a write with no user), a key the target holds or has held that far is held too. A row the merge leaves out (a dropped user's, one not live, a refused one, one the target holds) claims no key, so a live row of its key still lands. Of the rows the bundle brings that a write of one would retire (one key under one agent, user and session, across two merged namespaces too, and under newest_wins one user's rows of a key, or the rows of a key with no user), the newest by valid_at (its created_at where it has none), then the first in the bundle, lands, and the receipt counts the others as memories_superseded: the first pass over the bundle finds them, holding one rank per group. Under newest_wins a named write never retires a row with no user, and a write with no user retires the named rows of its key written before it, so the rows with no user are written in a pass before the named ones: a named row lands beside a row with no user of its key, as the source served both, and a run resumed between the two passes writes the same rows. Admission may still mark a target row a merged one contradicts as conflicted, and retire one: under newest_wins, a row stating the same attribute of the same subject with another value, unless the merged row is the older statement by valid_at, and, with the conflict resolver on, one it judges the merged row updates. Only facts live when the run starts are written (a redacted head, whose value is the placeholder no read serves, is not one), so every pass of a run decides a row alike; one that expires before its write lands with a one-second expiry, as it expired on the source. Pins and locks are not carried: a pin would refuse the target owners' own later writes of a close fact. An entry admission declines (a pinned peer, or a restatement folded into a row) is counted in the receipt as memories_not_admitted. The row's created_at is the import's; its validity, expiry, temporal anchor, sensitivity, evidence and grounding are the source's. memory.bulk_set takes no expiry action and sets the one the target gives a row's sensitivity, so the dry run names a merged row whose own action (on_expire) differs, which the target would otherwise delete where the source demotes or anonymizes it: land its namespace as a created one, which keeps it. The reason recorded for an expiry is not carried.
    • Documents: knowledge.upsert with their originals, so the target's embedder embeds them and the originals land in the target's store. Its ingested_at is the import's time, and the source's record of how it extracted each one (format, parser, coverage, artifact_sha256, its ingestion) stays behind. Two source namespaces may merge into one target: the first copy of an address lands, and a second is counted as present. An address the target namespace holds or has held, a deleted one included, is left as it is. The export checks each original's hash, and under the Postgres authority it refuses while a selected namespace has documents awaiting publication. A document an end user wrote stays behind and is counted: the writer takes its user only from the caller's token, so the target could not erase it as theirs. So does a knowledge source's synced copy: a source registered again rewrites or retires only documents its sync wrote (source_sync.ours), so a copy the import wrote would never be refreshed. A recording source's transcripts move instead: one registered again lists its last weeks only (ZOOM_LISTING_DAYS), a transcript never changes once written, and the source leaves an address another writer holds as it is.
    • Grants: written under the subject grants.create would write the mapped one under (a verified email's handle), with the import as granted_by. The person is matched as the gate matches them, case folded: a grant is left out when they hold that role or higher under a verified spelling (an unverified one only caps at the gate), or a target admin revoked them there under any spelling the directory ties to the subject. A pending request is no grant, so the source's grant replaces it.
    • Blacklist: entries go first, with a deterministic id per pattern and target namespace. A source pattern lands narrowed to each created namespace it reaches, never wider. A merge stores none on the target's namespace, which is not the source's to refuse for: it refuses the rows it brings by the source's patterns in process, through the guard's own matcher (blacklist_guard.match_value, new). A memory one matches is counted as refused, not written. The dry run builds every memory row the bundle brings into a namespace it lands (the restore check, and for a merge the bulk entry and memory.bulk_set's own char_limit measure) and names each one the target refuses, such as a date past 2106, text the Postgres authority cannot store, or a value past its char_limit once serialized again, which would otherwise stop every apply at that row. It may name a row the run would then leave out, such as a key the target holds; the runbook says so. It refuses a pattern this deployment cannot compile, and a created namespace whose regexes still to be stored would pass the per-scope RE2 budget (finished landings and patterns stored by an earlier run do not count, so a rerun passes).
    • Model calls (embedding, extraction) run under the target org's customer attribution.
  • Reruns and resume, with no new table.

    • Landing rows: before it creates a namespace, the import writes an instance.import audit row naming its source (<deployment>/<org>/<name>); a merge writes instance.import.merge. A later plan reads these as this source's landing, not a collision, so an interrupted run resumes with the same command and the same digest, unless the target changed what the plan reads: a namespace someone created since in a target org only the import landed in, or a landed name someone registered since, makes that org one that serves others, and the dry run shows the new decisions. A merged-into namespace never counts as the import's own.
    • Done rows: once a namespace's content is written, an instance.import.done row marks it, and later runs skip that namespace entirely, so whatever the target's owners deleted or revoked since stays so. Only a namespace the manifest's content lists gets one: a row-only landing gets none, so a later bundle that selects the account (a whole-org export) resumes it and brings its content; the dry run marks those landings.
    • Inside an unfinished namespace, a run writes nothing the target holds in any state (created and merged namespaces alike read the target namespace's keys once per run; under the Postgres authority every memory and document head it holds counts, deleted and unpublished ones included). Every read of a plan and apply is sequentially consistent, so a lagging replica never hides what an earlier run or the target's owners wrote: no memory key the namespace has held, no source_uri it has held, no setting, policy, guide revision or SSO link it holds, and no grant the person holds at that rank or higher or was revoked from.
    • Erasure during an unfinished import: an erasure on the target removes what the target holds then, and a purge leaves no row for a later run to find, so the docs say to run it again once the import finishes, as docs/operations/backup-and-recovery.md already says after a restore. A guard that refused resumes after any target erasure would leave the import no way to finish.
    • Using audit rows avoids a staging table, and with it an erasure census row and a migration.
  • Left out, and listed. Service accounts, bots and connected accounts are listed in the receipt for their owners to set up again, because their credentials never move. The manifest's left_behind names or counts:

    • repositories and knowledge sources with a remote, and the documents those sources synced, recording transcripts aside;
    • conversations, session briefs and tasks;
    • promoted shared memories and records;
    • end users' documents.

    A --namespace export counts these for its namespaces only, and the dry run prints each counted kind with its row count.

    Embeddings, caches, traces and the audit log stay behind. Mirror and code-store namespaces (their reserved acl-/crs-<24 hex> forms) and collections stay behind; any other name moves. memory.bulk_set embeds merged memories as it writes them; a created namespace's are embedded by the embedding worker's next full pass, the same path namespace.restore relies on. An export that selects nothing is refused.

Alternatives considered:

  • Making _SnapshotMemoryRow public. The bundle's memories section is namespace.snapshot's row, and that module names every row model of an op's output with a leading underscore (_SnapshotTypeRow, _SnapshotGrantRow), as the generated reference shows; the import reads it as the restore does.
  • An op behind the platform-admin role, rather than a CLI. A bundle is gigabytes and would need a background job writing to the document bucket, and the import side needs the operator on the target anyway.
  • A per-namespace self-service export for namespace admins. That is Export and import memories and documents with verified recovery #159; it can reuse instance_bundle with the content sections only.
  • Using a bundle as a backup. It leaves out what the target rebuilds, so full backups stay BACKUP DATABASE and dev/backup_loom.py.
  • Carrying groups. Their grants exist only on collections, which do not move.

Not in this PR, as #2146 orders them:

  • step 2: delta passes, loom instance freeze and the moved hint;
  • step 3: conversations, briefs and tasks, the telemetry archive, undo and the search-parity probe. Promoted shared memories, records and end users' documents join step 3.

Scope and risk

  • New CLI command group (server/cli/instance*.py). server.auth.self_signup._refuse_empowered is renamed refuse_empowered, unchanged, for the import to call. Three read-only helpers are added for it: blacklist_guard.match_value (the guard's matcher over patterns the caller holds), pg_memory.held_in (the keys of a namespace's heads, deleted ones included, paged by key) and pg_documents.held_uris (which addresses have a head, without the rows). Two gate tests classify the new files: test_namespaces_writers_mirror_classification lists the import as a known namespace writer (it writes the source's full row, classification and join policy included), and test_pg_durable_reads lists the export and the import as journal readers. No op, field, setting, migration or table changes.
  • Tenant isolation: the import writes only into the target orgs the plan names, and no source subject reaches a target subject the map does not name.
    • Same handle on both sides: a source alice whose handle the target already uses, or that already holds access there, is refused until the map gives it another handle.
    • Emails: with no map entry, an email grant lands under a handle only where a target account verified the address, as any grants.create would write it; an explicit map entry maps it as it maps any other subject.
    • Settings that name source services are cleared: rerank_endpoint, classify_endpoint, released_aliases, budget_alert_inbox.
    • Non-account namespaces: their password_hash and contact_email are cleared, so no plain namespace's email reads as a verified spelling of its owner.
  • A Postgres-authority source or target uses the writers namespace.restore uses under both authorities, and the merge reads keys from both stores. The new integration test also runs in CI's Postgres pass. Not exercised: Cloud as source or target.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none. The procedure is in docs/operations/consolidation.md.
  • Rollback: reverting removes the commands. Rows an import wrote stay, as rows from any other writer do.

Tests

  • tests/unit/test_instance_consolidation.py:
    • bundle round trip, owner-only modes on every file and directory, and refusal of an altered section, an altered original, a missing manifest and an --out that names a file;
    • the same handle on two people, and its resume under the claimed handle;
    • namespace and JIT-name collisions; group, agent and everyone subjects refused, with keep running the same checks;
    • user: kept alone and refused in a shared target org; user: maps only to user:; two source users landing as one;
    • two source orgs bringing one name;
    • a public namespace asking for approval in a shared org, and a merged-into org staying shared;
    • email holders in another org or the same one, each proposed drop, and single sign-on link emails under sso_same_issuer;
    • resume with the same digest; a landed name someone took since (its row's created_at differs) refused with a rename proposal, its email no longer excused (a drop proposal), and a finished landing never a collision; a landing excused only under the handle the map gives now; a new digest for another bundle or another sso_same_issuer;
    • the in-process merge refusal: an org-wide regex and a deployment-wide substring refuse, another namespace's pattern does not;
    • merge targets, reserved names and map errors, strict booleans included;
    • --namespace selection, by handle and by contact or link email, and the export keeping acl-reviews while leaving out a mirror's reserved name and a collection;
    • a landing from an earlier bundle, its row absent from this one, still counted as the import's;
    • an account the source revoked: no email check, a note saying it lands revoked, and a mapping onto a target account refused; revoked after an earlier bundle landed it claimable: refused until the target revokes it, whether the map keeps, drops, maps or claims it under another handle; a resumed landing of a revoked account, and a finished one the target deleted, still planned;
    • two accounts of the bundle, in two source orgs, landing with one email (case folded): refused with a drop proposal;
    • a map entry naming nothing in the bundle, and mappings onto group:eng and everyone, refused;
    • a landed namespace row its owners deleted proposed for a rename, not read as a landing, and a landed name someone registered since making the org one that serves others;
    • a revoked account's contact and link emails dropped as grant subjects, and a mapping of one refused; a subjects entry naming a plain namespace refused;
    • a merge's memory.bulk_set calls: every entry checked, oldest first, no update detection, no reinforcement, no pin, the expiry taken from the time of writing (a row expired since the run began sent with one second), and a declined entry counted as memories_not_admitted;
    • a skipped namespace's grant subjects and end users needing no decision;
    • a mapping of an end user onto user:- or user: refused;
    • which merged rows land: a superseded row, a redacted one, and one past its expiry at the run's start, claiming no key, so the live row of its key lands; of rows that would retire each other the newest, across two merged namespaces too, and the others counted as memories_superseded; under newest_wins a key the target holds for the same user in any agent or session, or for anyone where the row has no user, held, a row with no user written first and landing beside a newer named row of its key, and a run resumed after the rows with no user writing the rest; under another policy, or in a created namespace, only the exact key;
    • the dry run naming a created and a merged memory the target cannot store, a value past its char_limit once serialized again among them, but not one a merge leaves out, a dropped user's or a skipped namespace's;
    • an --expect-plan that is not the plan's digest: exit 2, before the acceptance check and the apply; an original changed after the dry run read it: _documents raises on it before writing, and the command turns that into a stop that says to run it again;
    • instance import among the commands whose default is a dry run (test_cli_apply_default.py);
    • a resume under the Postgres authority: pg_memory.held_in paged to the end, its keys counted with ClickHouse's, and a document head the authority holds counted as written;
    • _land holding to the recorded created_at when the bundle's differs: a row it wrote is its own, the row it still owes is written with it, and a row registered since stops the run;
    • a resumed run writing no source head over a key someone wrote into the created namespace since, whatever its memory id;
    • two source namespaces merging into one target with the same document address: the first copy lands, the second is counted as present; an address the target's owners write during the run, read just before its write, is counted as present too, and the next document still lands;
    • a merge write reading the target's keys of its entries again just before its call: a key written since in another session under newest_wins is left out and counted as held; pg_memory.held_in filtered to given keys;
    • a created row's verifier and locker under the mapped subject, cleared for a dropped or unplanned one, and a note with no subject kept;
    • a merge without its grants needing only its end users decided, and its grant subjects once it carries them; the dry run naming a created namespace whose owner does not land;
    • the dry run naming a merged row with an on_expire the merge cannot keep, and leaving out a redacted one.
  • tests/integration/test_instance_consolidation.py, against a real ClickHouse and server. An org moves into another org of the same deployment that already has an alice, a team, and a grant to bob.
    • Dry run: it refuses, and prints exactly the rename, claim (alice-legacy, and bob-legacy from the access check) and drop entries; the map built from them plans a digest. With an original changed since the export, it refuses; a clean one ends with the whole apply line, digest included.
    • Apply:
      • every memory lands field for field, except the version, actor and source class the restore owns;
      • the blacklisted memory is refused, and the pattern lands narrowed to team-legacy;
      • six org-wide regexes (1,734 RE2 instructions together) land narrowed on each created namespace and none on the merged team, whose row matching them is refused; afterwards the target's own write of that row to team succeeds;
      • the document lands with its original's hash, every column the source's but those knowledge.upsert owns (ingested_at included) and the extraction record; a knowledge source's synced copy stays behind and the manifest counts it, and a recording's transcript lands;
      • the per-type setting, the policy and the guide revision land field for field;
      • a third namespace merges into the target's team: its new key keeps the source's validity, tags, confidence, sensitivity and expiry, and its key the target holds is left alone; the target's team uses newest_wins: of a key the source holds in two sessions only the newer lands, and a key the target holds in another session stays the target's and live, an end user's newer row of a key (its user: subject kept by the map) lands beside the row with no user of that key, both read back live from the table, and the receipt counts the older employer row as memories_superseded;
      • the merge carries its grants (grants: true): erin@src.test, who only asked to join the target's team, gets the source's viewer grant; dave@src.test, whose target revocation is stored as Dave@Src.Test, gets none; and frank, whose unverified self-signup email holds writer there, gets the source's writer grant;
      • the target's own rows are unchanged;
      • accounts land with the source's hash and email; the SCIM-revoked one lands with no hash or email, neither its grant nor the grant to its email lands, and single sign-on's email lookup for it finds nothing;
      • the public namespace lands with join_policy: approval;
      • grants go to the claimed handles, and nothing goes to the target's alice or bob;
      • a landing and a done audit row are written per decision.
    • A --namespace bundle, then a whole-org bundle: the first lands the owning account as a row only (marked in the dry run, no done row; the second dry run marks the finished team) and counts what it leaves behind for that namespace only; the second brings the account's own memory, marks it done, and leaves the finished namespace alone. Between the two, an account the first landed claimable and the source revoked since refuses a later plan until the target revokes it too (source and target share the deployment, so the test takes the source's revocation back before that plan reads the target). Under sso_same_issuer: true an account single sign-on made lands with its link and without JIT's tag, and single sign-on with its email resolves to it on the target.
    • Reruns: after its done rows are deleted, a resumed apply writes nothing (memory versions, every row of the merged team with its status and version, document revision, namespaces, grants and refusals compared), and a finished rerun writes nothing either. Both pass the regex budget with the stored regexes, which a check counting them twice would refuse.
  • The CLI snapshot and docs/reference/cli.md regenerated (the import gives its own dry-run hint, apply_gated=False). The dry run marks a landing an earlier run finished, which the apply skips. Ruff, mypy and the mypy gate, the function-length gate, the analyzer corpus, the package contracts, test_cell_cli_orgs, test_signup_privilege, test_model_call_writers, the mutation inventory, doc links and public copy all pass.
  • End to end, on the first push, between two private ClickHouse servers with a server on each: the source password signed in on the target as the claimed handle. The integration test covers the other paths 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. Checked by the end-to-end run, the integration test and the unit tests.

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

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • 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), the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py) and the standalone skill bundles (python3 scripts/codegen/standalone_skills.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.
  • I signed the Contributor License Agreement (CLA) if CLA assistant requested a signature.

🤖 Generated with Claude Code


Note

Medium Risk
New operator path copies passwords, high-sensitive memories, and grants into another deployment; mistakes in the YAML map or skipping dry-run could land data on wrong subjects, though plan refusal and --expect-plan mitigate many collision cases.

Overview
Adds loom instance export and loom instance import so operators can move selected orgs (namespaces, password accounts, grants, memories, documents) from one deployment into another that already serves other teams. Export builds an owner-only bundle (gzip JSONL sections, document originals, manifest with checksums); import dry-runs a reviewed plan (YAML map for org/namespace/subject renames, merges, drops) and applies only when --expect-plan matches the plan digest.

Plan/apply behavior refuses collisions (existing namespaces, handles, emails, empowered names) instead of folding rows; merged namespaces write via memory.bulk_set, created ones via restore; audit rows (instance.import, .merge, .done) support idempotent resume. Export blocks unfinished erasures and unpublished Postgres documents; it does not audit per sensitive memory read (documented like dev/backup_loom.py).

Also renames _refuse_empowered → refuse_empowered for import/signup checks, adds blacklist_guard.match_value, pg_memory.held_in, pg_documents.held_uris for import idempotency under Postgres authority, and ships docs/operations/consolidation.md plus CLI/docs/CI wiring and integration tests.

Reviewed by Cursor Bugbot for commit d1626d0. Bugbot is set up for automated code reviews on this repo. Configure here.

…es others

An export writes one deployment's orgs as a bundle: namespaces, accounts with their
password hashes, live grants, groups, blacklist entries, memories, and documents with
their originals, each section checksummed in a manifest. An import plans the bundle
against the target, refuses a plan while any source name or subject could land on
someone else's, and applies the plan whose digest the operator reviewed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
@vercel

vercel Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Dec 5, 2026 1:01am UTC
loom-telemetry Ready Ready Preview Dec 5, 2026 1:01am UTC

Request Review

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/cli/instance_plan.py Resolved
Comment thread server/cli/instance_import.py Resolved
Comment thread server/cli/instance_export.py Resolved
… orgs need the map

- An instance.import.done audit row marks each namespace whose content landed;
  later runs skip it, so what the target deleted or revoked since stays so.
  Groups get landing rows too, and reruns skip revoked grants and existing
  blacklist ids.
- Two source orgs landing in one target org share its names and groups; a
  name or group both bring refuses the plan.
- everyone, user: and agent: subjects need keep, a mapping or drop in a
  target org that serves others; memory user ids follow the user: decision,
  and two source users may not land as one.
- Blacklist patterns land narrowed to the moved namespaces they reach.
- A merge carries validity, expiry, sensitivity, evidence and grounding, and
  skips rows that are no live fact; per-type settings land with created
  namespaces only.
- Model calls run under the target org's customer attribution.
- The plan digest binds the bundle; the map's flags are strict booleans;
  collection and alias names are refused.
- The export carries only the groups its grants name, filters identity rows
  by the selected pairs, streams every section, checks each original's hash,
  and refuses under the Postgres authority while documents await
  publication.
- A claim under another handle plans the same digest when run again.
- An integration test moves an org into a live one, field for field, with a
  merge and a rerun that writes nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/cli/instance_plan.py Resolved
Comment thread server/cli/instance_plan.py Resolved
Comment thread server/cli/instance_import.py Resolved
…y add

- A claimed account handle that already holds access on the target (a
  platform-admin or trusted-caller setting, a grant, a namespace, a token, a
  task) refuses the plan with a new-handle proposal, and the apply checks it
  again under the account claim: the same check self-signup runs, now public
  as refuse_empowered.
- The export reads revocations under SCIM's key and any case, so a
  deprovisioned account lands with no password and no links.
- keep runs the checks no rule runs; it only settles an end user of a shared
  target org.
- A namespace anyone could join at once lands with join_policy approval in a
  target org that serves others.
- A merge writes no key the target namespace holds or has held; a resumed run
  writes no per-type setting, policy, guide revision or single sign-on link
  the target holds in any state.
- Groups, agents and everyone hold grants on collections only, which do not
  move: the group path is removed, and such a subject needs drop or a mapping.
- Policies and guides move with created namespaces; promoted shared memories,
  records and end users' documents are counted as left behind.
- The digest names sso_same_issuer; merges land under their own audit event,
  so a target org merged into stays shared; a user: subject maps to any user:
  subject; an undecided subject maps to nothing.
- The dry run checks the regex budget and every original before anything is
  written; the target orgs are declared only to write a reviewed plan; an
  export that selects nothing is refused.
- The integration test covers a target-held handle, a SCIM-revoked account,
  a refusal, a document and its original, a public namespace, a merge key
  both sides hold, and a resume of unfinished landings; it also runs in CI's
  Postgres pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/cli/instance_import.py Resolved
Comment thread server/cli/instance_import.py Resolved
… no refusals

- An account the source revoked lands with no password, email or link, and
  its grants stay behind: an empty hash with a contact email was claimable
  by whoever proved that email at the target's identity provider.
- A landed name is this import's own only while its row keeps the source's
  created_at; a name taken between the audit row and the namespace row is a
  collision, and a missing row is checked for use and access again.
- A merge refuses the rows it brings by the source's refusals in process and
  stores none on the target's namespace.
- The regex budget counts only the patterns a created namespace still has to
  store and skips finished landings, so a rerun is not refused; a refusal
  this deployment cannot compile is a plan problem.
- A merge reads its target namespace's keys once per run, not per batch.
- The bundle writer makes its directories 0700 and files 0600 itself,
  replacing the process-wide umask; an --out that names a file is refused.
- The left-behind counts of a --namespace export cover those namespaces, and
  the dry run prints each counted kind with its row count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/cli/instance_import.py Resolved
zlareb1 and others added 3 commits December 4, 2026 23:32
… move

- The manifest names the namespaces whose content the bundle holds, and
  instance.import.done is written for those only: an account a --namespace
  export brought for its grants landed done with none of its content, so a
  later whole-org import skipped it. The dry run marks row-only landings.
- The export leaves out only the reserved mirror and code-store forms and
  collections, not every acl- or crs- name.
- The plan checks no email or link of an account the source revoked, since
  none of them lands, and says it lands revoked.
- Under the Postgres authority, a resume reads every head the authority
  holds, deleted and unpublished ones included, as written already.
- Every read of a plan and apply is sequentially consistent, replacing the
  per-statement settings.
- A merge matches the source refusals with the guard's own matcher.
- The integration test's revoked account has a handle of its own, and a new
  test runs a --namespace bundle and then a whole-org one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
- The import's namespace writer is a known one: it writes the source's full
  row, classification and join policy included.
- The export and the import are classified journal readers: the export
  sends nothing, and the import's reads decide writes that commit.
- The column read names the configured database, not `loom` by value.
- No SELECT alias shadows a column its statement filters on.
- The write batch says why it is not a setting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…dation

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/cli/instance_import.py Resolved
Comment thread server/cli/instance_import.py Resolved
Comment thread server/cli/instance_import.py Resolved
…share an email

- A grant is left out when the person holds that role or higher under any
  spelling the directory ties to the subject, case folded, or was revoked
  there; a pending request is no grant, so the source's replaces it. It is
  written under the subject `grants.create` would write it under.
- The plan refuses two accounts of the bundle that land with one email,
  which single sign-on refuses, and proposes `drop`.
- The plan refuses a map entry that names nothing in the bundle, and a
  mapping onto a subject that holds grants on collections only.
- A landed namespace row its owners deleted is no landing of this import.
- Under the Postgres authority, a document head it holds counts as written.
- The dry run reads every original back with its hash checked; an apply that
  finds one changed since stops and says to run it again.
- An account single sign-on made on the source lands untagged, so the target
  never finishes its provisioning with an owner grant the source revoked.
- The docs say the export writes no audit row per memory it reads, as a
  database dump does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

"revoked_at": None,
"version": run.next_version(),
"status": "active",
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending grants survive subject rewrite

Medium Severity

Pending grants are ignored when deciding what the target already holds, and the new row is inserted under canonical_subject, not the pending row's subject. loom.namespace_grants only collapses an exact (org, namespace, subject) match, so a different case or a verified email's handle leaves the pending request in place. It can still be approved after the import.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 14bdc82. Configure here.

…s stay behind

- A grant to an email a revoked source account names is dropped: on the
  source single sign-on admits no one by that address, and the account lands
  with no email, so on the target it would. Mapping one is refused.
- The export leaves a knowledge source's synced documents behind and counts
  them (`documents_of_sources`): a source registered again writes and keeps
  only its own copies.
- A carried grant is left out for a role the person holds under a verified
  spelling only, as the gate admits them; any spelling still reaches a
  revocation.
- A landed name counts toward an org the import alone serves only while its
  row is the one the import wrote, or its content is finished.
- A subjects entry naming a namespace that is no account refuses the plan.
- The dry run's hint gives the whole apply line, `--expect-plan` included.
- `apply` takes `sso_same_issuer` from the plan the digest binds.
- One Postgres read of document heads per namespace, not per document.
- The docs say an erasure during an unfinished import is run again after it,
  as after a restore, and correct the email-grant wording.
- Tests: per-type settings, policies and guide revisions compared field for
  field, a single sign-on account landing untagged with its link, the dry run
  refusing a changed original, apply's stop on one, a revoked account's email
  grant, a synced document, and a grant past an unverified spelling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/cli/instance_import.py Resolved
zlareb1 and others added 2 commits December 5, 2026 01:33
…s move

- A `--namespace` export brings the accounts a grant names by email too, by
  contact or single sign-on link: on the source single sign-on admits no one
  by an address a revoked or password account names, and the plan needs the
  account to place such a grant.
- A recording source's transcripts move with the bundle: a source registered
  again lists its last weeks only, and a transcript never changes once
  written. Every other synced copy stays behind as before.
- The `instance.import` audit row records the source row's `created_at`, and
  `TargetOrg.holds` decides from it whether a landing is still the import's,
  whichever bundle the plan reads. A row-only landing an earlier bundle made
  no longer makes the org one that serves others.
- A resumed import reads which document addresses the Postgres authority
  holds without their rows (`pg_documents.held_uris`).
- Tests: the selection by email, a landing from another bundle, an original
  changed after the dry run stopping `_documents` itself, the dry run's hint,
  a recording transcript landing, and `instance import` among the commands
  whose default is a dry run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…dation

Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/cli/instance_plan.py Resolved
zlareb1 and others added 2 commits December 5, 2026 01:50
…it holds

- An email that signs in to a target account is excused only while that
  account is still this import's landing (`TargetOrg.holds`). A name someone
  signed up with since, with the same email, now refuses the account with a
  proposal to map it there, instead of landing it under another handle with an
  email the target's account also holds.
- The apply tests an existing namespace row against the `created_at` the
  landing's audit row recorded, the value the plan used, not the bundle's: a
  source row created again between bundles no longer passes the dry run and
  stops every apply.
- The audit helper takes `created_at` as a named argument.
- Prose: the consolidation table's wording, and hand-wrapped lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
- A created namespace skips each source head whose key (agent, user, session
  and key) the namespace holds or has held, as a merge does, not only the
  memory ids an earlier run wrote: a fact someone wrote there before the rerun
  stays theirs. `_seen` reads document addresses only, and
  `pg_memory.held_in` pages head keys by `KeyInNamespace`.
- An account the source revoked after an earlier bundle landed it as one that
  signs in refuses the plan until the target revokes it, which also ends its
  tokens and sessions there. `load_target` reads the target's revocations of
  landed names; the export and the import share the query.
- An email that signs in to a target account is proposed `drop`: nothing
  proves a target account's contact email. Only the import's landing under the
  handle the map now gives is excused.
- A landing that recorded its audit row but no namespace row writes it with
  the recorded `created_at`.
- The bundle's digest is the SHA-256 of the manifest bytes the open read.
- The dry run marks a landing an earlier run finished.
- Docs: merged memories are embedded as `memory.bulk_set` writes them; a
  document's extraction record stays behind; rewrapped paragraphs.
- Tests: `_land` against a recorded `created_at` that differs from the
  bundle's, a resumed run and a key written since, a revoke after a landing,
  a landing under a changed handle, and every column of a landed document.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/cli/instance_import.py Resolved
Comment thread server/cli/instance_plan.py Resolved
zlareb1 and others added 2 commits December 5, 2026 02:43
…he map does

- The plan checks every earlier landing of an account the source revoked,
  before its map entry: one the target still lets sign in, and has not
  revoked, refuses the plan whether the map keeps the account, drops it or
  claims it under another handle. The problem text and the docs say the
  target's `loom revoke-token --subject` reaches the handle in every org.
- `pg_memory.held_in` returns the keys themselves; `_held_keys` pages it
  without a wrapper, and `_seen` is `_held_uris`.
- Docs and docstring: created and merged namespaces both receive only keys
  the target never held; a document's `ingested_at` and `artifact_sha256`
  are named.
- Tests: the revoked landing under `drop` and under another claim, and the
  dry run's mark on a landing an earlier run finished.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
- Two source namespaces may merge into one target namespace: a document
  address the run has written is counted as present for the next one, as a
  memory key is, instead of superseding the first copy.
- A landing the target deleted no longer counts as one that still signs in:
  password and single sign-on read `active`.
- Docs: the plan reads earlier landings in the target orgs the map names, and
  deleting the landed account settles the plan where another org holds the
  handle, ending only its sign-in.
- `pg_memory.held_in` builds keys with `key_in_namespace`; the module
  docstring is reflowed.
- Tests: two merges with one address, a revoked account mapped onto a target
  account, a finished landing the target deleted, and, end to end, an account
  revoked on the source after a first bundle landed it refusing a later plan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/cli/instance_plan.py Resolved
zlareb1 and others added 3 commits December 5, 2026 03:15
- A merged entry `memory.bulk_set` declines (a pinned peer, or a
  restatement it folds into a row) is counted as `memories_not_admitted`,
  so the receipt adds up to the source's count.
- The single sign-on links land in their own step (`_links`), run under
  `sso_same_issuer`, not at the end of `_grants`.
- Docs: a document address the namespace holds or has held is left alone, and
  of two namespaces merged into one the first brings an address or key both
  hold; the revoked-landing paragraph names the one target org the plan reads
  and what a delete leads to for an unfinished landing.
- The integration test lapses the revocation with a newer row instead of a
  mutation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
- A merge's `memory.bulk_set` calls check every entry, whatever
  `bulk_conflict_check_max_entries` caps a call at, send each call oldest
  first, and turn off update detection and reinforcement, which each rerun
  would add again.
- Under `newest_wins`, a same-key write retires the older rows in every
  session of its user (of anyone, for a write with no user): a merged key
  counts as held that far, the merge's own writes included.
- A merge no longer carries a source pin, which would refuse the target
  owners' own later writes of a close fact.
- The dry run builds every memory row the apply writes and names each one the
  target refuses, which would otherwise stop every apply at that row.
- The receipt counts single sign-on links; the landings are built once on the
  run; the Postgres authority's documents are read in `_held_uris`.
- Docs: merge admission settings, the `newest_wins` reach, what admission may
  still mark or retire, pins, the dry run's memory check, and the handle the
  plan proposes after a delete.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…ch other

- A row the merge leaves out (a dropped user's, one not live, a refused one,
  one the target holds) is decided before it claims a key, so a live row of
  its key still lands.
- Of the merged rows that would retire each other (one key under one agent,
  user and session, across two merged namespaces too, and under newest_wins
  as far as a same-key write reaches), the newest by valid_at, then
  created_at, then bundle order, lands; the receipt counts the others as
  memories_superseded. A first pass over the bundle finds them, a second
  writes them.
- The dry run measures a merged value against its char_limit as
  memory.bulk_set does, which refuses the whole call.
- Docs: under newest_wins admission may retire a target row stating the same
  attribute with another value unless the merged row is the older statement;
  the reach is of keys the target holds or has held; the dry run may name a
  row the run leaves out; the paragraph is rewrapped.
- The integration test merges into a newest_wins namespace and reads back
  which rows are live.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/cli/instance_import.py Resolved
Comment thread server/cli/instance_import.py Resolved
zlareb1 and others added 6 commits December 5, 2026 04:41
…its key

- Under newest_wins a named write never retires a row with no user, and a
  write with no user retires the named rows of its key written before it. The
  merge's rows with no user now compete only with each other, one user's rows
  only with that user's, and the rows with no user are written in a pass
  before the named ones: both land, as the source served them, and a run
  resumed between the two passes writes the same rows.
- The exact-identity and newest_wins groups are kept apart, and the counter
  of merged rows kept is named `carried`.
- Docs and docstrings: the newest by valid_at (its created_at where it has
  none), then the first in the bundle; the order of the two passes.
- Tests: a row with no user beside a newer named one, a run resumed after the
  rows with no user, and the receipt's `memories_superseded` end to end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
- The unit test puts the row with no user after the named row of its key in
  the bundle, so only writing the rows with no user first passes it.
- The integration test merges an end user's newer row beside the row with no
  user of its key into the newest_wins target, and reads both back live.
- The merged-row counter is `merged`, not the module's `carried`; the
  docstring says the rows with no user are written first; the second pass is
  a plain `if`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
- `_bulk_entry` reads the time through `utc_now`, so the unit test pins the
  clock: a newer row of a key past its expiry is left out and counted as not
  live, and the older live row of its key lands.
- The rerun state compares every row of the merged `team`, with its status
  and version, so a rerun that writes or retires a merged `newest_wins` row
  fails it; it replaces the single `team` key read through `memory.get`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
- `_live` decides whether a merge carries a row against the run's start, so
  the pass that ranks rows and the write agree: a row that expires between
  them was ranked the winner of its key, then dropped, and its key landed
  with no row. `_bulk_entry` takes the expiry from the time of writing, at
  least a second, so such a row lands and expires as it did on the source.
- The plan decides only the subjects of namespaces it does not skip: a
  skipped namespace's grants, owner and end users move nowhere.
- A test runs the import with a stale `--expect-plan`: exit 2, with neither
  the acceptance check nor the apply called.
- `as_aware_utc` replaces a copy of it; the docs say a merged row keeps its
  validity, and only a created namespace its `created_at` and attestation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
- `_live` requires `redacted_at` empty: a redacted head stays active with the
  placeholder as its value, which no read serves, and a merge wrote it as a
  fact with its redaction marks dropped. It is counted as not live, so a
  live row of its key lands.
- The plan refuses a mapping of an end user onto `user:-` or `user:`, which
  would land their rows beside the rows with no user.
- The runbook says a row that expires before its write lands with a
  one-second expiry; `landed_row` uses `as_aware_utc`; the `_kept` docstring
  names `_live`; the merge test's run starts before its expiry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
- Each merge call reads the target's keys of its entries again just before
  `memory.bulk_set`, and each document its address before
  `knowledge.upsert`, with the rule `_kept` uses (`_holds`): a key or
  address the target's owners write while the run goes on stays theirs.
  `_held_keys` and `pg_memory.held_in` take the keys to read; `_held_uris`
  reads only the addresses asked for.
- The dry run names a merged row whose `on_expire` is not the one the
  target's `memory.bulk_set` gives its sensitivity: the target would delete
  what the source demotes or anonymizes. A created namespace keeps it.
- A created row's `verified_by` and `locked_by` name a subject as the plan
  maps it, and no one where it drops or never planned it.
- The plan decides a merged namespace's end users, and its grant subjects
  only when it carries its grants, never its owner; the dry run says when a
  created namespace's owner does not land. A mapping onto `user:-` says why
  it is refused. The runbook covers a source erasure after the export.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d1626d0. Configure here.

kind, sep, who = str(m.get(col) or "").partition(":")
if sep and f"{kind}:" in (HUMAN_PREFIX, PROCESS_PREFIX):
to = run.subject(d.source_org, who)
m[col] = f"{kind}:{to}" if to else ""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pipeline actors remapped as subjects

Medium Severity

_row splits every human: and process: verifier and locker and looks the remainder up as a plan subject. Pipeline actors such as process:loom and process:cli:… are not principals. A suffix that matches a mapped handle is rewritten onto that person; any other pipeline actor is cleared on a created namespace.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d1626d0. Configure here.

This branch has not been deployed

No deployments
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