Skip to content

feat(tenancy): MH9 cells, serve only this deployment's KY_CELLS - #745

Queued
Yoshiofthewire wants to merge 2 commits into
mainfrom
feat/multihost-cells
Queued

Yoshiofthewire wants to merge 2 commits into
mainfrom
feat/multihost-cells

Conversation

@Yoshiofthewire

Copy link
Copy Markdown
Member

In one line: A multi-tenant KyPost (still not startable) now serves only the KyIdentity cells listed in KY_CELLS. An org of another cell gets the same answer as an unknown org everywhere, and its directory events are refused before anything is written.

What changed

  • KY_CELLS:
    • In multi mode it is required: 1 to 32 KyIdentity home_region slugs, sorted, none twice. Single mode refuses it, and no refusal echoes the value.
    • It is a shared replica setting, compared only when set, so single-tenant fingerprints stay byte for byte the same. A replica serving other cells is refused at start.
    • The hosted and MX compose profiles now require it.
  • The orgs poll is the one choke point. An org whose home_region is not one of the server's cells goes to a new foreign_orgs(id, home_region, revision) table and never into orgs. The staff org is the exception: it is in every cell. So every lookup misses it exactly as it misses an uncached org:
    • browser sign-in and device sign-on;
    • session, device, CardDAV and MCP credentials;
    • sending;
    • receiving bind (451);
    • imports;
    • storage reports;
    • the purge;
    • staff selection;
    • peer calls (no_user).
  • Directory events:
    • An event for an org of another cell gets 422, permanent, so KyIdentity stops retrying.
    • An event for an org no poll has listed yet gets 503 and KyIdentity retries. This replaces "an uncached org's event applies": with cells, that org could be another cell's new org.
    • Neither writes anything.
  • Cell-scoped object prefix: each own org's home_region is stored. The spec fixes MH11's keys as cells/<home_region>/bodies/<org>/…. KyPost has no object storage yet, so the code that uses the prefix lands with MH11.
  • Bumps ky-primitives to the commit KyCalendar uses (b5f5853), for suitedir.Org.HomeRegion.

Review this

Checked: see the verification comment for the run on this head.

  • The two-host test TestCellsServeOnlyTheirOwnOrgs passes on SQLite and PostgreSQL 18.
  • So do TestHostedBindForeignOrg, TestForeignOrg, TestCells, TestCellsAreSharedOnlyWhenSet and TestReplicaWithOtherCellsRefused (PostgreSQL), and the existing org, tenancy, restore and cross-org tests.

Not checked:

  • Production wiring of Server.cells. Like Server.tenancy and staffOrg, it is test-only until K PR 7 wires multi startup.
  • The masked relay region code table and the DR runbook are not built. They are needed before a second cell opens, not before K PR 7.

Decided for you:

  • Directory events for another cell get a permanent 422 (as the MH9 step says) rather than the unknown-org answer. Every customer-facing way in does get the unknown-org answer.
  • Uncached-org events now wait for the next poll.

You need to: nothing. multi stays refused in release builds.

Detail
  • As built: multi-host spec, "MH9 cells as built (2026-11-25)"; tenancy spec (Phased build plan); backend/AGENTS.md (Cells); docs/CONFIGURATION.md; CHANGELOG.
  • ApplyOrg refuses to re-cache an org whose foreign_orgs revision is newer. ApplyForeignOrg drops a cached row, but never a deleted tombstone, after its members' sessions are revoked as for a suspension. OrgCursor counts foreign_orgs. ForgetRestored clears it.
  • Every step that changes two statements fails closed: in between, the org reads as uncached.
  • TestTenancySyncAppliesEventsForAnUncachedOrg became TestTenancySyncWaitsForAnUncachedOrg.
  • Test fixtures: useTenancy serves testCell, and listed() homes orgs there.
  • Tests that set KYPOST_TENANCY=multi in the environment also set KY_CELLS.

🤖 Generated with Claude Code

KY_CELLS lists the KyIdentity home regions a multi-tenant deployment
serves (KyIdentity tenancy spec, Cells, C1-C5): required in multi mode,
refused in single mode, and a shared replica setting only when set, so
single-tenant fingerprints are unchanged.

The orgs poll is the one place a cell is decided: an org of another cell
goes to foreign_orgs (ID, cell and revision) and never into the orgs
cache, so sign-in, device sign-on, every credential, receiving, imports,
storage reports and peer calls answer it exactly as an uncached org.
Directory events for such an org are refused for good (422), and those
for an org no poll has listed yet for now (503), before any write.
orgs.home_region records each own org's cell for MH11's cell-scoped
object keys (cells/<home_region>/bodies/...).

Bumps ky-primitives for suitedir.Org.HomeRegion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Yoshiofthewire commented Nov 26, 2026 •

Copy link
Copy Markdown
Member Author

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪

🧪 PR contains tests

⚡ No major issues detected


Advisory only: this comment never gates the pull request.
gpt-6.1-sol using pr-agent on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 26, 2026 •

Copy link
Copy Markdown
Member Author

Security review - cleared

Detail withheld: this repository is public, and posting an unfixed finding here would be public disclosure. The full report was posted to the hand-off board at https://myslop.urlxl.us/f/pr-reviewer-busnes-app-kypost-server-745, where it is readable by the operator and expires seven days after the last post.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 26, 2026 •

Copy link
Copy Markdown
Member Author

Autonomous review - 1/1 personas cleared

  • security: cleared

Merging remains a human decision; this bot never approves.


gpt-6.1-sol using security-audit on behalf of Yoshi

…mode

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

Verification for 8813136 (code) plus 847f2d2 (a test-only fix). All runs were in place on Major; the PostgreSQL runs used my own throwaway postgres:18.7-trixie (CI's digest, --locale=C, max_connections=400).

  • Mutations: 14/14 killed on PostgreSQL:
    • the poll caching other cells
    • the poll's staff exemption
    • the sync foreign refusal
    • the sync uncached refusal
    • a foreign row kept in orgs
    • the cursor ignoring foreign orgs
    • a restore keeping foreign orgs
    • an own org leaving its foreign row
    • a stale own answer over a foreign one
    • single mode taking KY_CELLS
    • multi mode without KY_CELLS
    • a duplicate cell
    • the fingerprint without cells
    • cells always fingerprinted
  • SQLite: go test -race -count=1 -p 2 ./... passed every package. go vet, gofmt, golangci-lint (0 issues) and deadcode are clean.
  • PostgreSQL: -race on CI's stores list plus api passed every package except one app test that my fixture broke (TestTableBackupCLISelectsDocumentsBeforeService returned to single mode with KY_CELLS still set). 847f2d2 fixes it, and it passes on PostgreSQL.
  • Flake: on the app rerun, TestLeasedImportPurgeFence failed once under load. It passed alone 3/3, and it passed in the full PostgreSQL run before that. It is unrelated to cells: it goes through LookupOrg, whose semantics are unchanged.
  • Two-host test: TestCellsServeOnlyTheirOwnOrgs passed on SQLite and PostgreSQL.

@Yoshiofthewire
Yoshiofthewire added this pull request to the merge queue Nov 26, 2026
Any commits made after this event will not be merged.
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