Repository navigation
Commit 41106b5
feat(runtime)!: refuse runtime package changes when replicas are declared on the Redis driver (#31751)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi968N7B64dDN7Noq8Fj3QSME)_
Fixes #31599
Maintainer ruling D1 on cloud#3814: 「多副本时拒绝」. Claim 6727421428
(`domain:server#4`, card-thread session_01ADHkmPnqZD15YnBkNbm1jJ), as
amended by 6728532665; seat rulings A on the three open questions (one
code, R6-style recipe wording, runtime's own ledger row).
Clause-②: yes (narrowing) — narrowed: the seven runtime package doors
(`POST /api/v1/packages`, `PATCH …/:id/enable`, `PATCH …/:id/disable`,
`POST …/:id/duplicate`, `POST …/:id/ensure-customization`, `PATCH
…/:id`, `DELETE …/:id`) answer `409
MULTI_REPLICA_PACKAGE_CHANGE_REFUSED` before anything is written when
the deployment declares several replicas (`OS_CLUSTER_REPLICAS` greater
than 1, or `OS_EXPECT_MULTI_NODE=true`) and the composed cluster service
runs the `redis` driver; `POST /api/v1/automation/:name/clone` and `POST
/api/v1/security/permission-sets/:name/clone` answer the same only when
their default landing would create the source's paired customization
package on this replica. Measured by the ablation that removes the
condition (the base behaviour): every refused door answered `2xx` and
ran its writer on base. Every other topology is unchanged. Widened:
`ERROR_CODE_LEDGER` (`@objectstack/spec`) registers the
already-registered code under `@objectstack/runtime` too (one row per
emitting package); nothing is removed or renamed. A registered ledger
row is a published schema, so this PR takes a `CONTRACT_REVIEW_TIER`
review.
Metadata-protocol: none
## 维护者速读
- 改了什么:部署声明了多副本(`OS_CLUSTER_REPLICAS` 大于 1 或
`OS_EXPECT_MULTI_NODE=true`)且集群驱动是 Redis 时,运行时的 7
个包门(安装、启用、停用、复制、确保定制包、改清单、删除)直接返回 409
`MULTI_REPLICA_PACKAGE_CHANGE_REFUSED`,提示在维护窗口里单副本或用 CLI
操作、再重启所有副本;流程和权限集的"新建相似"只在需要新建配对定制包时才拒绝。
-
为什么改:包注册表只在启动时读,启用/停用状态按副本各自保存,所以运行时改包只改到处理请求的那一个副本,其他副本看不到,重启后还会各自不同。维护者
D1 裁决「多副本时拒绝」。
- 风险与回滚:只在"声明多副本 + Redis
驱动"时生效;单节点、内存驱动、没有集群服务时字节不变;发布/草稿/回滚等元数据写门写共享库,不拒绝。回滚即 revert 本 PR。
- 先看:`packages/runtime/src/multi-replica-package-refusal.ts`(新文件,复用
#31602 落地的 `declaresMultiReplicaOnRedis`);`domains/packages.ts` 7
处调用点;`automation.ts` 与 `permission-set-clone.ts` 的两处克隆门;账本新增的一行。
- 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run
src/domains/packages-capability-gate.test.ts
src/domains/automation-flow-clone-custom-package.test.ts
src/domains/permission-set-clone.test.ts` —— 预期 209 passed,其中本卡新增 64 个。
- 需要你做的:无,席位落地(账本新增一行走 CONTRACT_REVIEW_TIER 复核)。
## What changes
Step 0, the doors that change the package registry or the per-replica
package state, read on `cae8d8fe`:
| Door | Handler | What it writes today |
|---|---|---|
| `POST /packages` | `handlePackagesRequest` install branch | `protocol`
install or `registry.installPackage`: a package in this replica's
registry |
| `PATCH /:id/enable`, `/:id/disable` | same, enable/disable |
`writePackageState`: the host store, or
`OS_HOME/package-state/<env>.<project>.json` on this replica's volume;
then the registry switch |
| `POST /:id/duplicate` | same | `protocol.duplicatePackage`: a new
package |
| `POST /:id/ensure-customization` | same |
`protocol.ensureCustomizationPackage`: the pair package |
| `PATCH /:id` | same, manifest edit | `protocol.updatePackage`
(`sys_packages` + registry) or `registry.updatePackageManifest` |
| `DELETE /:id` | same | `registry.uninstallPackage` + `sys_metadata`
removal |
| `POST /automation/:name/clone` | `resolveCloneTarget` → `land` |
ensures `<base>.custom` when the default landing needs it |
| `POST /security/permission-sets/:name/clone` |
`resolveDefaultCloneLanding` | same |
- **`packages/runtime/src/multi-replica-package-refusal.ts`** (new) —
`packageChangeReachesOneReplica` reads the composed `cluster` service's
driver per request and asks `declaresMultiReplicaOnRedis(process.env,
driver)` from `@objectstack/service-cluster` (landed by #31602).
`refuseMultiReplicaPackageChange` answers `409` with the code and the
recipe ("make the change in a maintenance window: run it on a single
replica or through the CLI, then restart every replica").
`multiReplicaPairCreationRefusal` refuses a clone only when this
replica's registry does not hold the pair yet.
- **`packages/runtime/src/domains/packages.ts`** — the refusal at each
of the seven doors right after `requireManageMetadata` and the
walled-catalog refusal, before the body is judged or anything is read or
written.
- **`packages/runtime/src/domains/automation.ts`**,
**`permission-set-clone.ts`** — the pair-creation refusal right before
the ensure. The flow door asks it inside `land`, after the engine has
accepted the copy, so a refusal withdraws the registration as a refused
landing already does; the permission-set door asks it through a
`beforeEnsure` hook and throws a `409` the door's existing envelope
renders.
- **`packages/spec/src/api/error-code-ledger.zod.ts`** —
`MULTI_REPLICA_PACKAGE_CHANGE_REFUSED` under `@objectstack/runtime`
(seat ruling: one row per emitting package, no second waiver). The code
was already in the union, so no reference doc changes (`check:docs`
green).
- **Tests** — in the existing harnesses (shared-harness rule), each a
new top-level `describe`: `packages-capability-gate.test.ts` (the
`make()` fake kernel gains an optional `cluster` service),
`automation-flow-clone-custom-package.test.ts` and
`permission-set-clone.test.ts` (each `boot` gains `clusterDriver`). No
existing case changed.
- **`.changeset/31599-runtime-package-doors-multi-replica-refusal.md`**
— `patch` for `@objectstack/runtime` and `@objectstack/spec`; both
declaration lines; `adr-0087: not-required (no-migration-prescription)`;
Before / Now / Unchanged / Who sees it.
## Tests
- Package doors, for each declaration (`OS_CLUSTER_REPLICAS=3`,
`OS_EXPECT_MULTI_NODE=true`) on `redis`, each of the seven doors: `409`
with the code, the message names the maintenance window and "restart
every replica", none of the registry or protocol writers ran, and
`OS_HOME` stays empty (no package-state file). An `isSystem` caller is
refused too; a caller without `manage_metadata` still gets the `403`
first.
- CONTROLs, each of the seven doors runs its writer as before: a single
node on `redis`, `OS_CLUSTER_REPLICAS=1` on `redis`, declared replicas
on the in-process driver (escape hatch), declared replicas with no
cluster service. On a single node, disable writes
`OS_HOME/package-state`, so the "nothing written" check would see a
write.
- Unchanged: the five metadata write doors of the same table
(publish-drafts, discard-drafts, commit revert, rollback, adopt-orphans)
are not refused under declared replicas on `redis`.
- Flow clone (real `ObjectQL` + `ObjectStackProtocolImplementation`
rig): `409` when the pair is absent (no pair installed, nothing
published, no row, the copy's registration withdrawn); `200` into an
existing pair; `200` for an explicit writable target; CONTROLs on a
single node and on the in-process driver.
- Permission-set clone: `409` when the pair is absent (no ensure, no
save); `200` into an existing pair; environment-authored source and
explicit target `200` with no ensure; CONTROLs on a single node, the
in-process driver and no cluster service.
## Acceptance notes
- **Not refused, by design.** publish, publish-drafts, discard-drafts,
revert, rollback, `commits/:commitId/revert` and adopt-orphans write the
shared metadata store, which every replica reads (and the metadata
cluster bridge fans out). The CLI's `os plugin disable`
(`plugin-installation-store`) is the recipe's own path and is not an
HTTP door.
- **The clone doors refuse narrowly.** Copying into a pair this replica
already serves, or into an explicit writable target, creates no package,
so it lands as before. A pair created on another replica only would
still be "absent" here and refused, which is the safe answer.
- **Protocol-internal ensure callers** inside
`@objectstack/metadata-protocol` are outside the claimed surface and are
not touched.
- **The recipe's wording** follows R6 (#31602) and names the CLI and a
single replica; it is one function, `multiReplicaPackageChangeMessage`.
## Verification
Head `5eb211c4` (fix `6a362f63`, tests and changeset `cecb6bff`, the
collection-time import the test-source-alias gate asks for `5eb211c4`),
cut on `origin/main` `cae8d8fe`; `main` has since moved 7 commits, none
touching a file this PR changes.
<details><summary>Suites (os-verify-lock, every VERDICT command-exit
0)</summary>
- `pnpm --filter @objectstack/runtime test`: 563 files / 9117 passed, 19
skipped (`cecb6bff`); `typecheck` exit 0; the edited suite rerun on
`5eb211c4`: 134 passed.
- `pnpm --filter @objectstack/service-cluster test`: 10 files / 128
tests.
- `pnpm --filter @objectstack/spec test`: 823 files / 26079 passed, 1
skipped, 1 todo. `typecheck`: exit 0 with
`NODE_OPTIONS=--max-old-space-size=8192`; at the script's default 4096
its `check:test-typecheck` leg ran out of heap in this container before
reporting (no diagnostics; the diff to `spec` is one ledger string).
- `pnpm --filter @objectstack/spec check:docs`: exit 0, 246 generated
files in sync.
- `pnpm --filter @objectstack/dogfood test` (full battery, narrowing
arm): 440 passed, 3 skipped files / 3652 passed, 41 skipped tests
(`5eb211c4`).
- Lint (`eslint --no-inline-config`) on `packages/runtime/src` and the
ledger file: exit 0.
</details>
<details><summary>Ablations (negative pins)</summary>
`scripts/ablation-replace.mjs` on `cecb6bff`; the tests import the
runtime from `src`, so no rebuild leg.
- Marker `ABLATED_31599`: `packageChangeReachesOneReplica` always
answers `false` (the base behaviour). **19 of 209 red**, exactly the
refusal cases: 14 package-door cases (7 doors × 2 declarations), the
`isSystem` case, and the two clone doors × 2 declarations. Every CONTROL
and every unchanged case green. Restored: blob `aad86398` == HEAD, `git
diff HEAD` empty.
- Marker `ABLATED_31599_PAIR`: the existing-pair exemption removed. **2
of 75 red**, exactly the two "pair already served is reused" cases.
Restored, blob == HEAD.
</details>
<details><summary>Derived gates</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack`: 93 families, each run with stdin closed and
its exit recorded; `--ran` reconciliation: "93 derived famil(ies)
accounted for — 93 run, 0 NOT-MEASURED". All 93 exit 0, among them
`check:error-code-provenance`, `check:error-code-casing`,
`check:dispatcher-error-vocabulary`, `check:error-status-conformance`,
`check:route-envelope` and `check:changeset-no-major`. The first pass on
`cecb6bff` had five `spec` surface gates at exit 3 (no `spec`
declarations built; green after `pnpm --filter @objectstack/spec build`)
and `check:test-source-alias` red (the edited packages suite reaches
`@objectstack/metadata` during collection; fixed in `5eb211c4` with the
module-top import the gate prescribes, then green).
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmPnqZD15YnBkNbm1jJ)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 5f26be2 commit 41106b5
9 files changed
Lines changed: 650 additions & 11 deletions
File tree
- .changeset
- packages
- runtime/src
- domains
- spec/src/api
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
113 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
114 | 126 | | |
115 | 127 | | |
116 | 128 | | |
| |||
133 | 145 | | |
134 | 146 | | |
135 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
136 | 159 | | |
137 | 160 | | |
138 | 161 | | |
139 | 162 | | |
140 | 163 | | |
141 | 164 | | |
142 | 165 | | |
143 | | - | |
| 166 | + | |
144 | 167 | | |
145 | 168 | | |
146 | 169 | | |
| |||
153 | 176 | | |
154 | 177 | | |
155 | 178 | | |
| 179 | + | |
156 | 180 | | |
157 | 181 | | |
158 | 182 | | |
| |||
473 | 497 | | |
474 | 498 | | |
475 | 499 | | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| |||
2606 | 2607 | | |
2607 | 2608 | | |
2608 | 2609 | | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
2609 | 2614 | | |
2610 | 2615 | | |
2611 | 2616 | | |
| |||
0 commit comments