Skip to content

Commit 20bf222

Browse files
fix(metadata-protocol)!: a bare save or delete counts the holders the bare read counts (ADR-0150 D3/D5) (#34324)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbBePzY6g11h3hyWk5ud4vWy)_ Fixes #34144 Part of #33955 Part of #34262 > #33955 and #34262 are folded into this PR and are closed by the area on merge (seat ruling, 2026-11-16T13:57Z); they are `Part of` so the landing gate reads one delivered card, #34144. Clause-②: no (narrowing) Metadata-protocol: none Skills-docs: none — a `git grep` of `skills/` finds no text that teaches a bare save or delete of a name two enabled packages hold or only disabled packages hold > **BREAKING (declared narrowing).** Every moved answer goes from accepted (or, for a bare delete or draft discard over no stored row, the no-op receipt) to refused, and nothing that was refused is now accepted. A bare save in these states that a later gate already refused now answers this 409 first: refused to refused. The changeset carries the ADR-0087 marker (`not-required (no-migration-prescription)`). > **Follows #33995 (merged).** This branch has `origin/main` with #33995 merged in, and flips #33995's review#2 S3 save pin (`packages/objectql/src/disabled-holder-packageless-row-doors.test.ts`) to this refusal. The pin's delete half, its shipped-member `403 NOT_OVERRIDABLE` CONTROL and its re-enable CONTROL are unchanged. The FROM and TO are in the table below and in the changeset. ## 维护者速读 - 改了什么:不带包名保存或删除一个名字时,现在按读取的规则数持有者。两个以上启用中的包持有时,拒绝(409)并列出这些包。只有停用的包持有时,拒绝并提示用 `?package=`,不点名任何包。这两种状态下,没有存储行时的删除和草稿丢弃也从“无操作成功”改为拒绝。 - 为什么改:读取已经这样回答(409 列出两个包,或 404),保存却返回 200,悄悄改写某个包的行,或写出一条读不到的行。这违反 ADR-0150 红线 2(有歧义就报告,不猜),也违反裁决 A。 - 风险与回滚:这是声明过的收窄,原来能保存的现在被拒绝。只影响两种状态,带 `?package=` 的写入和环境自己的条目不变。回滚就是撤销这个 PR,不涉及存储行。 - 先看:`packages/metadata-protocol/src/protocol-save.ts` 文件末尾的 `packagelessHolderRefusal` 和两处调用;`protocol-diff-delete-load.ts` 里删除的那一处调用;`packages/objectql/src/disabled-holder-packageless-row-doors.test.ts` 里翻转的 S3 保存断言。 - 两分钟验证:`pnpm --filter @objectstack/metadata-protocol build && cd packages/runtime && pnpm exec vitest run --project local src/domains/meta-disabled-holder-served-stack.test.ts`,预期 1 个文件、全部用例通过。 - 需要你做的:无,席位落地。 ## What changes A write that names no package (`PUT` / `DELETE /meta/:type/:name` with no `?package=`, `saveMetaItem` / `deleteMetaItem` with no `packageId`) took its address from the stored rows' bindings alone (`packagelessAddress`), while the bare read counts the name's holders. One new judgment, `packagelessHolderRefusal` in `protocol-save.ts`, runs after the existing judgments (`servedPackagelessSaveAddress` and the two-bindings refusal), so neither of their answers moves. It is asked by the publish-mode bare save, the draft-mode bare save, and the bare delete (`protocol-diff-delete-load.ts`, the delete half only). - **Two or more enabled holders (#33955, ADR-0150 D3/D5, red line 2).** The judgment asks the package-scoped resolver, `registry.resolveItem(type, name, null, member)`, which the by-name read asks before any layer. When it refuses `ambiguous-in-environment`, the write is refused with the existing `packagelessAddressAmbiguityRefusal`, which names those packages. - **Only disabled holders (#34144 ruling A, #34262).** When every holder of the name is disabled, the write is refused with `disabledHoldersOnlyRefusal`. Holders here are registry holders, code shippers and stored-row bindings, and a row bound to a disabled holder's customization pair counts as that holder. The refusal is `409 RESOURCE_CONFLICT` (the same family, no new code) with the `?package=` remedy, and it names no package. - **Left alone.** A package-unbound row stored at the address, the environment's own item, a type the registry does not read by package, and a registry without the reads. Commits: one per card, then the #33995 follow-up. #34144 is the disabled-only arm, its pins and the flipped #33889 CONTROL. #33955 is the resolver arm and its pins. #34262 is a pin only: the #34144 arm already covers that cell. After merging `origin/main` (with #33995), one commit flips #33995's S3 save pin and one adds that FROM and TO to the changeset. Then three review#1 commits: the jsdoc gap and the shared recogniser in the resolver catch (N1), the no-row delete pins (S2, N2), and the changeset corrections (S2, N3, N4). At takeover, one commit (e378b62) adds a sentence to this PR's changeset that supersedes the stale line of `.changeset/33385-disabled-holders-env-404.md` (prose only). | Door (no package named) | State | FROM | TO | |:---|:---|:---|:---| | publish save | only disabled D holds, D's row alone | 200, D's row updated | 409 `RESOURCE_CONFLICT`, `?package=` remedy, no package named; D's row byte-unchanged | | publish save | only disabled D ships it, no stored row | 200, package-unbound row written (every read withholds it) | 409 as above, nothing written | | publish save | only disabled D ships it, D's row | 200, D's row updated | 409 as above, row unchanged | | draft save | only disabled D ships it, no stored row | 200, package-unbound draft written | 409 as above, nothing written | | delete | only disabled D ships it, D's row | 200, D's row removed | 409 as above, row stays | | publish save, `email_template` | every holder disabled, a member D never ships (#34262) and the member it ships | 200, package-unbound row stored and withheld | 409 as above, nothing stored | | publish save, `email_template` (#33995's S3 pin, objectql engine) | the package disabled, `fr-FR`, a member it never ships | `success: true, state: 'active'`, package-less row stored, hidden until re-enable | 409 `RESOURCE_CONFLICT`, `?package=` remedy, naming no package, no row stored | | publish save | two enabled packages ship it, no stored row | 200, package-unbound row written | 409 naming both, nothing written | | publish save | two enabled ship it, one package's row (either) | 200, that row updated | 409 naming both, row unchanged | | draft save | two enabled ship it, no stored row | 200, package-unbound draft written | 409 naming both | | delete | two enabled ship it, E's row | 200, E's row removed | 409 naming both, row stays | | delete and draft discard (`state: 'draft'`) | two enabled ship it, no stored row | the no-op receipt (`success: true, reset: false`) | 409 naming both | | delete and draft discard (`state: 'draft'`) | only disabled D ships it, no stored row | the no-op receipt (`success: true, reset: false`) | 409 with the `?package=` remedy, no package named | Unchanged, pinned as CONTROLs: a row of each of two enabled holders (409 before and after); `?package=D` and `?package=E` saves and deletes; a name one enabled package holds; every #32605 cell (an enabled beside a disabled holder); a name no package holds; a package-unbound row at the address (the save edits it and the delete removes it); and every bare write once the package is enabled again. ## Tests - `packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts`, inside the existing #32605 bare-save harness (shared-harness rule). Every new pin runs on a booted kernel, through both transports (the runtime dispatcher and `RestServer`) and in both registration orders. The harness's `put` now takes a query (`?package=`, `?mode=draft`). - The #33889 CONTROL "a name only the disabled D holds … is saved as before" is flipped to ruling A's refusal, with `?package=D` and re-enable as CONTROLs. - #34144: the bare save over no row and over D's row, the draft save, and the bare delete with the delete naming D as CONTROL. Also the environment's own items. - #33955: rows 0 / E's / D's / both, the bare read's 409 beside the save's, the draft save and delete, `?package=E` as CONTROL, and the package-unbound row as CONTROL. - #34262: the `email_template` member D never ships and the one it ships, with re-enable as CONTROL. - review#1 S2: the bare delete and the bare draft discard over no stored row, one pin per state (`d_norow_dash`, `two_norow_dash`), with the delete naming the package (still the no-op receipt) as CONTROL. Declared and pinned rather than guarded on a row being addressed: over no row the address is just as ambiguous (two enabled holders) or unheld (only disabled holders) as for the save, and ADR-0150 D5 answers an ambiguous bare address 409, "never a silent pick". The no-op receipt's self-heal also restores a registry view at that unresolved address. - review#1 N2: the disabled-only delete pins now assert the `?package=` remedy and that no package is named. - `packages/objectql/src/disabled-holder-packageless-row-doors.test.ts` (#33995's file, an approved extension of this claim's surface): the review#2 S3 save is flipped from "accepted and kept" to the refusal above, and nothing is stored. CONTROLs: the shipped-member `en-US` save is still `403 NOT_OVERRIDABLE` (that gate answers before this judgment), and once the package is enabled again the same `fr-FR` save is kept. The delete half is unchanged: with the package disabled again, a delete naming no package removes the package-less row. - Refusals assert `code` and `status`, the `?package=` remedy, and which packages are named or not named. The rest of the wording is not pinned. <details><summary>Readings, head 6401aad (origin/main 43dd565 merged in)</summary> - `meta-disabled-holder-served-stack.test.ts` at 504dd1f after building metadata-protocol: Test Files 1 passed (1), Tests 128 passed (128). - `pnpm --filter @objectstack/metadata-protocol test` at 504dd1f: Test Files 344 passed, 9 skipped (353); Tests 22946 passed, 45 skipped. - `pnpm --filter @objectstack/metadata-protocol typecheck` and `pnpm --filter @objectstack/runtime typecheck` at 504dd1f: exit 0, exit 0. - After the merge, at 6401aad, with a fresh install and the runtime, rest and dogfood closure built under the verify lock: `pnpm --filter @objectstack/runtime test` gave Test Files 607 passed (607), Tests 11144 passed, 19 skipped. `pnpm --filter @objectstack/rest test` gave Test Files 413 passed (413), Tests 8491 passed, 350 skipped. - Dogfood battery at 6401aad (`pnpm --filter @objectstack/dogfood test`, no shard, no path): VERDICT command-exit 0. Test Files 470 passed, 3 skipped (473); Tests 3985 passed, 42 skipped. It was not re-run on the later heads; the Dogfood Regression Gate in CI carries it. </details> <details><summary>Ablations (one per arm, each rebuilt into dist and checked there)</summary> - **S2, at e378b62 (this round).** The no-row refusal of the bare delete and draft discard was ablated at its call site in `protocol-diff-delete-load.ts`. The anchor `if (request.packageId == null) {` was replaced so the holder judgment runs only when a row is addressed (`... && rowsAtAddress.candidates.length > 0 && String('ABLATION_S2_NOROW') !== ''`). `ablation-replace` reported anchor 1 to 0, blob 0efc258 to 02c67f22e2df. `ablation-dist-preflight` found the marker in 2 built files (`dist/index.cjs`, `dist/index.js`), exit 0. Result: Tests 8 failed, 128 passed (136). The 8 are exactly the two S2 pins (`d_norow_dash`, `two_norow_dash`) in all four transport and order cases. Every other pin, the row-present delete pins included, stayed green. Restore: blob equal to HEAD (0efc258), `git diff HEAD` empty. After the rebuild, `--absent` exit 0 (marker absent from all 24 built files, tree clean), and the file passed again: Tests 136 passed (136). - Disabled-only arm: the anchor `return disabledHoldersOnlyRefusal(...)` was replaced with a guarded copy carrying the marker `ABLATION_34144_NEVER`. `ablation-replace` reported anchor 1 to 0, blob 38624bc to 006312afca07. `ablation-dist-preflight` found the marker present in 2 built files. Result: Tests 20 failed, 108 passed. The 20 are exactly the five ruling-A pins in all four transport and order cases, including the #34262 pin. Every CONTROL stayed green. - Enabled-holders arm: the `held.length > 1` refusal was guarded with the marker `ABLATION_33955_NEVER`, giving blob 38624bc to fbc5c93f2c63, with the marker present in 2 built files. Result: Tests 16 failed, 112 passed. The 16 are the three new #33955 rows plus the draft and delete pin, in all four cases. The "row of each" CONTROL stayed green, refused by the stored rows' own refusal as before. - Restore: `git diff HEAD` was empty after both. After the rebuild, `ablation-dist-preflight --absent` passed for both markers (exit 0, exit 0). - #33995's S3 save pin (objectql), at 0deac3e: the disabled-only anchor replaced with `return void 'ABLATE_S3_34144'`, blob 38624bc to 0a2d9ce3926e, the marker present in 2 built files. Result: Tests 1 failed, 4 passed; the flipped pin failed with `expected [ undefined, undefined ] to deeply equal [ 409, 'RESOURCE_CONFLICT' ]` (the save accepted). Restored (blob equal to HEAD, `git diff HEAD` empty); rebuilt, `--absent` exit 0. A first run used a comment marker the build strips, so its dist proof failed (marker absent) and it is not counted. </details> ## Acceptance notes - Open question closed as A (keep), by the coordinator: a package-unbound row of a name only a disabled package ships (`d_unbound_dash`). The bare read answers 404 and the bare save still edits that row. It is pinned as a measured, unchanged CONTROL: the `?package=` remedy cannot reach a package-unbound row, so refusing would leave no way to write it while the package is disabled. The maintainer's decision on it is #34348. - Known gap, not fixed here (review#1 S1): two enabled holders whose stored rows are bound to a disabled package and to exactly one enabled holder still save to that holder's row (200) where the read refuses 409; with an enabled and a disabled holder the draft save and the delete still take their address from the rows. The jsdoc of `servedPackagelessSaveAddress` and `packagelessHolderRefusal` names the gap. Carried by #34346. - The unreleased note `.changeset/33385-disabled-holders-env-404.md` (from #33995) still says the never-shipped-member save "is accepted and kept, as before". That file is not edited here (seat routing). Instead, this PR's changeset names it by filename and says the line is superseded: while every holder is disabled, the save is refused and nothing is stored (commit e378b62). Both notes ship in the same release. - Measured: two enabled shippers plus a package-unbound row laid straight into the store. The bare read answers 409, because the registry has not hydrated the row, while the save edits the row, as before. The save keeps the prefer-local rule (ADR-0048). - The `email_template` save at the member the package ships answered 200 in this harness (a code-registered package), not 403 `NOT_OVERRIDABLE` as in #33995's harness. Both now refuse while every holder is disabled. ## Follow-ups - #34346: mixed holders plus a disabled binding, on the publish save, the draft save and the delete (review#1 S1). - #34348: decision on a package-unbound row beside disabled-only or two enabled holders (review#1 S3). ## Verification **Verified at head e378b62** (the review#1 round at 7b1880f plus the changeset sentence; no code change since 7b1880f). This takeover round ran on a fresh worktree from `origin/claude/area-E1b-34144`, with the runtime, rest, metadata-protocol and dogfood closure built under the verify lock (VERDICT command-exit 0). `origin/main` was not merged in that round. The area then merged `origin/main` `cfcba539` by update-branch (K was 31): head `18533305`, the PR's patch-id unchanged; the dogfood battery is re-run on that head and recorded on #34144. <details><summary>Readings at e378b62</summary> - `meta-disabled-holder-served-stack.test.ts` (runtime, metadata-protocol rebuilt): Test Files 1 passed (1), Tests 136 passed (136). That is 128 before plus the two S2 pins in four cases. - `pnpm --filter @objectstack/metadata-protocol test`: Test Files 345 passed, 9 skipped (354); Tests 22956 passed, 45 skipped. - `pnpm --filter @objectstack/objectql test` (the flipped #33995 pin's package): Test Files 600 passed (600); Tests 13387 passed. - `pnpm --filter @objectstack/runtime test`: Test Files 607 passed (607); Tests 11206 passed, 19 skipped. - `pnpm --filter @objectstack/rest test`: Test Files 413 passed (413); Tests 8552 passed, 350 skipped. - `typecheck` of metadata-protocol, runtime, rest and objectql: VERDICT command-exit 0 for each run. - Dogfood battery, once on this head (`pnpm --filter @objectstack/dogfood test`, no shard, no path): VERDICT command-exit 0; Test Files 473 passed, 3 skipped (476); Tests 4003 passed, 42 skipped; no failures. - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 71 families from this diff (5 paths). All 71 were run, each recorded with its exit code. `--ran`: "71 derived famil(ies) accounted for — 71 run, 0 NOT-MEASURED". Three first ran with exit 3 and were re-run to exit 0: `check-plugin-teardown-shape --self-test` (its pinned control commit was fetched), `check:type-check-debt` (the lock queue timed out; the re-run re-measured OK), and `check:dual-build-cjs-loads` (after that full build: 123 entries across 72 packages load). The derivation warned that this tree is behind origin/main and that 2 of its gate files changed there (`check-skills-token-ratchet.mjs`, `label-write.mjs`); neither is a family this diff derives. - CI on e378b62: 35 success, 16 skipped, none failed. That includes `Lint & Repo Gates`, `TypeScript Type Check`, `Test Core` (8/8), `Build Core`, `Governed Surface Queue Guard`, `Check Changeset`, `Dogfood Regression Gate` and `Live E2E UI`. - Overlap with #34238 is unchanged: this PR lands first, and #34238 reconciles `protocol-save.ts` when it merges main. </details> Earlier rounds' readings: <details><summary>Local gates and overlap</summary> - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 70 families on this diff. All 70 were run at 6401aad, each with its exit code recorded. `--ran` reconciliation: "70 derived famil(ies) accounted for, 70 run, 0 NOT-MEASURED (a DERIVED zero)". - `check:dual-build-cjs-loads` first exited 3 (PREREQUISITE NOT MET: no dist yet). It was re-run after the full build that `check:type-check-debt` makes under the lock, and exited 0 (123 entries across 72 packages load). - `pnpm lint`: exit 0. `check:nul-bytes`: OK. - PR-body gates on this body: `check-changeset-no-major` (LEVEL AXIS: `no (narrowing)` plus `none` at `patch`), `check-adr-0087-registration` (1 declared-breaking changeset with its disposition), `check-closing-keyword-parity` and `check-partof-closing-keyword`. Each exited 0. - `git merge-tree --write-tree --name-only` of HEAD against #34147 (624b7ff), #33995 (69f4887), branch `claude/area-E1b-32780` (d314ad0) and origin/main: exit 0 for each, with no conflicted path. The coupling with #33995 is semantic, not textual (see the banner above). - `node scripts/pm/dispatch-gates.mjs --tier`: no path-derived tier mandate. "A card that only NARROWS one is `Clause-②: no`", which matches this declaration. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01FEkQ5obaLbqgzRUR9xXfft)_ <!-- signed: repo:objectstack#1 · os-project-manager · session_01FEkQ5obaLbqgzRUR9xXfft --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent c9ef653 commit 20bf222

5 files changed

Lines changed: 401 additions & 26 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
fix(metadata-protocol)!: a bare save or delete answers the holders the bare read counts: a name two enabled packages hold is refused naming both, and a name only disabled packages hold is refused naming none (ADR-0150 D3/D5)
6+
7+
Clause-②: no (narrowing)
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export changes shape. The moved answers are write doors under a reversible package state: no stored row is rewritten, so there is nothing for a migration to rewrite and no tombstone. -->
11+
12+
**BREAKING** for a writer that saves or deletes a name without naming a package (`PUT` or `DELETE /meta/:type/:name` with no `?package=`, or `saveMetaItem` / `deleteMetaItem` with no `packageId`), in two states. The bare write used to take its address from the stored rows alone, while the bare read counts the name's holders. It now counts them as the read does (ADR-0150 D3/D5, red line 2: ambiguity is reported, never guessed). Every refusal is the existing `409 RESOURCE_CONFLICT` with the `?package=` remedy; there is no new code. Measured on a booted kernel through the runtime dispatcher and `RestServer`, in both registration orders.
13+
14+
**Two or more enabled packages hold the name.** The bare read refuses 409 naming them.
15+
16+
- A publish-mode bare save used to answer 200. Over no stored row it wrote a package-unbound row beside both packages; over one package's row it updated that row. It is now refused naming both packages, and nothing is written. Over a row of each it was refused already, and still is.
17+
- A draft-mode bare save (`?mode=draft`) used to write a package-unbound draft, or the one package's draft. It is now refused the same way.
18+
- A bare delete used to remove the one package's row. It is now refused the same way, and the row stays.
19+
- A bare delete or bare draft discard (`?state=draft`) over no stored row used to answer the no-op receipt (`success: true, reset: false`). It is now refused the same way.
20+
21+
**Every package that holds the name is disabled.** A disabled package holds no name (ruling A on #34144 and the registry's served-holder rule, #32183), so the bare read answers 404. The bare write is now refused naming no package (ruling A):
22+
23+
- A publish-mode bare save of a name whose only holder D is disabled used to answer 200. Over D's row alone it updated D's row; over no stored row it wrote a package-unbound row that every read then withheld. It is now refused, and nothing is written.
24+
- A bare save of a bundled name (an `email_template`) whose every holder is disabled, at a member the holder never ships, used to answer 200 and store a package-unbound row that the by-name read and both lists withheld until the package was enabled again. It is now refused, and nothing is stored. This replaces the "accepted and kept" save described in this release's note on reads of a disabled package's customization: FROM `success: true` with the row stored and hidden, TO `409 RESOURCE_CONFLICT` with the `?package=` remedy, naming no package, no row stored. The line of `.changeset/33385-disabled-holders-env-404.md` that says this save "is accepted and kept, as before" is superseded by this note: while every holder is disabled, the save is refused and nothing is stored. A delete of such a row while the package is disabled still removes it, a save at a member the package ships is still refused `403 NOT_OVERRIDABLE` where the package door refuses it, and once the package is enabled again the same save is kept.
25+
- A draft-mode bare save (`?mode=draft`) of such a name used to write a package-unbound draft. It is now refused the same way.
26+
- A bare delete of such a name used to remove D's row. It is now refused, and D's row stays.
27+
- A bare delete or bare draft discard (`?state=draft`) of such a name over no stored row used to answer the no-op receipt (`success: true, reset: false`). It is now refused the same way.
28+
29+
**Not moved.** A write naming the package (`?package=`, `packageId`) answers as before. So do a name one enabled package holds, a name an enabled and a disabled package both hold, a name no package holds (the environment's own item), and a package-unbound row stored at the address: the save edits that row and the delete removes it, as before. Once a disabled package is enabled again, its bare writes answer as before. A type the registry does not read by package (`action`, `doc`, whose bare reads refuse through their own judges) is not judged here and answers as before. A bare save in these two states that a later gate already refused (an invalid body, a read-only inherited package) is still refused, now with this `409` first: refused to refused.
30+
31+
**No migration.** No schema key or stored row changes. To write one holder's item, name its package; to write a disabled package's item, name it or enable it again.

‎packages/metadata-protocol/src/protocol-diff-delete-load.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import { withRefusalAudit } from './protocol-refusal-audit.js';
6666
import { captureStoredExpressionChange, fillStoredExpressionChange } from './protocol-stored-expression-fill.js';
6767
import type { RuntimeAuthoringIssue } from './runtime-authoring-gate.js';
6868
import type { ProtocolHost } from './protocol-host.js';
69+
import { packagelessHolderRefusal } from './protocol-save.js';
6970

7071
/**
7172
* [#33308] The row slot a `sys_metadata` row is: its bound package, or `null`
@@ -730,6 +731,23 @@ export class ProtocolDiffDeleteLoadFacet {
730731
);
731732
throw addressRefusal;
732733
}
734+
// [ADR-0150 D3/D5, red line 2, ruling A] …and the holders the
735+
// read naming no package counts, as the save door asks them
736+
// ({@link packagelessHolderRefusal}): two or more enabled holders
737+
// are refused naming them, and a name only disabled packages hold
738+
// is refused naming none, never one row removed. Over no stored
739+
// row too (the delete and the draft discard answered the no-op
740+
// receipt). A package-unbound row at the address is the
741+
// environment's own, and its removal is left as it was.
742+
if (request.packageId == null) {
743+
const holderRefusal = packagelessHolderRefusal(
744+
host, 'delete', request.type, singularTypeForRepo, request.name, member, rowsAtAddress,
745+
);
746+
if (holderRefusal) {
747+
addressRefusal = holderRefusal;
748+
throw addressRefusal;
749+
}
750+
}
733751
const packageId: string | null = request.packageId
734752
?? (draftAddress !== undefined ? draftAddress.key : rowsAtAddress.packageId);
735753
// Probe first — "no overlay exists" is a success/no-op, not

‎packages/metadata-protocol/src/protocol-save.ts‎

Lines changed: 147 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ import { saveRegistryQuestion } from './registry-question.js';
8888
import { OBJECT_EXTENSION_TYPE, registrableObjectExtension } from './protocol-object-extension-item.js';
8989
import { servedAddressJudgment } from './protocol-meta-item-face.js';
9090
import { packagelessContentPackage, shippingPackageIds } from './protocol-environment-rows.js';
91+
import { installedManifestsOfEngine } from './installed-manifests.js';
92+
import { packageScopedRefusalOf } from './protocol-meta-item-reads.js';
93+
import { pairsOf } from '@objectstack/metadata-core';
9194
import { BatchRowHealError, canJudgeBatchObjects, isBatchObjectType, readActiveBatchRow, settleBatchObjectRows, undoBatchRowWrite, undoOutcomeForLog, type WrittenBatchRow } from './batch-object-registration.js';
9295

9396
export class ProtocolSaveFacet {
@@ -826,6 +829,15 @@ export class ProtocolSaveFacet {
826829
if (address.candidates.length > 1) {
827830
throw packagelessAddressAmbiguityRefusal('save', request.type, request.name, address.candidates);
828831
}
832+
// [ADR-0150 D3/D5, red line 2, ruling A] …and the holders the
833+
// read naming no package counts ({@link packagelessHolderRefusal}):
834+
// two or more enabled holders are refused naming them, and a name
835+
// only disabled packages hold is refused naming none, never
836+
// written at one row's package or as a new package-unbound row.
837+
const holderRefusal = packagelessHolderRefusal(
838+
host, 'save', request.type, writeType, request.name, itemDiscriminator(writeType, request.item), address,
839+
);
840+
if (holderRefusal) throw holderRefusal;
829841
if (address.packageId !== null) request = { ...request, packageId: address.packageId };
830842
}
831843
}
@@ -846,6 +858,21 @@ export class ProtocolSaveFacet {
846858
singularType, request.name, itemDiscriminator(singularType, request.item),
847859
)
848860
: undefined;
861+
// [ADR-0150 D3/D5, red line 2, ruling A] The draft save naming no
862+
// package answers the holders as the publish-mode save above does
863+
// ({@link packagelessHolderRefusal}), judged over the item's active rows
864+
// and its drafts: the draft address alone took the one package with a
865+
// row, or a new package-unbound draft. An ambiguous draft address is
866+
// left to the repository's `409`, as before.
867+
if (draftAddress !== undefined && draftAddress.kind !== 'ambiguous') {
868+
const member = itemDiscriminator(singularType, request.item);
869+
const active = await host.packagelessAddress(singularType, request.name, member, 'active');
870+
const holderRefusal = packagelessHolderRefusal(host, 'save', request.type, singularType, request.name, member, {
871+
candidates: [...new Set([...active.candidates, ...draftAddress.drafts.candidates])],
872+
unbound: active.unbound || draftAddress.drafts.unbound,
873+
});
874+
if (holderRefusal) throw holderRefusal;
875+
}
849876

850877
// [#26921] THE NAMED-BASE RULE for the binding a save naming no
851878
// package INHERITS: the package its address gives (the resolved
@@ -2836,9 +2863,10 @@ export class ProtocolSaveFacet {
28362863
/**
28372864
* [#32605, epic ruling 6781691009 on #32354, ADR-0150 D3/D4/D5] THE WRITE
28382865
* ADDRESS of a publish-mode save naming no package, for a name a DISABLED
2839-
* package also holds: the address the read naming no package serves, so the
2840-
* save writes exactly the row the next read answers. A disabled package holds
2841-
* nothing an address reaches, so it is never the address and never named.
2866+
* package also holds: in the cells below, the address the read naming no
2867+
* package serves, so the save writes the row the next read answers. A
2868+
* disabled package holds nothing an address reaches, so it is never the
2869+
* address and never named.
28422870
*
28432871
* - The read's own judgment first ({@link servedAddressJudgment}, the one
28442872
* #32183 and #32354 gave the reads): its served holder is the address; its
@@ -2851,9 +2879,15 @@ export class ProtocolSaveFacet {
28512879
* the package-unbound row when one is stored (the save edits it, as the
28522880
* read serves it), else the one enabled package that ships the name (the
28532881
* read's content package, {@link packagelessContentPackage}).
2854-
* - `undefined` leaves the address to {@link packagelessAddress}, as before:
2855-
* no disabled holder, or one only disabled packages hold (no served holder
2856-
* to take the write; the save keeps naming that package, as it did).
2882+
* - `undefined` leaves the address to {@link packagelessAddress} and
2883+
* {@link packagelessHolderRefusal}: no disabled holder, or one only
2884+
* disabled packages hold (no served holder to take the write; that judgment
2885+
* refuses it naming no package).
2886+
*
2887+
* Known gap: two or more ENABLED packages hold the name and the stored rows
2888+
* are bound to a disabled package and to exactly one of them. The enabled
2889+
* bindings above pick that one (the save answers 200) where the read refuses
2890+
* `409` naming every enabled holder. A follow-up card is filed.
28572891
*
28582892
* Without it the save door counted the disabled holder as a holder: over no
28592893
* stored row it wrote a package-unbound row (an environment-own item that
@@ -2887,3 +2921,110 @@ async function servedPackagelessSaveAddress(
28872921
const content = packagelessContentPackage({ packageId: null, candidates: [] }, shippers.map((id) => ({ _packageId: id })));
28882922
return typeof content === 'string' ? { packageId: content } : undefined;
28892923
}
2924+
2925+
/**
2926+
* [ADR-0150 D3, ruling A on the disabled-only name] The refusal of a write
2927+
* naming no package of a name every holder of which is disabled. A disabled
2928+
* package holds no name, so the read naming no package answers the missing
2929+
* name; the write names no package either, and points to the one way to act
2930+
* on that package's item. `409 RESOURCE_CONFLICT`, the refusal family of
2931+
* {@link packagelessAddressAmbiguityRefusal}, with no new code.
2932+
*/
2933+
export function disabledHoldersOnlyRefusal(
2934+
verb: 'save' | 'delete',
2935+
type: string,
2936+
name: string,
2937+
): Error & { code: 'RESOURCE_CONFLICT'; status: 409 } {
2938+
const [nothing, single] = verb === 'save'
2939+
? ['Nothing was written.', 'no row to write']
2940+
: ['Nothing was deleted.', 'no row to remove'];
2941+
const err = new Error(
2942+
`Name the package this ${verb} is for, then send it again: on the REST door add ?package= with the package id, `
2943+
+ `in process pass packageId. ${nothing} ${type} '${name}' is held by no enabled package, and a ${verb} `
2944+
+ `that names none has ${single}.`,
2945+
) as Error & { code: 'RESOURCE_CONFLICT'; status: 409 };
2946+
err.code = 'RESOURCE_CONFLICT';
2947+
err.status = 409;
2948+
return err;
2949+
}
2950+
2951+
/**
2952+
* [ADR-0150 D3/D5 and red line 2] THE HOLDERS a write naming no package
2953+
* counts before it takes its address from the stored rows' bindings
2954+
* ({@link packagelessAddress}): the holders the read naming no package
2955+
* counts, so the bare save (publish and draft mode), the bare delete and the
2956+
* bare draft discard answer as the bare read does in the two states below,
2957+
* whether or not a row is stored at the address (over none, the delete and
2958+
* the discard are refused too, not answered the no-op receipt).
2959+
* Asked after {@link servedPackagelessSaveAddress} (a name an enabled and a
2960+
* disabled package both hold) and after the rows' own refusal (two or more
2961+
* bindings), so neither answer moves.
2962+
*
2963+
* - Two or more ENABLED packages hold the name: the package-scoped
2964+
* resolver's own refusal (`resolveItem` naming no package, the judgment
2965+
* the by-name read asks before any layer), restated as the write's
2966+
* refusal naming those packages. The rows' bindings alone picked the one
2967+
* package with a row, or wrote a package-unbound row beside both.
2968+
* - Every package holding the name is disabled (a registry holder, a code
2969+
* shipper or a stored row's binding; a row bound to a disabled holder's
2970+
* customization pair is that holder's): {@link disabledHoldersOnlyRefusal},
2971+
* naming no package. The write edited the disabled package's row, or
2972+
* stored a row every read then withholds.
2973+
* - `undefined` otherwise: no holder, one enabled holder, a package-unbound
2974+
* row stored at the address or the environment's own item (ADR-0150 D3
2975+
* (a): the row the write edits), a type the registry does not read by
2976+
* package, or a registry without the reads.
2977+
*
2978+
* Known gap: with an enabled and a disabled holder, the draft save and the
2979+
* delete have no {@link servedPackagelessSaveAddress} step and still take
2980+
* their address from the rows, and that step's own gap stands for the publish
2981+
* save. A follow-up card is filed.
2982+
*/
2983+
export function packagelessHolderRefusal(
2984+
host: Pick<ProtocolHost, 'engine' | 'shippedArtifactsOf'>,
2985+
verb: 'save' | 'delete',
2986+
shownType: string,
2987+
type: string,
2988+
name: string,
2989+
member: string | undefined,
2990+
address: { readonly candidates: readonly string[]; readonly unbound: boolean },
2991+
): (Error & { code: 'RESOURCE_CONFLICT'; status: 409 }) | undefined {
2992+
if (address.unbound) return undefined;
2993+
const registry = host.engine?.registry as HolderRegistry | undefined;
2994+
if (typeof registry?.readsByPackage !== 'function' || registry.readsByPackage(type) !== true) return undefined;
2995+
if (typeof registry.getEnvironmentScopedItem === 'function' && registry.getEnvironmentScopedItem(type, name, member) !== undefined) {
2996+
return undefined;
2997+
}
2998+
if (typeof registry.resolveItem === 'function') {
2999+
try {
3000+
registry.resolveItem(type, name, null, member);
3001+
} catch (error) {
3002+
const refusal = packageScopedRefusalOf(error);
3003+
if (refusal === undefined) throw error;
3004+
const held = refusal.reason === 'ambiguous-in-environment'
3005+
? refusal.candidates.flatMap((candidate) => (candidate.kind === 'package' ? [candidate.packageId] : []))
3006+
: [];
3007+
if (held.length > 1) return packagelessAddressAmbiguityRefusal(verb, shownType, name, held);
3008+
}
3009+
}
3010+
if (typeof registry.packageScopedHoldersOf !== 'function' || typeof registry.isPackageDisabled !== 'function') return undefined;
3011+
const disabled = (id: string): boolean => registry.isPackageDisabled?.(id) === true;
3012+
const known = [...new Set([
3013+
...(registry.packageScopedHoldersOf(type, name, null, { includeDisabledPackages: true }) ?? []),
3014+
...shippingPackageIds(host.shippedArtifactsOf(type, name)),
3015+
])];
3016+
const installed = installedManifestsOfEngine(host.engine);
3017+
const disabledHoldersPair = (id: string): boolean => known.some((holder) => disabled(holder) && pairsOf(holder, installed).includes(id));
3018+
const every = [...new Set([...known, ...address.candidates])];
3019+
if (every.length === 0 || every.some((id) => !disabled(id) && !disabledHoldersPair(id))) return undefined;
3020+
return disabledHoldersOnlyRefusal(verb, shownType, name);
3021+
}
3022+
3023+
/** The registry reads {@link packagelessHolderRefusal} asks, each optional-called. */
3024+
interface HolderRegistry {
3025+
readsByPackage?(type: string): boolean;
3026+
getEnvironmentScopedItem?(type: string, name: string, member?: string): unknown;
3027+
resolveItem?(type: string, name: string, callerPackageId: null, member?: string): unknown;
3028+
packageScopedHoldersOf?(type: string, name: string, callerPackageId?: string | null, options?: { includeDisabledPackages?: boolean }): readonly string[] | undefined;
3029+
isPackageDisabled?(id: string): boolean;
3030+
}

0 commit comments

Comments
 (0)