You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2b752aa
Browse filesBrowse the repository at this point in the historyBrowse files
fix(cli)!: os serve asks the multi-node gate about a topology declared by OS_EXPECT_MULTI_NODE=true (#31750)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi98pnQTATbhdKpMadAsFvNFN)_Fixes#31719
Clause-②: no (narrowing)
Metadata-protocol: none
## 维护者速读
- 改了什么:`os serve` 问多节点门禁时,先用 `declaresMultiNode` 判断是否声明了多节点(两种写法都认);只写
`OS_EXPECT_MULTI_NODE=true`、没给副本数时,按 2
个节点去问门禁。容量受限的门禁提示在这种“没给数量”的情况下不再编造副本数,改为点名
`OS_EXPECT_MULTI_NODE=true`;文档里“门禁拒绝只会降级、不会失败”的错误说法一并改正。
- 为什么改:以前门禁只看 `OS_CLUSTER_REPLICAS`,只写 `OS_EXPECT_MULTI_NODE=true`
的部署被当成单节点放行,开源版没有门禁也能跑多节点;同一拓扑换一种写法就被拒。
- 风险与回滚:这是收紧——只写
`OS_EXPECT_MULTI_NODE=true`、用远程集群驱动、又没注册门禁的部署,升级后启动会被拒。回滚就是回退这一个提交。
- 先看:`packages/cli/src/commands/serve.ts` 门禁调用那几行(`__countUnknown` /
`__requestedNodes`)和
`formatMultiNodeCapAdvisory`;`packages/cli/test/serve-multi-node-gate-declaration.integration.test.ts`。
- 两分钟验证:`pnpm --filter @objectstack/cli exec vitest run --project
integration
test/serve-multi-node-gate-declaration.integration.test.ts`,预期 4 个用例全过。
- 需要你做的:无,席位落地。
## What changes
`packages/cli/src/commands/serve.ts`, gate call region only. The gate is
now asked about the topology `declaresMultiNode(process.env)` reads (the
split-brain guard's predicate, from the same lazily loaded
`@objectstack/service-cluster` namespace `checkMultiNodeAllowed` comes
from). There is no second parse of either spelling in `serve.ts`: the
count spelling is asked through the same predicate, `declaresMultiNode({
OS_CLUSTER_REPLICAS })`, only to learn whether a count was given. The
refusal line is byte-identical.
| Declaration | Asked as | Before |
|:---|:---|:---|
| none (`OS_CLUSTER_REPLICAS` unset / 0 / 1) |
`Number(OS_CLUSTER_REPLICAS)`, unchanged | same |
| `OS_CLUSTER_REPLICAS=N` (N > 1), with or without
`OS_EXPECT_MULTI_NODE` | N, unchanged | same |
| `OS_EXPECT_MULTI_NODE=true`, no count | **2** | `NaN`, read as "not
declared" |
## The count for "declared, count unknown": 2
Measured on `multi-node-gate.ts` at the base (35a9c69).
`checkMultiNodeAllowed(requested)` normalizes `requested` through
`normalizeCount`: `undefined`, `NaN`, any non-finite value and any value
≤ 0 become "not declared"; 1 is single-node. With no gate registered it
refuses only when the normalized count is > 1. So `NaN` / `undefined` /
`Infinity` / 1 all read as "not declared" and are allowed, which is the
defect. 2 is the smallest value the gate reads as declared multi-node.
- No gate (open core): 2 is refused with `MULTI_NODE_NO_GATE_REASON`,
the same as `OS_CLUSTER_REPLICAS=2`.
- A registered gate is asked `allowMultiNode(2)`. An uncapped allowing
gate (the EE gate returns a bare `{ allowed, reason }`) admits it. A
cap-aware gate is asked about the fewest nodes a multi-node topology can
be.
- Telemetry (`describeMultiNodeCapTelemetry`) still reads
`OS_CLUSTER_REPLICAS` itself, so no `cluster_declared_nodes` series is
made from this 2.
The gate's signature in service-cluster is unchanged; no spec change.
## The cap advisory for an uncounted declaration (seat ruling)
That 2 is the call site's, not the operator's, so it must not reach the
licensed-cap advisory as a count they wrote.
`formatMultiNodeCapAdvisory` takes a second, required argument, `{
countDeclared: boolean }`, passed from the call site as
`!__countUnknown`. The formatter re-reads nothing. With `countDeclared:
false` (only `OS_EXPECT_MULTI_NODE=true`, and a cap-aware gate admits
fewer than 2) it prints:
```
[cluster] licensed node cap exceeded: the licence admits 1 node(s), but OS_EXPECT_MULTI_NODE=true declares a multi-node topology without a replica count.
[cluster] This cap is ADVISORY and is not enforced yet: nothing is refused, and every replica will still join the cluster.
[cluster] Run at most 1 replica(s) (or set OS_CLUSTER_REPLICAS to the count you run), or raise the licensed node limit.
```
There is no declared count, no "N beyond the cap" and no "all N
replicas". The counted case (`countDeclared: true`, every case `os
serve` produced before this PR) is byte-identical. This edit is outside
the gate call region (the formatter in `serve.ts`), as the seat ruled.
`content/docs/kernel/cluster.mdx`: the sentence that a gate denial makes
`os serve` downgrade "rather than failing" now says the remote driver is
dropped for the in-memory one, which is a downgrade only when no
multi-node topology is declared; with one declared (either spelling) the
split-brain guard refuses the boot. It also says a declared topology is
denied when no gate is registered.
## Tests
- New
`packages/cli/test/serve-multi-node-gate-declaration.integration.test.ts`:
four real `os serve` boots. The app's `@objectstack/service-cluster`
re-exports the framework's real ESM entry, so the gate and
`declaresMultiNode` are the shipped code. The app's
`@objectstack/service-cluster-redis` registers a `redis` driver that
delegates to `memory`, so no Redis server is needed.
1. `OS_EXPECT_MULTI_NODE=true` + redis + no gate → the gate refuses with
its own no-gate reason, and the split-brain guard refuses the in-process
fallback; no ready banner.
2. CONTROL: single node + redis + no gate → boots, no gate line.
3. CONTROL: `OS_CLUSTER_REPLICAS=2` + redis + no gate → refused, as
before.
4. CONTROL: `OS_EXPECT_MULTI_NODE=true` + redis + a registered gate that
admits → boots (`OS_ALLOW_MEMORY_CLUSTER_MULTINODE=true`, because the
stand-in driver is honestly in-process); the gate prints that it was
asked for 2.
- The file is named `.integration.test.ts` so it runs in the per-PR
integration tier; `*.e2e.test.ts` runs nightly only. It carries `//
test-budget: 40 — spawns the real producer once per single-cause
fixture`, from a local reading of 29.04 s (no CI reading yet).
Forced test edits (named):
- `packages/cli/src/commands/serve-multi-node-cap-advisory.pin.test.ts`
"passes the operator-declared replica count": the regex pinned the
literal
`checkMultiNodeAllowed(Number(process.env.OS_CLUSTER_REPLICAS))`. It now
pins the `__countUnknown` expression (both `declaresMultiNode` calls),
`__requestedNodes = __countUnknown ? 2 :
Number(process.env.OS_CLUSTER_REPLICAS)`, the
`checkMultiNodeAllowed(__requestedNodes)` call, and that no code in
`serve.ts` reads `process.env.OS_EXPECT_MULTI_NODE`. A new case pins the
call site passing `{ countDeclared: !__countUnknown }` and the required
second parameter.
- `packages/cli/src/commands/serve-multi-node-cap-advisory.test.ts`:
every existing call passes `COUNTED` (the expected text is unchanged).
Four new cases pin the uncounted text byte for byte, that it prints no
declared count, excess or "all N replicas", that the same verdict with
`COUNTED` keeps the counted text, and that the uncounted declaration is
silent wherever the counted one is. The file gains module-top
side-effect imports, because `check:test-source-alias` judges an edited
test file whose source reaches dynamic `import()`s.
- `packages/cli/test/serve-cluster-driver-diagnosis.e2e.test.ts` and
`packages/cli/test/serve-app-anchored-optional-import.e2e.test.ts`:
their stand-in `@objectstack/service-cluster` gains `declaresMultiNode()
{ return false; }`, because `serve` now calls it. The diagnosis file's
vacuity guard ("varies exactly one slot") moves the shared prefix to
include it.
## Acceptance notes
- In the boot test the red leg on main also ends in the split-brain
guard's refusal. That is a fixture fact: the stand-in driver is
in-process. With a real Redis driver, main booted multi-node (the card's
reach). The assertion that separates main from the fix is the gate's own
refusal line.
## Verification
<details><summary>Red on main, green on the fix, ablation</summary>
- Green at 1ae7d5f (serve.ts as in head): `vitest run --project
integration test/serve-multi-node-gate-declaration.integration.test.ts`
→ Test Files 1 passed, Tests 4 passed (tests 29.04 s); lock VERDICT
command-exit 0.
- Red on main: serve.ts restored from 35a9c69 in the working tree, same
command → Tests 2 failed | 2 passed. `× REFUSES
OS_EXPECT_MULTI_NODE=true …` (`expected … to contain '[cluster]
multi-node not authorized (…'`), and `× CONTROL: a registered gate …`
(`expected … to contain '[fixture] multi-node gate asked for 2'`; main
asked with `undefined`). Both CONTROLs for single node and
`OS_CLUSTER_REPLICAS=2` passed on main. Restore proven: `git diff HEAD`
empty and blob == HEAD.
- Ablation A1 through `scripts/ablation-replace.mjs`: `? 2` → `? 1 //
ABLATION-A1` (anchor 1 → 0, blob ecf1ee2 → 457b8d187bd2) → the same
two cases red, Tests 2 failed | 2 passed; restored, blob == HEAD, `git
diff HEAD` empty. No rebuild: `runServe` spawns `bin/run-dev.js`, which
runs `src/` through tsx.
- Ablation B1: ` if (!declaration.countDeclared) {` → ` if (false as
boolean) { // ABLATION-B1` (anchor 1 → 0, blob 91c4eba →
9a508e46c8f5) → `× names OS_EXPECT_MULTI_NODE and prints no count …` and
`× ⚠️ never prints the 2 serve asked about …`, Tests 2 failed | 19
passed; restored, blob == HEAD, `git diff HEAD` empty.
- Ablation B2: the call site's `{ countDeclared: !__countUnknown }` → `{
countDeclared: true /* ABLATION-B2 */ }` (blob 91c4eba →
13586c3aa1ba) → `× tells the cap advisory whether the count the gate saw
is one the operator wrote`, Tests 1 failed | 20 passed; restored, blob
== HEAD.
</details>
<details><summary>Package checks and gates</summary>
Final head 9a7ee97 (round 2 on top of ed64040; no new main merge,
serve.ts is touched by no open sibling).
- On 9a7ee97: `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` → 102 families (the docs line adds
families), every one exit 0. `--ran` reconciliation: "102 derived
famil(ies) accounted for — 102 run, 0 NOT-MEASURED (a DERIVED zero)".
The first pass on 29970f4 had one red, `check:test-source-alias` on the
edited advisory test; 9a7ee97 adds the module-top imports it names.
- On 9a7ee97: `pnpm --filter @objectstack/cli typecheck` → exit 0.
Advisory test + pin test → Tests 21 passed. `eslint --no-inline-config`
on the touched cli files → exit 0.
- On 29970f4 (9a7ee97 differs only by test-file imports): `turbo run
build --filter='./packages/**'` exit 0. New integration file → Tests 4
passed. `pnpm --filter @objectstack/cli exec vitest run --project unit`
→ Test Files 407 passed (407), Tests 5780 passed (5780).
- Dogfood battery on 29970f4: `pnpm --filter @objectstack/dogfood test`
under the lock → VERDICT command-exit 0, Test Files 440 passed / 3
skipped (443), Tests 3652 passed / 41 skipped (3693). Also green with
the same counts on ed64040 and 20b3fb9.
- Earlier (20b3fb9): nightly fixtures, `OS_TEST_TIERS=nightly …
--project integration test/serve-cluster-driver-diagnosis.e2e.test.ts
test/serve-app-anchored-optional-import.e2e.test.ts` → 2 files, 14 tests
passed. The rest of the cli `integration` tier is declared to CI.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmSNEnhcDvnrhmAucKu)_
<!-- signed: domain:server#2 · os-steve ·
session_01ADHkmQKZzp4DLtqiCkZZRM -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(cli)!: `os serve` asks the multi-node gate about a topology declared by `OS_EXPECT_MULTI_NODE=true`, not only by `OS_CLUSTER_REPLICAS`
6
+
7
+
Clause-②: no (narrowing)
8
+
Metadata-protocol: none
9
+
Skills-docs: `skills/**` names neither spelling of the multi-node declaration. `content/docs/kernel/cluster.mdx` already teaches both spellings as the declaration; its sentence that a gate denial "downgrades … rather than failing" is corrected in this diff: with a declared topology the split-brain guard refuses the boot.
10
+
11
+
<!-- adr-0087: not-required (no-migration-prescription) No schema key, export, type or stored shape changes. The narrowing is a boot refusal keyed to environment variables an operator sets, so there is nothing for a metadata migration to rewrite and no tombstone. -->
12
+
13
+
**BREAKING** for a deployment that runs `os serve` with a remote cluster driver (`OS_CLUSTER_DRIVER` other than `memory`), declares multi-node only as `OS_EXPECT_MULTI_NODE=true`, and registers no multi-node gate.
14
+
15
+
A multi-node topology has two spellings, `OS_CLUSTER_REPLICAS` greater than 1 and `OS_EXPECT_MULTI_NODE=true`. With no gate registered, the gate refuses a declared multi-node topology, because multi-node is a licensed capability. `os serve` used to ask the gate with `OS_CLUSTER_REPLICAS` alone, so a topology declared only as `OS_EXPECT_MULTI_NODE=true` reached the gate as undeclared and booted the remote driver multi-node with no gate. The same deployment spelled `OS_CLUSTER_REPLICAS=2` was already refused.
16
+
17
+
After the upgrade both spellings answer the same way. `os serve` reads the declaration through `declaresMultiNode` from `@objectstack/service-cluster`. A declaration with no count is asked as 2 nodes, the smallest multi-node count. With no gate registered it prints `[cluster] multi-node not authorized (…)`, drops the remote driver, and the split-brain guard refuses the in-process fallback, so the boot stops.
18
+
19
+
FROM a multi-replica deployment that sets `OS_EXPECT_MULTI_NODE=true` over a remote driver with no gate TO either:
20
+
21
+
- register a multi-node gate (install the distribution that carries it), which authorizes the topology, or
22
+
- drop `OS_EXPECT_MULTI_NODE` (and keep `OS_CLUSTER_REPLICAS` unset or 1) to run single-node.
23
+
24
+
A single-node boot, a boot declared as `OS_CLUSTER_REPLICAS`, and a boot whose registered gate admits the topology are unchanged.
25
+
26
+
When a gate that caps the node count admits fewer nodes than that 2, the licensed-cap advisory no longer prints a replica count the operator did not write. It names `OS_EXPECT_MULTI_NODE=true`, says what the licence admits, says the cap is advisory and every replica still joins, and asks the operator to run at most that many replicas (or set `OS_CLUSTER_REPLICAS`) or raise the limit. The advisory for a count declared as `OS_CLUSTER_REPLICAS` is unchanged.
0 commit comments