Skip to content

The router answers a placed org's lookup from its cache while the directory is down - #520

Merged
zlareb1 merged 1 commit into
mainfrom
feat/cell-router-lookup-cache
Nov 12, 2026
Merged

zlareb1 merged 1 commit into
mainfrom
feat/cell-router-lookup-cache

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

The router answers a placed org's GET /cells/lookup from its cache while its directory cannot be read, and the lookup before any cell is registered answers 503 with the code NO_CELL, which clients match instead of the message.

Why

The sixth of the pull requests that implement cells. It stacks on #519. The page says that with the directory down, only "a lookup of an org it has not cached" answers 503, and that loom login --org keeps its host only on the NO_CELL answer. The router read the directory on every lookup and answered every 503 with free text, so an outage failed every lookup and a client could not tell "no cell yet" from "directory down". #497's description named both as still to come.

Design

  • Cache of placed orgs (server/router/app.py, Router.lookup):
    • a lookup that finds a placement remembers (cell, host) with the time it was read;
    • within LOOM_ROUTER_DIRECTORY_CACHE_S the cached answer is given without a read; once older, the directory is read again, so a cell's changed host reaches the lookup;
    • when that read fails, a cached org gets its last answer (a placement never changes), stamped before the read so lookups arriving while it runs, and after it fails, get the cached answer: a down directory is read at most once a window per org rather than costing every lookup a read and its timeout, and an org not cached answers 503;
    • an org with no placement, which answers the first cell, is not cached, so it answers its own cell once placed;
    • bounded at MAX_KEYS (the limiter's bound), forgetting the oldest read.
  • NO_CELL: _refused takes an optional code, and the lookup's "the directory holds no cell yet" answer carries code: "NO_CELL". The outage 503 carries none. NO_CELL is classed configuration, not retryable (CLASS_BY_CODE), since it is a settled answer the client acts on, and docs/reference/errors.md is regenerated to say so.
  • The page's code map names the cache, and LOOM_ROUTER_DIRECTORY_CACHE_S's description (and the generated settings reference) says it also bounds how long a placed org's lookup answer stands.

Scope and risk

Router only. The cache is per replica and in memory; a restarted replica answers uncached orgs from the directory again. Each replica's lookups still go through its per-client limit before the cache.

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

Compatibility, rollout and rollback

Additive: a field in one 503 body and a cache inside the router. Rolling back makes every lookup read the directory again.

Tests

  • tests/unit/test_router.py (70): a lookup before any cell is registered carries NO_CELL; a looked-up org keeps its answer through a directory outage well past the window, while an uncached one answers 503 with no code; a cached answer is not read again within the window and is read again after it, picking up a changed host; an org with no placement is not cached and answers its own cell once placed; a down directory is read at most once a window per cached org, including by four lookups arriving together while a slow failing read runs; past its bound the cache forgets the oldest, which then answers 503 during an outage while the others keep theirs.
  • Removing the outage fallback, and stamping only after the failed read, each made a test fail.
  • Targeted at this head: the router, error and doc tests (450 and 288 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

…ectory is down, and the lookup before any cell is registered carries NO_CELL

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the feat/cell-router-lookup-cache branch from 70d88ba to a193b36 Compare November 12, 2026 00:51
@zlareb1
zlareb1 marked this pull request as ready for review November 12, 2026 00:51
@zlareb1
zlareb1 merged commit 32bd5f7 into main Nov 12, 2026
21 checks passed
@zlareb1
zlareb1 deleted the feat/cell-router-lookup-cache branch November 12, 2026 00:51
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