Skip to content

Cells: a deployment spreads its orgs over complete deployments behind a router, each serving only the orgs placed in it - #452

Merged
zlareb1 merged 1 commit into
mainfrom
docs/pg-placement-units
Nov 11, 2026
Merged

zlareb1 merged 1 commit into
mainfrom
docs/pg-placement-units

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Documentation (changelog entry is not required)

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

...

Why

Under LOOM_STORAGE_AUTHORITY=postgres a deployment's whole authority is one Postgres primary, and its ClickHouse service and bucket are shared by every org. Measured with a synthetic load (Memory at scale), a key costs about 6.8 KB of Postgres and 13.6 KB of ClickHouse, so one primary reaches several TB around a billion keys, where vacuum, failover, backup, restore and erasure by org all slow down. An org may also need its memory in services of its own.

docs/architecture/cells.md is the design the cell pull requests implement. An earlier draft of this page split Postgres alone into placement units behind one control plane. That draft was replaced because every security check, worker lease, erasure, policy generation and the audit chain would then span stores, and each needs a protocol of its own (the page's "Rejected" section).

Design

  • A cell is a complete deployment: its replicas and workers, one Postgres unit with a synchronous standby, one ClickHouse service, one bucket prefix, its own public host, keys, grants and erasure. Every guarantee a single deployment makes holds per cell unchanged. An org lives in exactly one cell and never leaves it.
  • The router is a stateless proxy on the shared host. It holds a directory (cells, placements, hosts) in its own Postgres and routes by host, by SCIM host, by the token's issuer, and otherwise to the first cell. Until the first cell is serving, it passes every request on the shared host but its own /cells/ and health paths through to the existing deployment.
  • The tenancy check. With LOOM_CELL set, a cell serves only the orgs it holds a loom.tenancy row for. An org comes to a cell only through a verified request whose principal is scoped to it (or, on the first cell in recording, an org-declaring CLI command, recorded as a request is), through loom cell place with the router's operator credential (for a bot, an import or a new org of people), at attach (the orgs the first cell already holds and each cell's configured orgs), or through the loom cell update that changes a configured org. The cell calls the router's placement API (under a per-org lock, the winner read, else the cell judged on its locked row and the placement inserted), and another cell's org answers 409 WRONG_CELL with nothing written. A cell's placement calls are rate-limited per cell at each router replica (an operator's loom cell place is not rate-limited), bounded in total by a per-cell quota once one is set, and are never deleted. Until attach's step 3 writes enforced to the cell's mode, and again whenever step 3 or step 4 returns it to recording, the first cell (only the first cell ever records) records a new org as a single deployment does, while the directory answers attaching, with a tenancy row and no placement call (the insert reads the mode row FOR SHARE, and attach takes LOCK TABLE loom.tenancy_mode IN EXCLUSIVE MODE before writing the mode, in short tries, in one transaction with server-side timeouts, ending a cut-off session and reading the mode back after any error (each recording insert commits on its own), so the write waits for running inserts, later ones queue behind it, and a queued insert waits a few seconds at most), and attach places those orgs unrefused; after step 3 or step 4 returns it to recording, a process whose cache still reads enforced places through the router's gate until its cache expires. In every state but open (no first, mode, tenancy or own row) and the first cell in recording (docs/architecture/cells.md, "The first row"), statement-level triggers refuse a row of any org-keyed table of the authority but loom.tenancy for an org the cell does not hold, and attach requires the cell's ClickHouse writer credentials rotated to checking builds; an older CLI given the rotated credential still writes ClickHouse unchecked, and loom doctor lists what it wrote. Under the Postgres authority, a server process or an org-declaring CLI command with LOOM_CELL unset refuses in those same states; org-free commands run as before.
  • One exception to failing closed. A registered cell with no state, tenancy or own row (its Postgres restored to before its prepare, or a prepare stopped between registration and its row write) is open until loom cell restore (after a restore) or a prepare rerun (after a stopped prepare): the cell's Postgres, which holds its state, cannot tell it from a deployment never prepared (ClickHouse carries no cell state: adding it would make the write path read a second store for tenancy), and a process with LOOM_CELL unset never reads the directory, so nothing local can refuse. A process with LOOM_CELL set stays unready (no mode row), and loom doctor, which reads the directory, names the cell. Every other state but the first cell in recording, including both rows absent beside a tenancy or own row, is gated.
  • Each cell's own row. Each process computes a fingerprint of what it accepts: hosts, OIDC client, SCIM, issuers, configured orgs, end-user org patterns, the deployment id and the bucket name and prefix. A process that matches neither value of its cell's loom.cell_self row (current, and next during a change) answers 503 to everything but health and the probe route. It also stands aside from the workers in every mode. loom cell update widens directory-first and narrows cell-first, so no issuer is ever accepted unreserved.
  • Prepare and attach. loom cell prepare registers a cell. It proves the stores are the live ones by a nonce echoed through an internal probe address, and records an immutable first row and the tenancy mode. The first cell is anchored to the router's own upstream configuration. loom cell attach runs the overlap refusals (issuers, OIDC client, hosts, org patterns, configured orgs, the root-secret fingerprint, the deployment id, Keeper and bucket isolation) under one directory lock, then moves the first cell from recording to enforced.
  • An org's cell is public. GET /cells/lookup?org=<org> is unauthenticated and rate-limited, so it tells that an org outside the first cell exists, as a workspace URL does. This is the one place the design confirms an org exists without a token; ops addressed by id still answer found=False, never a 403. The lookup is what lets loom login --org and the sign-in page start every flow at the org's cell host, so no flow crosses cells.
  • SCIM per cell: each cell is its own identity provider application, with tokens named for the cell (lsc_<cell>_…).
  • Scoped out. Designs of their own, with the requirements this page names: moving an org between cells, retiring a cell, and moving a cell's data to other stores or adding a bucket after prepare. Done as a single deployment does: restore safety beyond a single deployment's, and changing a cell's identity provider application. A design of its own, with no requirements stated yet: rebuilding a lost directory.

Scope and risk

Documentation only. The page describes settings, tables, routes and CLI commands that the pull requests built on it add. It merges only together with that implementation, or cut down to what has landed.

Compatibility, rollout and rollback

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

Tests

tests/unit/test_doc_links.py, tests/unit/test_public_copy.py, python scripts/codegen/docs_reference.py --check (llms.txt lists the page); prettier --check on the pages. The page's Tests section lists the behaviour each implementing pull request tests.

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: 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: not yet. The page describes the cells the implementing pull requests add, so this stays a draft until they land with it.
  • 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 docs/pg-placement-units branch from d9e3391 to 9921096 Compare November 10, 2026 04:44
@zlareb1 zlareb1 changed the title The storage-authority design describes Postgres placement units: the org route, fencing by epoch and moving an org Cells: a deployment spreads its orgs over complete deployments behind a router, each serving only the orgs placed in it Nov 10, 2026
@zlareb1
zlareb1 force-pushed the docs/pg-placement-units branch from 9397c1c to f4d106d Compare November 10, 2026 16:22
@zlareb1
zlareb1 force-pushed the docs/pg-placement-units branch from b6bd271 to 10312a3 Compare November 11, 2026 01:24
@zlareb1
zlareb1 force-pushed the docs/pg-placement-units branch from 0c0869a to d3ce44c Compare November 11, 2026 21:03
@zlareb1
zlareb1 marked this pull request as ready for review November 11, 2026 21:04
@zlareb1
zlareb1 merged commit 966d272 into main Nov 11, 2026
19 checks passed
@zlareb1
zlareb1 deleted the docs/pg-placement-units branch November 11, 2026 21:04
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