Skip to content

A first cell in recording records a new org only while the directory answers that it is attaching - #519

Merged
zlareb1 merged 3 commits into
mainfrom
feat/cell-router-state
Nov 12, 2026
Merged

zlareb1 merged 3 commits into
mainfrom
feat/cell-router-state

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 11, 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 (LOOM_CELL), the first cell in recording records a new org only while the router's directory answers that the cell is attaching; while the directory is unreadable or answers serving, a new org answers 503 and the orgs the cell holds keep serving. The router answers that read at GET /cells/v1/cells/<cell>, for the first cell's own credential only.

Why

The fifth of the pull requests that implement cells. It stacks on #497. A first cell's Postgres restored to before attach's step 3 reads recording again. If loom cell restore is skipped, that cell would record any new org with no check, because server.auth.tenancy.ensure_held recorded whenever the mode row read recording. The directory still says serving then, so asking it tells the two cases apart, which is what the design page says the cell does ("A process that reads recording records a new org only while the directory answers that its cell is attaching"). #473's and #497's descriptions named this read as still to come.

Design

  • GET /cells/v1/cells/<cell> (server/router/app.py, Router.cell_state):
    • the bearer must be the named cell's own credential, checked against the cached hashes first (a wrong one reads nothing) and then against the row just read, so a credential replaced on the row answers 401 within the cache window and the cache is read again on the next call;
    • answered only for the cell the directory marks first (directory.first_cell_named, a plain connection, not a lookup slot, so a lookup flood cannot starve it); any other cell answers 404;
    • a directory that cannot be read answers 503; the answer is {"cell", "state"}.
  • The cell's side (server/auth/tenancy.py):
    • directory_says_attaching() asks the router with LOOM_CELL_ROUTER_URL and LOOM_CELL_ROUTER_TOKEN, bounded as a whole by LOOM_CELL_ROUTER_TIMEOUT_S, and is true only for a 200 whose state is attaching. Anything else (no router configured, a refusal, a malformed or late answer) is false.
    • The answer, true or false, stands for LOOM_TENANCY_MODE_CACHE_S, and the requests waiting on it share one router call (a shielded task, as the placement call does).
    • ensure_held reads it only for an org the cell does not hold while the cached mode reads recording: held orgs keep serving whatever the directory says. On false, the org answers 503 and nothing is written.
    • The CLI goes through the same check (server/cli/_ch.py docstring updated), so an org-declaring command on a restored first cell refuses the same way.
    • The CLI now sends LOOM_CELL_ROUTER_TOKEN for that read, so it also keeps the page's rule on that credential: an org-declaring command refuses to run with it set, naming it, unless the cell reads recording (a later cell reads enforced), since the credential can place orgs in the shared directory.
    • With the router settings unset, the 503 names them; a malformed LOOM_CELL_ROUTER_URL (httpx.InvalidURL) counts as no answer, here and in the placement call, instead of escaping as a 500.
  • The page's code map names the new route and the cell's read.

Scope and risk

With LOOM_CELL unset nothing here runs, and no shipped command writes a mode row yet, so the read only matters once loom cell prepare exists. A first cell that is genuinely attaching now depends on the router to record a new org: during a router outage in the rollout, a new org answers 503 there, as the page's failure table already says ("A directory outage during the LOOM_CELL rollout and between prepare and attach leaves the first cell serving the orgs it holds, a new org answering 503").

Still to come with the routing pull request: routing rules 1 to 4, the cache of placed lookups, NO_CELL, and the lookup's clients (loom login --org, the org-first sign-in page, a typed WRONG_CELL error).

Compatibility, rollout and rollback

A new router route and a new check on the cell, both inside a cell only. A router older than this answers the state read 404 (no route), which the cell reads as not attaching: run the router first, as the page's order already says. Rolling back the cell removes the check.

Tests

  • tests/unit/test_router.py (64): a malformed placement answers 400 before any credential read; the first cell reads its own state (attaching, serving); a later cell answers 404; a wrong credential, another cell's own credential, a malformed name and an unknown cell answer 401; no bearer reads nothing; a replaced credential still cached answers 401 and the new one is accepted after one more directory read; a directory outage answers 503.
  • tests/unit/test_cell_tenancy.py: a recording cell the directory marks serving writes nothing for a new org and still serves a held one; the read is true only for a 200 naming attaching (serving, 404, 401, a non-object, a refused connection are false), is read once per window and shared by a burst of five, a false answer stands for the window too, a cancelled waiter leaves the read to the others, is false with no router configured (and the 503 names the unset setting) or with a URL httpx refuses (https://router.test:notaport, no request sent), and is cut off at the timeout; a placement with that URL answers 503 and writes nothing. The other recording tests run with the directory answering attaching.
  • tests/unit/test_cell_cli_orgs.py: the CLI's recording tests run with the directory answering attaching; a restored first cell the directory marks serving refuses a command for a new org and records nothing; a command with LOOM_CELL_ROUTER_TOKEN set refuses on an enforced cell, naming it, and runs on a recording one.
  • tests/integration/test_router_directory_pg.py: first_cell_named answers a cell the test marks first and nothing for another; the test moves the earlier first-cell mark to its own cell and restores it in a finally. Passed against a local Postgres.
  • The new recording check, the router's row credential check and the CLI's credential refusal were each removed in turn, and a test failed each time.
  • Targeted at the latest head: the router and tenancy tests (158 passed) and, at the head before, with the cell, CLI-org, package-contract and doc tests (516 passed); make lint and make typecheck pass. The full unit suite has not run on this stack.

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 marked this pull request as draft November 11, 2026 04:09
@zlareb1
zlareb1 force-pushed the feat/cell-router-directory branch from 4adc124 to ee97a1d Compare November 11, 2026 14:48
@zlareb1
zlareb1 force-pushed the feat/cell-router-state branch from 3c8f568 to 681c892 Compare November 11, 2026 14:48
@zlareb1
zlareb1 force-pushed the feat/cell-router-directory branch from ee97a1d to eb541c9 Compare November 11, 2026 15:11
@zlareb1
zlareb1 force-pushed the feat/cell-router-state branch from 681c892 to 221e6a5 Compare November 11, 2026 15:11
@zlareb1
zlareb1 force-pushed the feat/cell-router-directory branch from eb541c9 to 8242b63 Compare November 11, 2026 15:31
@zlareb1
zlareb1 force-pushed the feat/cell-router-state branch from 221e6a5 to d1eedc8 Compare November 11, 2026 15:31
@zlareb1
zlareb1 force-pushed the feat/cell-router-directory branch from 8242b63 to 0634607 Compare November 11, 2026 15:47
@zlareb1
zlareb1 force-pushed the feat/cell-router-state branch from d1eedc8 to 4a6fdcb Compare November 11, 2026 15:47
@zlareb1
zlareb1 force-pushed the feat/cell-router-directory branch from 0634607 to 4e3c11e Compare November 11, 2026 22:47
@zlareb1
zlareb1 changed the base branch from feat/cell-router-directory to main November 11, 2026 22:47
zlareb1 and others added 3 commits November 12, 2026 00:07
…answers that it is attaching

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…e as 503

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 force-pushed the feat/cell-router-state branch from 4a6fdcb to 907e82c Compare November 12, 2026 00:17
@zlareb1
zlareb1 marked this pull request as ready for review November 12, 2026 00:18
@zlareb1
zlareb1 merged commit 3ece14f into main Nov 12, 2026
8 checks passed
@zlareb1
zlareb1 deleted the feat/cell-router-state branch November 12, 2026 00:18
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