From 6cf21c574b7096a49fd71d638999374d562a3e8c Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Nov 2026 21:42:20 +0000 Subject: [PATCH 1/6] feat(cli)!: a declared multi-replica start on the redis cluster driver refuses to mint its own sign-in secret Claude-Session: https://claude.ai/code/session_01ADHkmNwSCrFC9AxLfZsBxf Co-authored-by: Claude --- packages/cli/package.json | 1 + .../start-deployment-durability.test.ts | 35 +++++++++++++ packages/cli/src/commands/start.ts | 51 ++++++++++++++++++ ...-deployment-durability.integration.test.ts | 52 +++++++++++++++++++ pnpm-lock.yaml | 3 ++ 5 files changed, 142 insertions(+) diff --git a/packages/cli/package.json b/packages/cli/package.json index e0a40fd215b..f53fa0c7c13 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -90,6 +90,7 @@ "@objectstack/service-analytics": "workspace:*", "@objectstack/service-automation": "workspace:*", "@objectstack/service-cache": "workspace:*", + "@objectstack/service-cluster": "workspace:*", "@objectstack/service-datasource": "workspace:*", "@objectstack/service-job": "workspace:*", "@objectstack/service-mailbox": "workspace:*", diff --git a/packages/cli/src/commands/start-deployment-durability.test.ts b/packages/cli/src/commands/start-deployment-durability.test.ts index c8e8c4340c1..dd8bfd9512e 100644 --- a/packages/cli/src/commands/start-deployment-durability.test.ts +++ b/packages/cli/src/commands/start-deployment-durability.test.ts @@ -10,14 +10,17 @@ import { describe, expect, it } from 'vitest'; import { DURABILITY_CHECK_ENV, INTERNAL_DEPLOYMENT_FINDINGS_ENV, + MULTI_REPLICA_AUTH_SECRET_REFUSAL, formatDurabilityBootBlock, formatDurabilityRefusal, isDefaultedDatabase, missingDurableVariables, readDurabilityCheckSignal, + refusesMintedAuthSecret, sqliteFileOf, writeDeploymentFindingsChannel, } from './start.js'; +import { declaresMultiNode } from '@objectstack/service-cluster'; describe('the image switch', () => { it.each([ @@ -137,3 +140,35 @@ describe('the channel to the server process', () => { expect(INTERNAL_DEPLOYMENT_FINDINGS_ENV in env).toBe(false); }); }); + +describe('a declared multi-replica start on the redis cluster driver mints no sign-in secret of its own', () => { + // The facts as the call site reads them: the declaration through the + // split-brain guard's own reader, the driver as `OS_CLUSTER_DRIVER` spells it. + const facts = (env: Record) => ({ + multiNode: declaresMultiNode(env), + clusterDriver: env.OS_CLUSTER_DRIVER, + }); + + it('refuses when several replicas are declared over the redis driver, by either declaration', () => { + expect(refusesMintedAuthSecret(facts({ OS_CLUSTER_REPLICAS: '3', OS_CLUSTER_DRIVER: 'redis' }))).toBe(true); + expect(refusesMintedAuthSecret(facts({ OS_EXPECT_MULTI_NODE: 'true', OS_CLUSTER_DRIVER: ' redis ' }))).toBe(true); + }); + + it('CONTROL: a single node keeps minting, on the redis driver too', () => { + expect(refusesMintedAuthSecret(facts({}))).toBe(false); + expect(refusesMintedAuthSecret(facts({ OS_CLUSTER_DRIVER: 'redis' }))).toBe(false); + expect(refusesMintedAuthSecret(facts({ OS_CLUSTER_REPLICAS: '1', OS_CLUSTER_DRIVER: 'redis' }))).toBe(false); + }); + + it('CONTROL: replicas declared over the memory driver, or none named, keep the boot they had', () => { + expect(refusesMintedAuthSecret(facts({ OS_CLUSTER_REPLICAS: '3', OS_CLUSTER_DRIVER: 'memory' }))).toBe(false); + expect(refusesMintedAuthSecret(facts({ OS_CLUSTER_REPLICAS: '3' }))).toBe(false); + }); + + it('the refusal is one line naming OS_AUTH_SECRET and how to generate it, and carries no value', () => { + expect(MULTI_REPLICA_AUTH_SECRET_REFUSAL).not.toContain('\n'); + expect(MULTI_REPLICA_AUTH_SECRET_REFUSAL).toMatch(/^\[auth\] Refusing to start: several replicas are declared/); + expect(MULTI_REPLICA_AUTH_SECRET_REFUSAL).toContain('but OS_AUTH_SECRET is not set'); + expect(MULTI_REPLICA_AUTH_SECRET_REFUSAL).toContain('set the same value on every replica, e.g. OS_AUTH_SECRET=$(openssl rand -hex 32)'); + }); +}); diff --git a/packages/cli/src/commands/start.ts b/packages/cli/src/commands/start.ts index fb478344f74..85743757cd5 100644 --- a/packages/cli/src/commands/start.ts +++ b/packages/cli/src/commands/start.ts @@ -364,6 +364,25 @@ export default class Start extends Command { } } + // ── A declared multi-replica deployment shares ONE sign-in secret ────── + // Minting one below is right for a single node and wrong for replicas: + // each mints its own into its own home, and a session signed on one is + // refused on the others. Asked only when the operator set none, and before + // anything is generated, so the refusal writes no secret. The declaration + // and the driver are the pair `planCacheAdapter` (`@objectstack/service-cache`) + // switches on: `declaresMultiNode`, read from the module that owns it, and + // the driver the `serve` child composes its cluster service from. + if (operatorAuthSecret === undefined || operatorAuthSecret.trim().length === 0) { + const { declaresMultiNode } = await import('@objectstack/service-cluster'); + if (refusesMintedAuthSecret({ + multiNode: declaresMultiNode(process.env), + clusterDriver: process.env.OS_CLUSTER_DRIVER, + })) { + process.stderr.write(`${MULTI_REPLICA_AUTH_SECRET_REFUSAL}\n`); + process.exit(1); + } + } + const persistedAuthSecret = operatorAuthSecret === undefined ? readOrCreateAuthSecret(homeDir) : undefined; const authSecret = persistedAuthSecret ? persistedAuthSecret.secret : operatorAuthSecret; @@ -674,6 +693,38 @@ export async function resolveStartDatabase(opts: { }); } +/** + * The cluster driver whose replicas share state, so whose deployment must + * share one sign-in secret too: the driver `planCacheAdapter` + * (`@objectstack/service-cache`) shares one cache over. + */ +const SHARED_CLUSTER_DRIVER = 'redis'; + +/** + * Whether `os start` refuses to mint its own sign-in secret: the deployment + * declares several replicas (`declaresMultiNode` from + * `@objectstack/service-cluster`, the split-brain guard's reading) over the + * redis cluster driver. Both are required (cloud ADR-0010 path A): a single + * node keeps minting into `/auth-secret`, and a declaration over any + * other driver keeps today's boot. The caller asks only when the operator set + * no secret. `clusterDriver` is `OS_CLUSTER_DRIVER` as written, trimmed the way + * the `serve` child trims it before composing the cluster service. + */ +export function refusesMintedAuthSecret(facts: { multiNode: boolean; clusterDriver: string | undefined }): boolean { + return facts.multiNode && facts.clusterDriver?.trim() === SHARED_CLUSTER_DRIVER; +} + +/** + * The refusal, one line in the data key's shape (`LocalCryptoProvider`): what + * is missing, what minting one would break, and how to generate the value. + * It names the variable and never a value. + */ +export const MULTI_REPLICA_AUTH_SECRET_REFUSAL = + '[auth] Refusing to start: several replicas are declared (OS_EXPECT_MULTI_NODE / OS_CLUSTER_REPLICAS>1) ' + + 'over the redis cluster driver, but OS_AUTH_SECRET is not set — each replica would mint its own sign-in ' + + 'secret, and a session signed on one would be refused on the others. Fix: generate one and set the same ' + + 'value on every replica, e.g. OS_AUTH_SECRET=$(openssl rand -hex 32)'; + /** * Read the persisted AUTH_SECRET from `/auth-secret`, or generate * one on first run and persist it so subsequent restarts keep existing diff --git a/packages/cli/test/start-deployment-durability.integration.test.ts b/packages/cli/test/start-deployment-durability.integration.test.ts index 5f899f6da6c..86c232e09c0 100644 --- a/packages/cli/test/start-deployment-durability.integration.test.ts +++ b/packages/cli/test/start-deployment-durability.integration.test.ts @@ -106,6 +106,10 @@ function baseEnv(home: string, over: Record = {}): R AUTH_SECRET: undefined, BETTER_AUTH_SECRET: undefined, OS_CLUSTER_DRIVER: undefined, + OS_EXPECT_MULTI_NODE: undefined, + OS_CLUSTER_REPLICAS: undefined, + OS_ALLOW_MEMORY_CLUSTER_MULTINODE: undefined, + OS_REDIS_URL: undefined, OS_MODE: undefined, OS_PORT: undefined, PORT: undefined, @@ -292,6 +296,54 @@ describe('#30120 — with the image switch on, a start missing its settings refu }); }); +// --------------------------------------------------------------------------- +// 1b — several replicas declared over the redis cluster driver: no secret of its own +// --------------------------------------------------------------------------- + +describe('#31600 — a declared multi-replica start on the redis cluster driver mints no sign-in secret of its own', () => { + // The data key is set on every leg, so the only thing each leg varies is the + // sign-in secret and the topology. No leg needs a Redis: the door is asked in + // `os start` itself, before the `serve` child composes any cluster driver. + const start = (over: Record) => { + const home = tmp('os-31600-home-'); + const cwd = tmp('os-31600-cwd-'); + const run = spawnSync(process.execPath, [CLI, 'start', '--port', KERNEL_ASSIGNED_PORT], { + cwd, + env: childEnv({ ...baseEnv(home, { OS_SECRET_KEY: secret(), ...over }), NODE_ENV: undefined }), + encoding: 'utf8', + timeout: 120_000, + }); + const minted = [...filesUnder(home), ...filesUnder(cwd)].filter((f) => /(^|\/)auth-secret$/.test(f)); + return { run, minted, out: `${run.stdout}\n${run.stderr}` }; + }; + const REFUSAL = /^\[auth\] Refusing to start: several replicas are declared \(OS_EXPECT_MULTI_NODE \/ OS_CLUSTER_REPLICAS>1\) over the redis cluster driver, but OS_AUTH_SECRET is not set/m; + + it('OS_AUTH_SECRET unset: exit 1 on the one line, before any secret is written', () => { + const { run, minted, out } = start({ OS_CLUSTER_REPLICAS: '3', OS_CLUSTER_DRIVER: 'redis' }); + expect(run.status, out).toBe(1); + expect(run.stderr).toMatch(REFUSAL); + expect(run.stderr).toContain('e.g. OS_AUTH_SECRET=$(openssl rand -hex 32)'); + expect(out).not.toMatch(READY); + expect(minted, out).toEqual([]); + }); + + it('OS_AUTH_SECRET set: this door passes, and nothing is minted', () => { + const { minted, out } = start({ OS_EXPECT_MULTI_NODE: 'true', OS_CLUSTER_DRIVER: 'redis', OS_AUTH_SECRET: secret() }); + expect(out).not.toMatch(REFUSAL); + // The banner is printed after the door: the start went on to its child. + expect(out).toMatch(/Database/); + expect(minted, out).toEqual([]); + }); + + it('CONTROL: replicas declared over the memory driver mint a secret exactly as before', () => { + // The child then meets the split-brain guard, today's refusal for this + // topology; the secret is minted in `os start` before that, as it always was. + const { minted, out } = start({ OS_CLUSTER_REPLICAS: '3', OS_CLUSTER_DRIVER: 'memory' }); + expect(out).not.toMatch(REFUSAL); + expect(minted, out).toEqual([join('.objectstack', 'auth-secret')]); + }); +}); + // --------------------------------------------------------------------------- // 2 — an explicit file: passes // --------------------------------------------------------------------------- diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2ae1a87a2f3..84e2a3957ca 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -649,6 +649,9 @@ importers: '@objectstack/service-cache': specifier: workspace:* version: link:../services/service-cache + '@objectstack/service-cluster': + specifier: workspace:* + version: link:../services/service-cluster '@objectstack/service-datasource': specifier: workspace:* version: link:../services/service-datasource From fd977a59349a42c8bc296face941e48233680a7f Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Nov 2026 21:48:23 +0000 Subject: [PATCH 2/6] test(cli): pin the multi-replica auth-secret refusal; add the changeset Claude-Session: https://claude.ai/code/session_01ADHkmNwSCrFC9AxLfZsBxf Co-authored-by: Claude --- .../31600-multi-replica-auth-secret-refusal.md | 16 ++++++++++++++++ ...art-deployment-durability.integration.test.ts | 8 +++++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 .changeset/31600-multi-replica-auth-secret-refusal.md diff --git a/.changeset/31600-multi-replica-auth-secret-refusal.md b/.changeset/31600-multi-replica-auth-secret-refusal.md new file mode 100644 index 00000000000..648cdec1612 --- /dev/null +++ b/.changeset/31600-multi-replica-auth-secret-refusal.md @@ -0,0 +1,16 @@ +--- +'@objectstack/cli': patch +--- + +feat(cli)!: a declared multi-replica `os start` on the redis cluster driver refuses to boot without `OS_AUTH_SECRET`, instead of minting a sign-in secret of its own on each replica + +Clause-②: no (narrowing) +Metadata-protocol: none + + + +**BREAKING** for a deployment that declares several replicas (`OS_EXPECT_MULTI_NODE=true` or `OS_CLUSTER_REPLICAS` above 1) over the redis cluster driver (`OS_CLUSTER_DRIVER=redis`) and sets no `OS_AUTH_SECRET`. `os start` used to generate a sign-in secret into each replica's own `/auth-secret`, so a session signed on one replica was refused on the others. It now exits 1 before generating anything, with one line naming `OS_AUTH_SECRET` and how to generate it. + +The fix: generate one value and set the same `OS_AUTH_SECRET` on every replica, e.g. `OS_AUTH_SECRET=$(openssl rand -hex 32)`. A deployment that ran on a generated secret keeps its users' sessions by setting `OS_AUTH_SECRET` to the contents of the `auth-secret` file one replica already holds. + +Unchanged: a single node (no replica declaration) keeps generating and reusing `/auth-secret` exactly as before, on any cluster driver; a replica declaration over any other cluster driver keeps its current boot; and an `OS_AUTH_SECRET` (or its legacy names, or `--auth-secret`) set on every replica boots as before. diff --git a/packages/cli/test/start-deployment-durability.integration.test.ts b/packages/cli/test/start-deployment-durability.integration.test.ts index 86c232e09c0..e1dae37e7fa 100644 --- a/packages/cli/test/start-deployment-durability.integration.test.ts +++ b/packages/cli/test/start-deployment-durability.integration.test.ts @@ -1,5 +1,5 @@ // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. -// test-budget: 40 — three refusals that exit before any server starts, then two real `os start` boots (one on explicit settings; one on the defaults, which also signs up an owner, creates a member and reads the notice as each); the file read 27.6 s on a shared local box (no CI reading yet) x 1.25, rounded up to the next 10 s +// test-budget: 40 — six starts that exit before any server answers (three image refusals; the multi-replica refusal, its pass and its memory-driver control), then two real `os start` boots (one on explicit settings; one on the defaults, which also signs up an owner, creates a member and reads the notice as each); the file read 27.6 s on a shared local box (no CI reading yet) x 1.25, rounded up to the next 10 s, and 26.9 s with the three multi-replica starts added /** * #30120, ruling A3 (record 6634240777) — the official image refuses to start @@ -29,6 +29,12 @@ * member is refused `403`, and neither the public auth config nor the * runtime config carries any of it. * + * And, beside the image's refusal (#31600): a start that declares several + * replicas over the redis cluster driver and sets no `OS_AUTH_SECRET` exits 1 + * on one line naming it, before it generates a secret; with the secret set it + * passes, and replicas declared over the memory driver still generate one. + * The single-node default keeps generating its own: leg 3 reads that file. + * * The hide's audit row and the route's other refusals are pinned beside the * routes (`service-settings` `deployment-notice.routes.test.ts`). * From a89df9b2b7ec6d67a4ad06cee0b3187285d3f7b0 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Nov 2026 21:57:23 +0000 Subject: [PATCH 3/6] docs(deployment): os start generates no sign-in secret on a declared multi-replica redis deployment Claude-Session: https://claude.ai/code/session_01ADHkmNwSCrFC9AxLfZsBxf Co-authored-by: Claude --- content/docs/deployment/cli.mdx | 9 +++++++-- content/docs/deployment/self-hosting.mdx | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/content/docs/deployment/cli.mdx b/content/docs/deployment/cli.mdx index 807ab6f1873..9bb05f42880 100644 --- a/content/docs/deployment/cli.mdx +++ b/content/docs/deployment/cli.mdx @@ -566,7 +566,7 @@ os start | `-d, --database ` | `OS_DATABASE_URL` | `file:…` / `:memory:` / `libsql://` / `postgres://` / `mongodb://` | | `--database-driver ` | `OS_DATABASE_DRIVER` | Force `sqlite` \| `sqlite-wasm` \| `turso` \| `postgres` \| `mysql` \| `mongodb` when the URL is ambiguous | | `--database-auth-token ` | `OS_DATABASE_AUTH_TOKEN` | Auth token for libsql/Turso | -| `--auth-secret ` | `OS_AUTH_SECRET` / `AUTH_SECRET` | Secret for `@objectstack/plugin-auth`. If neither the flag nor the env var is set, `os start` **auto-generates one** and persists it at `/auth-secret` | +| `--auth-secret ` | `OS_AUTH_SECRET` / `AUTH_SECRET` | Secret for `@objectstack/plugin-auth`. If neither the flag nor the env var is set, `os start` **auto-generates one** and persists it at `/auth-secret` — except on a deployment that declares several replicas (`OS_EXPECT_MULTI_NODE=true` / `OS_CLUSTER_REPLICAS` > 1) over the redis cluster driver, where it refuses to start and names the variable | | `--home ` | `OS_HOME` | Home directory for persistent state (default `/.objectstack` when an `objectstack.config.ts` is present, otherwise `~/.objectstack`) | | `--environment-id ` | `OS_ENVIRONMENT_ID` | Environment identifier (default `env_local`) | | `-p, --port ` | `OS_PORT` / `PORT` | Listen port (default `3000`). **Production fails loudly if the port is busy** — see note below. | @@ -618,7 +618,12 @@ as the project's **default** datasource it is refused at boot the same way. `AUTH_SECRET` env > a secret **auto-generated and persisted** at `/auth-secret` on first run — so `/api/v1/auth/*` (login/register) and the Console's login flow work out of the box, without any manual secret provisioning. Set the env var (or flag) -explicitly when you deploy across multiple nodes or want to rotate the secret. +explicitly when you deploy across multiple nodes or want to rotate the secret: the same +value on every replica. A start that declares several replicas +(`OS_EXPECT_MULTI_NODE=true` / `OS_CLUSTER_REPLICAS` > 1) over the redis cluster driver +does not generate one: without the variable it exits 1 on one line naming +`OS_AUTH_SECRET` and how to generate it (`openssl rand -hex 32`), because each replica +would otherwise mint its own and a session signed on one would be refused on the others. **`os start` vs `os serve`:** `os serve` boots from `objectstack.config.ts` (TypeScript source). diff --git a/content/docs/deployment/self-hosting.mdx b/content/docs/deployment/self-hosting.mdx index 75ac9a1dabb..86f881e9ec5 100644 --- a/content/docs/deployment/self-hosting.mdx +++ b/content/docs/deployment/self-hosting.mdx @@ -34,7 +34,7 @@ workable default: | Variable | Why it must be set | |:---|:---| | `OS_DATABASE_URL` | Without it, data lands in a SQLite file under the ObjectStack home directory (`~/.objectstack`, or `/.objectstack` next to a project config) — fine for one box, wrong for containers. Use `postgres://…`, `mysql://…`, `mongodb://…`, `libsql://…`, or a mounted `file:…` path (`postgres://…`'s driver is an **optional** package too — `npm install pg`, or the boot fails loudly rather than degrading to SQLite; `libsql://` / Turso is inferred, but its driver is an **optional** package — `npm install @objectstack/driver-turso`, or the boot fails loudly rather than degrading to SQLite; see [Drivers](/docs/data-modeling/drivers)). `mysql://…` is a supported deployment target that carries three dialect caveats — two of them integrity guarantees MySQL cannot enforce at the database — see [Drivers → MySQL dialect caveats](/docs/data-modeling/drivers#mysql-dialect-caveats) before choosing it; its driver is likewise an **optional** package — `npm install mysql2`, or the boot fails loudly rather than degrading to SQLite. `mongodb://…` is **single-tenant only**: the MongoDB driver has no row-level tenant isolation and refuses to boot unless the tenancy posture is `single` — see [Drivers → Multi-tenancy](/docs/data-modeling/drivers#multi-tenancy-not-supported). | -| `OS_AUTH_SECRET` | Session secret for the auth plugin (`AUTH_SECRET` is the legacy alias). Without it, `os start` generates one and keeps it in `auth-secret` under the ObjectStack home directory, reused on restart: lose that file (a replaced container) and everyone is signed out. | +| `OS_AUTH_SECRET` | Session secret for the auth plugin (`AUTH_SECRET` is the legacy alias). Without it, `os start` generates one and keeps it in `auth-secret` under the ObjectStack home directory, reused on restart: lose that file (a replaced container) and everyone is signed out. Several replicas declared over the redis cluster driver need one value set on every replica: there `os start` refuses to generate one. | | `OS_SECRET_KEY` | 32-byte master key encrypting every stored secret (`openssl rand -hex 32`). On a container's ephemeral filesystem the auto-minted key is **lost on restart**, making previously-encrypted secrets undecryptable. | | `OS_PORT` | `os start` **fails loudly** if the port is busy (it never auto-shifts like `os dev`). Pin it and keep your reverse-proxy upstream in sync. | From c99911487fb0cec4176897259b160a9a55c1c6c4 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Nov 2026 22:20:08 +0000 Subject: [PATCH 4/6] fix(cli): read the multi-replica predicate through cloud-connection, not a new cluster dependency The CLI declares no cluster package of its own: those ship with the host app. Claude-Session: https://claude.ai/code/session_01ADHkmNwSCrFC9AxLfZsBxf Co-authored-by: Claude --- packages/cli/package.json | 1 - .../start-deployment-durability.test.ts | 30 ++++------ packages/cli/src/commands/start.ts | 55 +++++++++---------- pnpm-lock.yaml | 3 - 4 files changed, 37 insertions(+), 52 deletions(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index f53fa0c7c13..e0a40fd215b 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -90,7 +90,6 @@ "@objectstack/service-analytics": "workspace:*", "@objectstack/service-automation": "workspace:*", "@objectstack/service-cache": "workspace:*", - "@objectstack/service-cluster": "workspace:*", "@objectstack/service-datasource": "workspace:*", "@objectstack/service-job": "workspace:*", "@objectstack/service-mailbox": "workspace:*", diff --git a/packages/cli/src/commands/start-deployment-durability.test.ts b/packages/cli/src/commands/start-deployment-durability.test.ts index dd8bfd9512e..d29226cce23 100644 --- a/packages/cli/src/commands/start-deployment-durability.test.ts +++ b/packages/cli/src/commands/start-deployment-durability.test.ts @@ -16,11 +16,10 @@ import { isDefaultedDatabase, missingDurableVariables, readDurabilityCheckSignal, - refusesMintedAuthSecret, + declaresReplicasSharingState, sqliteFileOf, writeDeploymentFindingsChannel, } from './start.js'; -import { declaresMultiNode } from '@objectstack/service-cluster'; describe('the image switch', () => { it.each([ @@ -142,27 +141,22 @@ describe('the channel to the server process', () => { }); describe('a declared multi-replica start on the redis cluster driver mints no sign-in secret of its own', () => { - // The facts as the call site reads them: the declaration through the - // split-brain guard's own reader, the driver as `OS_CLUSTER_DRIVER` spells it. - const facts = (env: Record) => ({ - multiNode: declaresMultiNode(env), - clusterDriver: env.OS_CLUSTER_DRIVER, - }); + const asks = (env: Record) => declaresReplicasSharingState(env as NodeJS.ProcessEnv); - it('refuses when several replicas are declared over the redis driver, by either declaration', () => { - expect(refusesMintedAuthSecret(facts({ OS_CLUSTER_REPLICAS: '3', OS_CLUSTER_DRIVER: 'redis' }))).toBe(true); - expect(refusesMintedAuthSecret(facts({ OS_EXPECT_MULTI_NODE: 'true', OS_CLUSTER_DRIVER: ' redis ' }))).toBe(true); + it('refuses when several replicas are declared over the redis driver, by either declaration', async () => { + expect(await asks({ OS_CLUSTER_REPLICAS: '3', OS_CLUSTER_DRIVER: 'redis' })).toBe(true); + expect(await asks({ OS_EXPECT_MULTI_NODE: 'true', OS_CLUSTER_DRIVER: ' redis ' })).toBe(true); }); - it('CONTROL: a single node keeps minting, on the redis driver too', () => { - expect(refusesMintedAuthSecret(facts({}))).toBe(false); - expect(refusesMintedAuthSecret(facts({ OS_CLUSTER_DRIVER: 'redis' }))).toBe(false); - expect(refusesMintedAuthSecret(facts({ OS_CLUSTER_REPLICAS: '1', OS_CLUSTER_DRIVER: 'redis' }))).toBe(false); + it('CONTROL: a single node keeps minting, on the redis driver too', async () => { + expect(await asks({})).toBe(false); + expect(await asks({ OS_CLUSTER_DRIVER: 'redis' })).toBe(false); + expect(await asks({ OS_CLUSTER_REPLICAS: '1', OS_CLUSTER_DRIVER: 'redis' })).toBe(false); }); - it('CONTROL: replicas declared over the memory driver, or none named, keep the boot they had', () => { - expect(refusesMintedAuthSecret(facts({ OS_CLUSTER_REPLICAS: '3', OS_CLUSTER_DRIVER: 'memory' }))).toBe(false); - expect(refusesMintedAuthSecret(facts({ OS_CLUSTER_REPLICAS: '3' }))).toBe(false); + it('CONTROL: replicas declared over the memory driver, or none named, keep the boot they had', async () => { + expect(await asks({ OS_CLUSTER_REPLICAS: '3', OS_CLUSTER_DRIVER: 'memory' })).toBe(false); + expect(await asks({ OS_CLUSTER_REPLICAS: '3' })).toBe(false); }); it('the refusal is one line naming OS_AUTH_SECRET and how to generate it, and carries no value', () => { diff --git a/packages/cli/src/commands/start.ts b/packages/cli/src/commands/start.ts index 85743757cd5..e9d80387506 100644 --- a/packages/cli/src/commands/start.ts +++ b/packages/cli/src/commands/start.ts @@ -368,19 +368,13 @@ export default class Start extends Command { // Minting one below is right for a single node and wrong for replicas: // each mints its own into its own home, and a session signed on one is // refused on the others. Asked only when the operator set none, and before - // anything is generated, so the refusal writes no secret. The declaration - // and the driver are the pair `planCacheAdapter` (`@objectstack/service-cache`) - // switches on: `declaresMultiNode`, read from the module that owns it, and - // the driver the `serve` child composes its cluster service from. - if (operatorAuthSecret === undefined || operatorAuthSecret.trim().length === 0) { - const { declaresMultiNode } = await import('@objectstack/service-cluster'); - if (refusesMintedAuthSecret({ - multiNode: declaresMultiNode(process.env), - clusterDriver: process.env.OS_CLUSTER_DRIVER, - })) { - process.stderr.write(`${MULTI_REPLICA_AUTH_SECRET_REFUSAL}\n`); - process.exit(1); - } + // anything is generated, so the refusal writes no secret. + if ( + (operatorAuthSecret === undefined || operatorAuthSecret.trim().length === 0) + && await declaresReplicasSharingState(process.env) + ) { + process.stderr.write(`${MULTI_REPLICA_AUTH_SECRET_REFUSAL}\n`); + process.exit(1); } const persistedAuthSecret = operatorAuthSecret === undefined ? readOrCreateAuthSecret(homeDir) : undefined; @@ -694,24 +688,25 @@ export async function resolveStartDatabase(opts: { } /** - * The cluster driver whose replicas share state, so whose deployment must - * share one sign-in secret too: the driver `planCacheAdapter` - * (`@objectstack/service-cache`) shares one cache over. - */ -const SHARED_CLUSTER_DRIVER = 'redis'; - -/** - * Whether `os start` refuses to mint its own sign-in secret: the deployment - * declares several replicas (`declaresMultiNode` from - * `@objectstack/service-cluster`, the split-brain guard's reading) over the - * redis cluster driver. Both are required (cloud ADR-0010 path A): a single - * node keeps minting into `/auth-secret`, and a declaration over any - * other driver keeps today's boot. The caller asks only when the operator set - * no secret. `clusterDriver` is `OS_CLUSTER_DRIVER` as written, trimmed the way - * the `serve` child trims it before composing the cluster service. + * Whether this deployment runs replicas that share state, so must share one + * sign-in secret too: several replicas declared (`OS_EXPECT_MULTI_NODE=true` / + * `OS_CLUSTER_REPLICAS` > 1, the split-brain guard's `declaresMultiNode`) over + * the redis cluster driver. Both are required, the rule every multi-replica + * change keeps (cloud#3814 R3): a single node keeps minting into + * `/auth-secret`, and a declaration over any other driver keeps the boot + * it had. + * + * ⛔ Not a second copy of that rule. It is asked of the one pre-boot form that + * exists, `sharesCloudBindingCredential` (`OS_CLUSTER_DRIVER` in place of the + * cluster service's driver, trimmed as the `serve` child trims it before + * composing that service), from a package this command already declares. The + * CLI declares no cluster package of its own: those ship with the host app + * (`serve-cluster-host-resolution.test.ts` says why). Lazy, so oclif's + * import-every-command startup does not pay for it. */ -export function refusesMintedAuthSecret(facts: { multiNode: boolean; clusterDriver: string | undefined }): boolean { - return facts.multiNode && facts.clusterDriver?.trim() === SHARED_CLUSTER_DRIVER; +export async function declaresReplicasSharingState(env: NodeJS.ProcessEnv): Promise { + const { sharesCloudBindingCredential } = await import('@objectstack/cloud-connection'); + return sharesCloudBindingCredential(env, env.OS_CLUSTER_DRIVER); } /** diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 84e2a3957ca..2ae1a87a2f3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -649,9 +649,6 @@ importers: '@objectstack/service-cache': specifier: workspace:* version: link:../services/service-cache - '@objectstack/service-cluster': - specifier: workspace:* - version: link:../services/service-cluster '@objectstack/service-datasource': specifier: workspace:* version: link:../services/service-datasource From c96d6e73fe89495232d43fe25407c1fc4454e095 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Nov 2026 22:30:53 +0000 Subject: [PATCH 5/6] test(cli): pay the lazy loads start.ts reaches during collection Claude-Session: https://claude.ai/code/session_01ADHkmNwSCrFC9AxLfZsBxf Co-authored-by: Claude --- .../cli/src/commands/start-deployment-durability.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/cli/src/commands/start-deployment-durability.test.ts b/packages/cli/src/commands/start-deployment-durability.test.ts index d29226cce23..d0ec5cdae5e 100644 --- a/packages/cli/src/commands/start-deployment-durability.test.ts +++ b/packages/cli/src/commands/start-deployment-durability.test.ts @@ -7,6 +7,11 @@ */ import { describe, expect, it } from 'vitest'; +// Paid during collection, never inside a case's clock: `start.ts` loads these +// lazily, and `check:test-source-alias` reads every one it can reach. +import '@objectstack/cloud-connection'; +import '@objectstack/runtime'; +import '@objectstack/service-settings'; import { DURABILITY_CHECK_ENV, INTERNAL_DEPLOYMENT_FINDINGS_ENV, From dc48e89a52fb356ae914bc85585c4ebadc4e6781 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Nov 2026 23:41:16 +0000 Subject: [PATCH 6/6] test(cli): give the multi-replica os start legs the spawn's own timeout The two legs that reach the serve child read ~4 s locally, under vitest's default 5 s per test; on a loaded CI runner (Test Core 1/8 on c96d6e73) the memory-driver CONTROL leg timed out at 5000 ms. Each leg now carries the spawnSync bound (120 s) plus 10 s. Claude-Session: https://claude.ai/code/session_01ADHkmNwSCrFC9AxLfZsBxf Co-authored-by: Claude --- .../start-deployment-durability.integration.test.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/cli/test/start-deployment-durability.integration.test.ts b/packages/cli/test/start-deployment-durability.integration.test.ts index e1dae37e7fa..3b21a57be46 100644 --- a/packages/cli/test/start-deployment-durability.integration.test.ts +++ b/packages/cli/test/start-deployment-durability.integration.test.ts @@ -310,6 +310,11 @@ describe('#31600 — a declared multi-replica start on the redis cluster driver // The data key is set on every leg, so the only thing each leg varies is the // sign-in secret and the topology. No leg needs a Redis: the door is asked in // `os start` itself, before the `serve` child composes any cluster driver. + // Each leg is one synchronous `os start`, bounded by the spawn's own 120 s; + // the two that reach the `serve` child read ~4 s locally, past vitest's + // default 5 s per test on a loaded runner, so the leg carries the spawn's bound. + const SPAWN_TIMEOUT_MS = 120_000; + const LEG_TIMEOUT_MS = SPAWN_TIMEOUT_MS + 10_000; const start = (over: Record) => { const home = tmp('os-31600-home-'); const cwd = tmp('os-31600-cwd-'); @@ -317,7 +322,7 @@ describe('#31600 — a declared multi-replica start on the redis cluster driver cwd, env: childEnv({ ...baseEnv(home, { OS_SECRET_KEY: secret(), ...over }), NODE_ENV: undefined }), encoding: 'utf8', - timeout: 120_000, + timeout: SPAWN_TIMEOUT_MS, }); const minted = [...filesUnder(home), ...filesUnder(cwd)].filter((f) => /(^|\/)auth-secret$/.test(f)); return { run, minted, out: `${run.stdout}\n${run.stderr}` }; @@ -331,7 +336,7 @@ describe('#31600 — a declared multi-replica start on the redis cluster driver expect(run.stderr).toContain('e.g. OS_AUTH_SECRET=$(openssl rand -hex 32)'); expect(out).not.toMatch(READY); expect(minted, out).toEqual([]); - }); + }, LEG_TIMEOUT_MS); it('OS_AUTH_SECRET set: this door passes, and nothing is minted', () => { const { minted, out } = start({ OS_EXPECT_MULTI_NODE: 'true', OS_CLUSTER_DRIVER: 'redis', OS_AUTH_SECRET: secret() }); @@ -339,7 +344,7 @@ describe('#31600 — a declared multi-replica start on the redis cluster driver // The banner is printed after the door: the start went on to its child. expect(out).toMatch(/Database/); expect(minted, out).toEqual([]); - }); + }, LEG_TIMEOUT_MS); it('CONTROL: replicas declared over the memory driver mint a secret exactly as before', () => { // The child then meets the split-brain guard, today's refusal for this @@ -347,7 +352,7 @@ describe('#31600 — a declared multi-replica start on the redis cluster driver const { minted, out } = start({ OS_CLUSTER_REPLICAS: '3', OS_CLUSTER_DRIVER: 'memory' }); expect(out).not.toMatch(REFUSAL); expect(minted, out).toEqual([join('.objectstack', 'auth-secret')]); - }); + }, LEG_TIMEOUT_MS); }); // ---------------------------------------------------------------------------