Skip to content

Every CLI command that connects declares the orgs it writes, and a cell refuses one it does not hold - #484

Merged
zlareb1 merged 4 commits into
mainfrom
feat/cell-cli-orgs
Nov 11, 2026
Merged

zlareb1 merged 4 commits into
mainfrom
feat/cell-cli-orgs

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

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

On a cell, a CLI command refuses, before it runs, an org the cell does not hold. Every command that connects declares the orgs it writes, or why it writes for none. On any deployment, a loom code command that reads its repository entry (_repo_cfg) and whose org has no configured entry now refuses instead of indexing the first entry's checkout under that org.

Why

The third of the pull requests that implement cells. The design is #452; this stacks on #473, the tenancy check on requests. A CLI command is not a request, so the transports' check never sees it, but it writes too: an import into an org, a bot, a rechunk, a reembed. Without a check of its own, an operator could write memory for an org another cell holds into this cell's stores.

Design

  • server/cli/_ch.py:

    • run_connected, connect_checked and a new connect_declared each take orgs= (the orgs a command writes) or org_free= (why it writes for none). A call with neither raises TypeError.
    • An orgs= that is passed but unset (a command's optional --org) names no org and checks nothing.
    • connect_declared connects and checks the orgs. connect_checked is connect_declared with the memory-authority check it already made (check_authority=True).
    • connect_code_plane(ch, args) declares the org a code-index command writes: its --org, else LOOM_CODE_ORG, as code_run._identity resolves it, and none on a --dry-run (answers-purge, coverage-import, repack). It resolves the org and namespace before it connects. scip-full and backfill's index phase resolve their entry first (backfill --phase embed reads no entry; it reads its first page of pending chunks on code_run's connection and declares its --org only when there are chunks to embed, so a mistyped --org has none and is never recorded, while the pass's status row, keyed by namespace, still lands), and _repo_cfg refuses a fallback entry of another org, so a mistyped --org is never indexed under that org's checkout; reembed and vector-twin check their model first; scip-retry reads its batch before it declares the org. A code command that refuses its own arguments therefore exits before a recording cell records anything. A pass over every configured repository (the SCIP delta, code_run's registry read and drain) declares none: configured orgs are placed at attach. compact declares none: it optimizes whole tables. scip-retry and entry-lock declare their --org.
    • On a cell, connect_declared first runs the deployment check (check_configured), so a tenancy row is written only into this deployment's own Postgres.
  • The check (check_orgs), with LOOM_CELL set and an org declared, reads the cell's rows (cell.refresh, with the deployment id set as boot sets it: a CLI process has read neither), after handing in the code orgs' reader (cell.set_code_orgs(repos.operator_orgs)), as boot does for a server, so its fingerprint is the one its server reports. It then applies the transports' gate: the command is refused when cell.gate_reason() is non-empty, so a shell whose LOOM_CELL or configuration is not its cell's records nothing, as the server would serve nothing. It then runs tenancy.ensure_held(org, None) for each declared org, before the command runs:

    • in recording, it records the org, as a request's org is recorded;
    • in enforced, it refuses an org the cell does not hold (OrgNotHeld, a SystemExit naming loom cell place, so the operator reads the message, not a traceback);
    • with no principal, it never places an org;
    • an unreadable tenancy (BackendUnavailableError) refuses with its message.
  • Every command declares. Every run_connected, connect_checked and connect_declared call declares orgs or a reason. Examples:

    • orgs=(args.org,) for the org-scoped commands, and orgs=dry_run_orgs(args) for those with --dry-run: a dry run only reads, so it declares no org (namespaces-gc declares its org only with --erase; reextract's connection only reads, and its replay writes through the server at --base-url);
    • the org _identity resolves, through connect_code_plane, for backfill-reviews, backfill-items and backfill-assignees (equal to the entry's org, since _repo_cfg refuses a mismatch), and orgs=(cfg.org,) for reconcile only with --heal; without it reconcile only reads and declares org_free="reads";
    • "the cell's settings" for the settings and key commands;
    • "sweeps the cell's own rows: every org it touches is held" for sensitivity-sweep, and its "repairs" variant for integrity-repair;
    • reads for every read-only command (entity-export, audit-namespace, mentor, drops, deploy-delta, doctor, the claim lookup before a release, and loom code stats, export-matrix, export-pairs, lint-instructions --symbols): a read records no org, and a CLI argument is free text that a recording cell would otherwise keep for good.

    The direct .connect() calls (the code-index commands, doctor, the analytics export, sql-access, the re-extract session read) now go through connect_declared, connect_code_plane or sql_access._connected. Outside a cell the code-index commands keep their behaviour. On a cell they gain the tenancy check and, through connect_declared, the deployment check. Those outside run_connected, doctor's two reads included, now close with _ch.disconnect, which closes the Postgres pool the tenancy read opens. connect_declared leaves an already connected client as it is (CHClient.connected; the tests' fake clients say connected = False), so a loom code command's connect inside code_run's no longer replaces the open driver.

  • The census (tests/unit/test_cell_cli_orgs.py) reads the syntax tree of every module under server/cli/, plus the two callers outside it (a benchmark harness and the op-reach census). It fails on:

    • a connect call that declares neither orgs= nor org_free=;
    • a .connect() under server/cli/ outside _ch.py, other than the setup command's own admin client and SQLite files;
    • a loom code coroutine that resolves its org (_identity, _repo_cfg) without a connect of its own;
    • a command that declares orgs=(args.org,) while it, or a function of its module it calls, reads args.dry_run.

Scope and risk

With LOOM_CELL unset, check_orgs returns at once, and a connect must say what it writes: a refusal at the call site, which the census catches in CI, not at run time. The design's gate for a CLI with LOOM_CELL unset comes later, with the gate for server processes that #468 defers. Two of the page's CLI rules come with #519, which first makes the CLI call the router: recording only while the directory answers attaching (read with LOOM_CELL_ROUTER_TOKEN), and the refusal of a command that declares an org while that credential is set outside a first cell in recording. Until then check_orgs records whenever the mode row reads recording.

The all-repository passes (scip-delta, the drain) stay org-free because #468's fingerprint counts the org of each LOOM_CODE_REPOS_JSON entry the code config keeps among the configured orgs, which attach places. One change reaches every deployment: _repo_cfg, with no entry for the addressed org and namespace and no --namespace naming another, used to fall back to the first entry whatever its org, so LOOM_CODE_ORG=other with only an acme entry indexed acme's checkout under other. It now exits non-zero, naming the remedy: --namespace of the org's own entries when it has some, else --org of the first entry, or an entry for the org and namespace.

Compatibility, rollout and rollback

  • Wire: none. CLI: an enforced cell refuses a command for an org it does not hold; on any deployment, a loom code command that reads its repository entry (_repo_cfg) and whose org has no configured entry refuses rather than indexing another org's (a scheduled run that relied on that fallback passes --org of the entry, or gets an entry of its own).
  • Rolling upgrade: no schema change.
  • Operator steps: none.
  • Rollback: revert.

Tests

  • tests/unit/test_cell_cli_orgs.py:
    • backfill --phase embed declares its org only once its first page has chunks, and an empty pass still writes its status row;
    • a CLI counts the code orgs as its server does: with an accepted fingerprint that holds a code org, check_orgs passes the gate (test_a_cli_counts_the_code_orgs_as_its_server_does; it fails without the hand-in);
    • loom code reconcile on a recording cell records nothing without --heal and records its entry's org with it, through the real connect_declared and check_orgs;
    • a CLI recording insert that finds enforced (the cell's rows read recording) records nothing and refuses, naming loom cell place, with no placement call;
    • the two censuses;
    • a connect declaring nothing is refused, and a declared but unset org checks nothing;
    • outside a cell nothing is checked;
    • on a cell a declared org is recorded or refused and never placed;
    • a command for an org the cell does not hold never runs, and its connection is closed.
  • The existing CLI and bench tests' fakes of run_connected, connect_checked and _connected accept the declaration (bench/test_docparse.py included). The entry-lock tests stub the connect entry-lock now makes. After the rebase onto main, every code, CLI, SCIP and cell test file with bench/test_docparse.py (two workers): 5512 passed; the census found loom reconcile, new on main, undeclared (now declared); the other three failures are test_code_regex_cost.py timing cases, which fail on the base too.
  • test_a_cli_process_reads_the_cells_mode_before_it_checks drives the real ensure_held against fake Postgres reads: recording records a new org, enforced refuses it; test_a_cell_whose_rows_cannot_be_read_refuses_every_declared_org; test_a_cell_the_transports_would_close_refuses_the_command; test_an_unread_tenancy_refuses_with_its_message; test_a_dry_run_declares_no_org; test_a_connected_client_is_not_connected_again.
  • test_a_code_index_command_declares_the_org_it_writes (its --org, else LOOM_CODE_ORG, else none) and test_on_a_cell_a_declared_connect_verifies_the_deployment_first.
  • Full unit suite: not yet completed on this stack; two runs on the base PR were stopped by the host's memory pressure (a shared machine). The CLI-touching test files and the censuses above stand in until it runs before merge.

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 full unit suite result follows in Tests).
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

@zlareb1
zlareb1 force-pushed the feat/cell-cli-orgs branch 3 times, most recently from 091c589 to d7759cb Compare November 10, 2026 14:44
zlareb1 and others added 4 commits November 11, 2026 21:44
…ll refuses one it does not hold

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ith 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]>
@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