Repository navigation
A cell serves only the orgs it holds, and places a token's new org through the router - #473
Merged
Merged
Conversation
8 of 9 tasks
zlareb1
force-pushed
the
feat/cell-tenancy
branch
3 times, most recently
from
November 10, 2026 16:15
397f333 to
ca8bcf8
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 16:29
68a8a90 to
f027958
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
5 times, most recently
from
November 10, 2026 17:31
038d76c to
ce1c191
Compare
8 of 9 tasks
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 17:43
4fbf5ce to
cf01548
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 17:44
ce1c191 to
a991311
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 18:03
cf01548 to
14756d1
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 18:03
a991311 to
dc4467a
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 18:19
14756d1 to
d8d68d3
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 18:19
dc4467a to
85b33db
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 18:29
d8d68d3 to
5a4f90e
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 18:29
85b33db to
ab3b97c
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 18:37
5a4f90e to
91a07de
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 18:37
ab3b97c to
ce4c529
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 18:44
91a07de to
2116808
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 18:44
ce4c529 to
d7e3709
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 18:55
6c805a6 to
6fa170b
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 18:55
d7e3709 to
852f2cd
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 19:01
6fa170b to
f2cff64
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 19:01
852f2cd to
f72ebd1
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 19:08
f2cff64 to
09487d4
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 19:08
f72ebd1 to
bfe68c9
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 19:13
09487d4 to
5a9a54e
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 20:18
3bbcb34 to
d528030
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 20:25
b3fa649 to
e1dbf1e
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 20:25
d528030 to
4f64737
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 20:31
e1dbf1e to
6d00bd7
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 20:32
4f64737 to
93d8d1a
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 20:45
6d00bd7 to
88c4880
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 20:47
93d8d1a to
a1c7f0c
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 20:56
88c4880 to
cb89ef2
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 20:57
a1c7f0c to
458d411
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 21:14
cb89ef2 to
610acf9
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 21:15
458d411 to
defead1
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 21:30
610acf9 to
7479bc9
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 21:30
defead1 to
bca1c48
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 21:34
7479bc9 to
3201ba7
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 21:46
bca1c48 to
cabdeb4
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 21:52
3201ba7 to
435bd7b
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 21:54
cabdeb4 to
6b1faed
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 21:58
435bd7b to
4dd3a95
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 21:59
6b1faed to
2e33d08
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 22:04
4dd3a95 to
557964c
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 22:05
2e33d08 to
82147b6
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 22:11
557964c to
ee77c95
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 22:12
82147b6 to
fbe1b11
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 22:18
ee77c95 to
853547c
Compare
zlareb1
force-pushed
the
feat/cell-tenancy
branch
from
November 10, 2026 22:20
fbe1b11 to
8c561bc
Compare
zlareb1
force-pushed
the
feat/cell-own-state
branch
from
November 10, 2026 22:26
853547c to
a859730
Compare
This was referenced Nov 11, 2026
…rough the router Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
A cell serves only the orgs it holds: a call for another cell's org answers 409
WRONG_CELLand writes nothing, and a token's own org new to the cell is placed through the router. WithLOOM_CELLunset nothing changes.Why
The second of the pull requests that implement cells (the design is #452; this stacks on #468, which gates a cell's process on its own rows). It adds the tenancy check: how a cell knows it holds the org a verified call acts in, records it before the first attach finishes, places a new one through the router after, and refuses another cell's.
Design
server/auth/tenancy.py(ensure_held), withLOOM_CELLset, for the org a verified call acts in:may_act_in_org: a token of another org) is refused first with the gate's 403, so it records, places and learns nothing, not whether the cell holds the org nor where it is placed;loom.tenancy, or one this process has seen held: a held org is never wrong to serve) passes with no further read;recording, one statement inserts the org's row only while the mode is stillrecording, and a conflict with another process's insert reads again;enforced, a principal scoped to the org (its token's own org) asks the router to place it (POST /cells/v1/placementsatLOOM_CELL_ROUTER_URLwithLOOM_CELL_ROUTER_TOKEN, carrying the process's fingerprint). The router inserts the placement if absent and answers the winner (cell and deployment id). Placed here, the cell writes its row and serves; placed elsewhere, 409WRONG_CELLand nothing written;*-org principal, or a call with no principal, never places an org;Retry-After(1 to 60 s) becomes the 503's, so a client past its cell's rate waits as the router asks;LOOM_CELL_ROUTER_TIMEOUT_Sbounds the whole call (asyncio.timeout), not each read;is_held, which personal-namespace provisioning reads for a caller acting in another org, remembers an org it read as not held forLOOM_TENANCY_MODE_CACHE_S, so such a caller reads Postgres once a window;'','-'and'*'name no tenant and are not checked.gates.authorize) checks the call's resolved org first, beforecheck_acted_forand personal-namespace provisioning, for HTTP and MCP alike; over MCP,WRONG_CELLis a tool error (isError) at the op gate and at the pre-dispatch namespace screen alike, so a batch keeps its other answers; a call in the token's own org, asgates.resolve_orgresolves it (acode.*ortracker.*call naming no org acts in its plane's org), is checked before the caller's defaults are read (they live in that org), a 503 there ledgered before it is raised (its rows under the token's org, so the scrub blanks them), so a call that names no namespace answersWRONG_CELL, not a validation failure, and the listings (initialize,tools/list) treat such an org as having no default; and the gate provisions the token's own personal namespace only where that org is the call's or its tenancy row is present (tenancy.is_held, read on a cache miss and placing nothing, so every replica does the same);check_authorized, which the routes outside the registry authorize through;admit_org(refuse_foreign_org, then the check), which every admin route whose body names its org now calls;ratelimit.set's org tier, and the admin account routes that write for a body's org;TenancyMiddleware(server/transport/tenancy_gate.py), inside the maintenance middleware, checks the org the routes that act in the token's org act in (acts_in_token_org:/v1/me/…, SCIM Groups, the assistant; for an org-wide or org-less token on/v1/me/set-default-namespaceand/v1/me/sharing-summary, theself_signup_orgthose routes fall back to, checked with no principal, so it is recorded or refused, never placed), exactly the routes the census markstoken, so a platform admin whose own org lives elsewhere still reaches the routes that act in no org or in a held one; a request with no bearer, a malformedAuthorizationheader, or a token that does not verify passes to the route, which answers it; a token the process cannot judge yet (AuthUnavailable) answers 503 there, never passing unchecked. Its refusals take the route's own shape: an RFC 7644 error on the SCIM routes, Loom's envelope elsewhere.loom.agent_eventsrow (the policy witness holds the same scrubbed row), but with the org, identity tuple, subject, consumer, key, run and arguments blanked (tenancy.attributable): that org's rows belong to its own cell, whose erasure never reaches this one. Acode.*validation failure writes no code trace for such an org. Worker rows keep theirs: a pass runs on the cell's own stores.tests/unit/test_cell_tenancy.py) lists every route of the app outside the op registry astoken(the middleware),named(its handler, or a function of its module it calls, calls a check, read from the syntax tree) or org-free with the reason, and fails on a route not listed, an entry naming no route, or anamedroute whose module calls no check.WRONG_CELL(409) joins the error reference. The SDKs map it by status until The SDKs raise a typed WrongCell that names the org and its cell #521 adds a typedWrongCell(The router's directory and placement API: a cell places a new org, and a client finds an org's cell #497 adds/cells/lookup; the routing pull request adds the lookup's clients).orgthat names an org (from_orgonmemory.copy_to,memory.cross_promote,procedure.fork, each checked throughcheck_authorized).LOOM_CELL_ROUTER_URL,LOOM_CELL_ROUTER_TOKEN(a secret: its name now matches the settings' secret pattern; refused at boot unless it islcr_and 128 lowercase hex characters, since the directory keeps only its unsalted SHA-256, and a length no SHA-256 has, so the secret is never taken for its hash) andLOOM_CELL_ROUTER_TIMEOUT_S(default 5 s).Left for later pull requests, as the design orders them: the recording cell's read of its own state from the directory (
GET /cells/v1/cells/<cell>, before it records a new org; here arecordingmode row records, and no shipped command writes one until prepare, which lands after that read), the CLI's org declarations, the enforced-mode Postgres trigger and the ClickHouse writer check (with attach), and the router itself and its directory.Scope and risk
Configured orgs (
oidc_jit_org, theself_signup_orgof a cell with signup on, the code and tracker orgs) are placed at attach. A call with no principal (JIT, self-signup) for one the cell does not hold yet answers 503, a retry naming what places it (attach, orloom cell updateonce the cell serves), neverWRONG_CELL; JIT runs the check before it writes an account (jit._provision_jit).Not in this PR: workers writing only for orgs the cell holds (the design's rule for a later cell's code index before attach), which lands with the commands that prepare and attach a later cell. And the design has a
recordingcell record a new org only while the directory answers that the cell isattaching(docs/architecture/cells.md, "What each cell runs"). That needs a cell-state answer from the router, which the router pull request after #497 adds together with this check; until then arecordingcell records as it does here. Merging first is safe because no command in this stack writesloom.tenancy_modebefore that pull request: nothing here runsloom cell prepare, attach orloom cell restore, so no cell is inrecordinguntil the check exists, and those commands land after it.Every path is behind
settings.cell. The middleware returns at once withLOOM_CELLunset; with it set, a raw route's bearer is verified twice (the middleware, then the route), which these low-volume routes afford.Compatibility, rollout and rollback
WRONG_CELL(409), from a cell only.Tests
tests/unit/test_cell_tenancy.py(79 cases):Retry-Afterbecomes the 503's, clamped to 1 to 60 s, and 1 s when absent or unreadable;recordingafter Postgres moved toenforced: the recording insert writes nothing and a scoped principal is placed through the router, a platform principal refused with no call;lcr_and 128 lowercase hex characters refused at boot, and an unset one accepted;WRONG_CELL, and JIT writes no account in an org the cell does not hold;LOOM_CELLunset, nor an org-free call;WRONG_CELLand writes nothing;check_acted_for;check_authorizedchecks;admit_orgrefuses a foreign org before checking;/mcpendpoint (the namespace screen included) keeps both answers when one entry names another cell's org (this test fails without the screen's catch); aloom_memory_setwith no namespace from another cell's org answersWRONG_CELL(fails without the check before the defaults); the pre-check resolves acode.*call's org as the gate does, and ledgers a 503;/v1/me/sharing-summary), a missing, malformed or unverifiable bearer passes to the route with nothing checked;code.*validation failure leaves no trace for an unheld org;/v1/admin/workers.status,/v1/admin/token.mintand/v1/whoamithrough the middleware;is_heldreads the row on a miss and places nothing;recordingandenforced, for an org held, unheld or remembered elsewhere, recording, placing and naming nothing;WRONG_CELLsays to call a cell only when it names one;tokenones, eachnamedroute's handler (or a function of its module it calls), and the census of org-like op fields.tests/unit/test_settings_env_contract.py: the environment sweep givesLOOM_CELL_ROUTER_TOKENa value of its form, so the variable is still checked to reach its field.tests/integration/test_cell_tenancy_pg.pyruns the module's own statements against Postgres: in a transaction it rolls back, a recording insert records once and conflicts after,enforcedrecords nothing, and a retried placement insert writes one row; and, over separate connections, an insert held open makes attach'sLOCK TABLE loom.tenancy_mode IN EXCLUSIVE MODEwait (the insert reads the mode rowFOR SHARE), and an insert that starts while attach waits queues behind it, then readsenforcedand records nothing; each wait is seen inpg_stat_activity, and the test ends its racing backends before it restores the mode and rows it touched. WithoutFOR SHAREthe second test fails. Both passed against a private Postgres 16. CI's Postgres integration job runs the file (.github/workflows/ci.yml). A third test checks thatloom.cell_first(A cell's process serves only while its own rows in Postgres accept its configuration #468) refuses an update, a delete and a truncate, also undersession_replication_role = replica: it passed against a database built from A cell's process serves only while its own rows in Postgres accept its configuration #468's008_cells.sqland fails against one without itsENABLE ALWAYSlines. It skips without the table or without a superuser; CI'sloomrole is the image's bootstrap superuser (dev/ci_start_postgres.sh), so it runs there. A later cell never records: A cell's process serves only while its own rows in Postgres accept its configuration #468's mode cache reads any mode butenforcedasenforcedthere, soensure_heldplaces, never records, on a later cell.test_sdk_errors_from_responsehas the new code's row.test_package_contractsandtest_transport_layeringpass with the module inserver/auth/(it readsauthzand the roles, whichserver/coremay not).eu-1inenforced(a private ClickHouse and Postgres) beside a stub router that placesacmehere and answersbetawithus-1:memory.setwith anacmetoken: one placement call (URL, bearer and fingerprint as sent), the tenancy row written, the memory written, 200; a latermemory.getmade no router call;memory.setwith abetatoken: 409WRONG_CELL, no tenancy row, no memory;/v1/me/sharing-summary) answered 409 forbetaand 200 foracmethrough the middleware;/v1/whoamiwithout a bearer reached the route;beta's refused calls, theWRONG_CELLand an earlier unknown-argument refusal, left no row namingbetainloom.agent_events(nor the rollups it feeds); before the telemetry fix in this branch they left three.tests/unit/test_cell_tenancy.py(79 passed), and withtest_cell.py, the SDK-error and errors-reference tests and the doc links (457 passed); earlier, everytests/unit/test_mcp_*.pywith the doc gates (623 passed), and earlier the tenancy, MCP, agent-claim, SDK-error and doc gates. The full suite is run 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 typecheckandmake test-unitpass (the full unit suite result follows in Tests); the integration suite passes if server behaviour changed.docs/reference/configuration.mdand thedocs/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).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code