Skip to content

Commit b68f9ae

Browse files
fix(metadata-protocol): the bare save, delete, publish, draft and history doors follow the row-held base the bare read serves (#35450)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgPKDiLo5gfWzDLyAK6J6UjZ)_ Fixes #34681 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 1. 用户能看到什么变化:同一封邮件模板的同一语言版本,基座包和依赖它的包各存了一份时,不指定包去保存、存草稿、发布、看历史、比较版本、回滚、删除,以前一律被拒绝并要求说明是哪个包,现在都直接作用在打开时看到的基座包那一份上,依赖包那一份原样保留;不指定包连删两次,第一次删基座包那份,第二次删依赖包那份。对外的接口说明文字同步改写。 2. 为什么做:落实「同一个地址,读到谁就写谁」这条已定规则,删除、丢弃草稿、回滚三扇门按 Bill 12:03Z 的裁决(选 A,三扇门都跟随)一并跟随。 3. 出错会怎样:受影响的只是这种两份并存的模板;基座包未安装或只读时,按指定基座包的同一请求拒绝,不会写进去;撤回这次改动即恢复为原来的拒绝,不需要迁移数据。 4. 要你做什么:无,席位落地。 ## What changes The seven doors naming no package (save in publish and draft mode, per-item publish, delete and draft discard, and the history family: history, diff and rollback) now resolve their address the way the read naming no package does in this cell: a bundled type's name no package ships, held as stored rows at one member by a base package and a package that declares it. One helper, `packagelessRowHeldBaseAddress` in `protocol-save.ts`, asks the read's own judgment (`rowHeldBaseAddressOf`, unchanged) over the item's active rows, with the same guard the layered read uses (two or more bound holders, no package-less row, the base among them). Each door asks it only where it would otherwise refuse naming two or more packages (the history family through `historySlotOf`, its shared slot resolution), and then proceeds as the same request naming the base, judged as named (a base bound to an id no installed package has is refused `422 WRITABLE_PACKAGE_REQUIRED` at the draft save too, see the third round below): | Door (no package named) | `main` 8596c80 | This head | |:--|:--|:--| | save (REST `PUT` and in process) | 409 naming both | writes the base's row (writable base); 422 `WRITABLE_PACKAGE_REQUIRED` naming the base, as `?package=BASE` answers (read-only base) | | draft save | 409 naming both | writes the base's draft | | per-item publish | 409 naming both | promotes the base's draft | | history | 409 naming both | the base's versions, equal to `?package=BASE` | | diff | 409 naming both | compares the base's versions, equal to `?package=BASE` | | rollback | 409 naming both | restores the base's row to the base's own version; the receipt names the package (`(package=BASE)`), as the delete's does | | delete / draft discard | 409 naming both | removes the base's row / draft; the receipt names the dependent's row as remaining; a second bare delete removes the dependent's row | The dependent's row is untouched and still read and written at its own `?package=`. The destructive doors (delete, draft discard, rollback) follow the base by the maintainer's ruling (S2, option A, comment 7008542936). **Third round (contract review 7008272548 and ruling 7008542936):** - **S1.** A bare draft save that follows the base now judges it with the named-base rule (#26921) and the late override re-judgment, as the save naming it is: the follow arm keeps the base in `followedBase` and both sites read it, where before they read the cleared draft address and judged nothing. Cell: the base's rows bound to an id no installed package has, which an installed dependent declares. Before: bare draft save 200, writing a draft bound to that id; now 422 `WRITABLE_PACKAGE_REQUIRED` naming it, as `?package=BASE` and the bare publish-mode save answer. - **Rider 1.** The rollback receipt's `message` names the package of the row it restored (` (package=ID)`), in the delete receipt's spelling. - **M1.** `packages/spec/src/api/protocol.zod.ts`: the `packageId` descriptions of the save (active and draft), the per-item publish, the delete, and `HISTORY_PACKAGE_SELECTOR_DESCRIPTION` (history, diff, rollback) now state the row-held base exception, that two packages neither of which declares the other are still refused `409`, and, on the delete, that a second bare delete removes the dependent's row and the base's copy comes back only by saving it again. `gen:schema` and `gen:docs` regenerated `content/docs/references/api/protocol.mdx`. Description text only; no shape, key or accepted value moves. - **S3.** Comment-only: the `packagelessAddress`, `packagelessDraftAddress`, `historyMetaItem` and `rollbackMetaItem` docblocks in `protocol.ts` and the `protocol-history-slots.ts` module header no longer say the bare doors refuse this cell. Files: `packages/metadata-protocol/src/protocol-save.ts` (the helper; the publish-mode and draft-mode address), `protocol-diff-delete-load.ts` (delete and discard), `protocol-history-and-publish.ts` (publish), `protocol-history-slots.ts` (`historySlotOf`: history, diff and rollback); host `Pick` lists widened by the members the read's judgment reads (one line each in the history, diff and rollback doors, the rollback's in `protocol-package-commits.ts`). Comment-only: the `packagelessLayeredReadRefusal` docblock in `protocol.ts` and the `rowHeldBaseAddressOf` docblock in `protocol-meta-item-face.ts` now say the writes follow the base (claim amendment 7005577225), plus the S3 docblocks above. `protocol-lock-version-gates.ts` needed no edit. No file seat 4's PR touched; under `packages/spec` only `protocol.zod.ts`'s five descriptions (claim amendment in 7008542936). Changesets: `.changeset/34681-bare-write-doors-follow-base.md` (`@objectstack/metadata-protocol` patch) and `.changeset/34681-spec-bare-doors-follow-base.md` (`@objectstack/spec` patch), each with `Clause-②: yes (widening)` and `Metadata-protocol: none`. Pins: `packages/runtime/src/domains/meta-bare-write-doors-follow-base-34681.test.ts` (new file, named for this card; the shared harness file `meta-disabled-holder-served-stack.test.ts` is fenced for this card). ## Tests <details><summary>Readings on `main` 8596c80 before the change (A1), through the real protocol on a booted kernel</summary> Bare read 200 `base en` at the base. Each bare door, code (read-only) pair and authored (writable) pair alike: save 409, draft save 409, publish 409, history 409, delete 409, draft discard 409, every message naming both packages. `?package=BASE` (authored base) save: 200 into the base's row. Diff and rollback, measured on branch head 90d943c before their change (the new diff and rollback pins run against that build): each 409 RESOURCE_CONFLICT naming both packages (`Tests 2 failed | 5 passed (7)`). </details> <details><summary>Third round, RED before the fixes (the build at `aa1df8a4`, new pins added first)</summary> `Tests 3 failed | 9 passed (12)`: - S1: the base bound to `com.qa.ghostbase` (no installed package has it), declared by the installed `com.qa.ghostaddon`. `?package=` naming it and the bare publish-mode save answered `422 WRITABLE_PACKAGE_REQUIRED`; the bare draft save answered 200, `Saved email_template 'ghost_mail' (env-wide, package=com.qa.ghostbase, state=draft)`. - Rider 1: the bare rollback's receipt read `Reverted to version 1 — type=email_template, name=rb_mail [seq=16]`, no package. - N2's REST `DELETE` pin: `405 METHOD_NOT_ALLOWED` (`use GET, HEAD, PUT`). The `HttpDispatcher` metadata-item route does not mount `DELETE` (`domains/meta.ts` says mounting it needs its own card), so the pin was dropped, not the door; see Acceptance notes. </details> <details><summary>Pins at the final head: 11/11 pass</summary> `pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/domains/meta-bare-write-doors-follow-base-34681.test.ts` → `Tests 11 passed (11)`. Added this round: the uninstalled base (S1), two bare deletes in a row, the bare draft read beside the bare discard (the dependent's draft stored first, so a first-match read would meet it first; the read serves the base's draft with a version token), the destructive doors under a read-only base (bare delete, draft discard and rollback each answer what `?package=BASE` answers, never `409`), the rollback receipt's package, and a bare read after the bare publish. </details> <details><summary>Ablation (one-shot, not kept)</summary> Round 3, each through `scripts/ablation-replace.mjs`, rebuilt, `ablation-dist-preflight` checked, then the pin file: - S1: `followedBase = base;` deleted (anchor 1 → 0, blob e8a6970 → fb961e6f), dist marker absent: `Tests 1 failed | 10 passed (11)`, the uninstalled-base pin red. - Rider 1: the receipt's package clause replaced (blob 3445e11 → 73848178), dist marker present in 2 built files: `Tests 1 failed | 10 passed (11)`, the rollback pin red. - The helper answering no base (main's behaviour at every door; blob e8a6970 → 4364e64b, marker present in 2 built files): `Tests 9 failed | 2 passed (11)`; every moved pin red, including the four rider-2 pins; the shipped-base neighbour and the controls green. A first attempt used a comment marker the bundle strips: the preflight refused it before any test ran, so that leg was a no-op and was re-run with a marker that survives. - Restored each: blob == HEAD, `git diff HEAD` empty, `git status --porcelain` empty, rebuilt, preflight `--absent` clean, `Tests 11 passed (11)`. Round 2, the `historySlotOf` site: its follow-the-base `return` replaced so it never fires (anchor 1 → 0, blob 3106fd3 → 9365a157), rebuilt, marker present in 2 built files: `Tests 3 failed | 4 passed (7)`, the history, diff and rollback pins red, the rest green. Restored: blob == HEAD 3106fd3, `git diff HEAD` empty, rebuilt, preflight `--absent` clean, `Tests 7 passed (7)`. Round 1, the helper itself: Mutation through `scripts/ablation-replace.mjs`: the helper's final `return` replaced so it never answers a base (anchor 1 → 0, blob 517f041 → aec26a74), `@objectstack/metadata-protocol` rebuilt, `ablation-dist-preflight` marker present in 2 built files. Run: `Tests 3 failed | 2 passed (5)`: the three moved pins went red (first failure: the REST `PUT` answered 409 where 200 is pinned); the neighbour reading and the controls stayed green, as expected. Restored: blob == HEAD 517f041, `git diff HEAD` empty, rebuilt, preflight `--absent` clean, `Tests 5 passed (5)`. </details> ## Acceptance notes - **A2, the shipped-base neighbour (measured, unchanged, pinned).** The base ships the member in code and the dependent stores a row of it: the bare read serves the base's code item, and the bare save is refused `403 NOT_OVERRIDABLE` toward `BASE.custom`, writing nothing (the package-less write is closed for a shipped name, ADR-0146 D11). The predicted disagreement (the save landing in the dependent's row) does not occur on `main` or here. - **A3, read after the bare delete (measured, pinned).** Once the bare delete removes the base's row, the bare read serves the dependent's row (200, `packageId` = dependent). Not silent: the delete receipt says the item still exists and names the dependent's row as remaining. - **Read-only base.** Where the base is a code or installed package, the bare save now answers what naming the base answers (`422 WRITABLE_PACKAGE_REQUIRED` naming the base) instead of `409` naming both, and so do the bare delete, draft discard and rollback (pinned equal to `?package=BASE`). - **Destructive doors (S2, ruled).** Bill picked option A at 12:03Z (comment 7008542936): the bare delete, draft discard and rollback follow the row-held base. The accepted consequence is pinned: a second bare delete removes the dependent's row, and the base's copy comes back only by saving it again. The spec delete text states it. - **N1, wording.** The per-item publish naming no package still states no package to the runtime authoring gate, as every bare publish does; the changeset says so instead of "exactly as named". - **N2.** The REST `DELETE` door is not mounted on this transport (`405`), so the REST pin stays on `PUT`; the delete is pinned in process. Mounting `DELETE` there is a public-surface change for its own card, not this one. - **Not moved (CONTROLS, pinned):** two holders with no base relation, a package-less row beside the holders, and a type with no members still refuse `409` naming every holder; `?package=` still writes where it names. - **Same family, moved here (claim amendment 7005577225):** the bare diff and the bare rollback follow the base through `historySlotOf`, pinned beside the first five doors. The two contract docblocks that said the writes do not follow the base are rewritten in the same PR. - **Neighbour defect, reported for filing, left to the area:** a dependent's non-canonical member over a base holding only the canonical member (the base's `en-US` row, the dependent's `fr-FR` row): the bare read at `fr-FR` answers 404, the bare save of `fr-FR` writes the dependent's row (200), and the bare read at `fr-FR` then answers 409. Present on `main` 8596c80, untouched here. ## Verification Third round at head `914e61af` (merge base with `origin/main` 6f36818; `overlap-check` against `origin/main` 819c067). The suites ran at `531d0988`; `914e61af` only re-flows four docblocks in `protocol.ts` (comments), after which the facade ratchet and the other ratchets were re-run. <details><summary>Local subset, each exit captured before any pipe</summary> - `pnpm --filter @objectstack/metadata-protocol exec vitest run --maxWorkers=2`: exit 0, `Test Files 360 passed | 9 skipped (369)`, `Tests 23249 passed | 45 skipped (23294)`. - `pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2` on the pin file plus `meta-disabled-holder-served-stack.test.ts` and `meta-bundle-member-one-request.test.ts`: exit 0, `Test Files 3 passed (3)`, `Tests 173 passed (173)`. - `pnpm --filter @objectstack/spec exec vitest run --maxWorkers=2`: exit 0, `Test Files 947 passed (947)`, `Tests 28933 passed | 1 todo (28934)`. - Typecheck: `@objectstack/metadata-protocol`, `@objectstack/runtime` (tsc plus `check:test-typecheck`) and `@objectstack/spec`: each exit 0. - `gen:schema` and `gen:docs`: exit 0; they changed only `content/docs/references/api/protocol.mdx`, committed. - Derived gate families (`dispatch-gates.mjs --commands`, 120): 118 exit 0; `check:dual-build-cjs-loads` and `check:skill-examples` exit 3, PREREQUISITE NOT MET (no full build here), NOT MEASURED locally and left to CI. `check:facade-delegation-only` was red in the first pass (`protocol.ts` 11717 lines over its ceiling 11705, from the S3 docblocks); the docblocks were re-flowed line-neutral and the gate re-run at `914e61af`: exit 0. `--ran` reconciliation: 120 derived, 118 run, 2 NOT-MEASURED, 0 UNRUN. - Re-run at `914e61af`: `check:facade-delegation-only`, `check:query-options-erasure` (236 sites, at the ceiling), `check:nul-bytes`, `@objectstack/spec check:generated` (all 14 artifacts current; a first run without the 4096 MB heap cap died in `tsc` with no diagnostics, re-run with it: exit 0). Each exit 0. - `overlap-check.mjs --branch=HEAD`: `VERDICT clean`, against `origin/main` and #35459. - `test:repo` not run locally (no file of that project changed); CI's `Test Core` runs it. </details> ## 席位核对 - Read first: `protocol-save.ts` (`packagelessRowHeldBaseAddress`, the draft-mode follow arm with `followedBase`, and the two sites that read it), `packages/spec/src/api/protocol.zod.ts` (the five descriptions), `protocol-diff-delete-load.ts` (the two address sites in the delete). - Two-minute check: `pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/domains/meta-bare-write-doors-follow-base-34681.test.ts`, expect `Tests 11 passed (11)` (after `pnpm --filter @objectstack/metadata-protocol build`). - Dogfood battery: not owed (no `!` in the title, the arm is `(widening)`). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Utp6CbP6iSEGkWb5fn8yqd <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6CbP6iSEGkWb5fn8yqd --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent c890070 commit b68f9ae

12 files changed

Lines changed: 622 additions & 76 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
fix(metadata-protocol): the save, delete, publish, draft, history, diff and rollback doors naming no package write and read the base's row where the read naming no package serves it
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: none
9+
10+
A bundled item (an email template's locale, for example) that no package ships in code can be stored as a row by a base package and, at the same member, by a package that declares that base. The read naming no package already serves the base's row there. The write doors naming no package now resolve the same address: the save (publish and draft mode), the per-item publish, the delete and the draft discard act on the base's row or draft, and the history, the diff and the rollback read and restore the base's own versions, as the same request naming the base (`?package=` on the REST door, `packageId` in process) does. The base is judged as named: bound to an id no installed package has, the save in either mode is refused `422 WRITABLE_PACKAGE_REQUIRED`. (The per-item publish naming no package still states no package to the runtime authoring gate, as every publish naming no package does.) Before, each was refused `409 RESOURCE_CONFLICT` naming both packages, so an item that opened fine could not be saved.
11+
12+
The dependent package's row stays where it is and is still read and written at its own `?package=`. Where the base is read-only, the save, the delete, the draft discard and the rollback now answer what naming the base answers (for the save, `422 WRITABLE_PACKAGE_REQUIRED` naming the base) instead of the `409`. After a delete naming no package removes the base's row, the read naming no package serves the dependent's row, and the delete's receipt names it as still stored; a second delete naming no package removes the dependent's row too, and the base's copy comes back only by saving it again. The rollback's receipt now names the package of the row it restored, as the delete's receipt does.
13+
14+
Unchanged: two packages holding the member with neither declaring the other, a package-less row beside the holders, and a type with no members are still refused `409` naming every holder.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/spec': patch
3+
---
4+
5+
docs(spec): the request texts state that a request naming no package follows the row-held base
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: none
9+
10+
The `packageId` descriptions of the save, draft save, per-item publish, delete and history/diff/rollback requests (`HISTORY_PACKAGE_SELECTOR_DESCRIPTION`) said a request naming no package is refused `409 RESOURCE_CONFLICT` wherever an item's active rows are bound to two or more packages. They now state the exception the server answers: a bundled type's member that a base package and a package declaring it both hold, with no package-unbound row beside them, is the row-held base's, as the read naming no package serves it, and the request addresses the base's row, draft or versions as naming the base does. Two packages neither of which declares the other are still refused `409`. The delete text states the consequence: the dependent's row is served next, a second delete naming no package removes it too, and the base's copy comes back only by saving it again. Description text only; no schema shape, key or accepted value moves.

‎content/docs/references/api/protocol.mdx‎

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

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

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +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';
69+
import { packagelessHolderRefusal, packagelessRowHeldBaseAddress } from './protocol-save.js';
7070

7171
/**
7272
* [#33308] The row slot a `sys_metadata` row is: its bound package, or `null`
@@ -79,7 +79,7 @@ function rowSlotOf(row: { package_id?: unknown }): string | null {
7979

8080
export class ProtocolDiffDeleteLoadFacet {
8181
/** The body of `ObjectStackProtocolImplementation#diffMetaItem`; the method's docblock there is its contract. */
82-
static async diffMetaItem(host: Pick<ProtocolHost, 'diffMetaItem' | 'engine' | 'findEnvironmentRow' | 'findEnvironmentRows' | 'findServedOverlayRow' | 'packagelessAddress' | 'resolveRowlessExpandedView' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'shippedArtifactsOf'>, request: {
82+
static async diffMetaItem(host: Pick<ProtocolHost, 'declinesStoredRow' | 'diffMetaItem' | 'engine' | 'findEnvironmentRow' | 'findEnvironmentRows' | 'findServedOverlayRow' | 'packagelessAddress' | 'readItemActiveRows' | 'resolveRowlessExpandedView' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'shippedArtifactsOf'>, request: {
8383
type: string;
8484
name: string;
8585
fromVersion?: number;
@@ -454,7 +454,7 @@ export class ProtocolDiffDeleteLoadFacet {
454454
}
455455

456456
/** [#28355] The body of {@link deleteMetaItem} before its refusal audit; that method's docblock is the contract. */
457-
static async deleteMetaItemUnaudited(host: Pick<ProtocolHost, 'assertLockAllowsDelete' | 'dropObjectStorage' | 'dropStorageRemainingRowsRefusal' | 'emitMetadataMutation' | 'engine' | 'environmentId' | 'findEnvironmentRow' | 'getOverlayRepo' | 'isArtifactBacked' | 'isOverlayAllowed' | 'isRuntimeCreateAllowed' | 'metadataConflictRefusal' | 'originGatedRemovalRefusal' | 'packagedArtifactOwner' | 'packagedBaseRefusal' | 'packagelessAddress' | 'packagelessDraftAddress' | 'packagelessOverlayWriteRefusal' | 'recordMetadataAudit' | 'recordOptimisticConflictAudit' | 'refuseOrganizationScopedWrite' | 'refusePackagedBaseRemoval' | 'registryAllowsOverlay' | 'restoreArtifactRegistryView' | 'runMutationProjector' | 'shippedArtifactsOf' | 'shouldDropStorage' | 'storedParentForToken'>, request: DeleteMetaItemRequest): Promise<{
457+
static async deleteMetaItemUnaudited(host: Pick<ProtocolHost, 'assertLockAllowsDelete' | 'declinesStoredRow' | 'dropObjectStorage' | 'dropStorageRemainingRowsRefusal' | 'emitMetadataMutation' | 'engine' | 'environmentId' | 'findEnvironmentRow' | 'getOverlayRepo' | 'isArtifactBacked' | 'isOverlayAllowed' | 'isRuntimeCreateAllowed' | 'metadataConflictRefusal' | 'originGatedRemovalRefusal' | 'packagedArtifactOwner' | 'packagedBaseRefusal' | 'packagelessAddress' | 'packagelessDraftAddress' | 'packagelessOverlayWriteRefusal' | 'readItemActiveRows' | 'recordMetadataAudit' | 'recordOptimisticConflictAudit' | 'refuseOrganizationScopedWrite' | 'refusePackagedBaseRemoval' | 'registryAllowsOverlay' | 'restoreArtifactRegistryView' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'runMutationProjector' | 'shippedArtifactsOf' | 'shouldDropStorage' | 'storedParentForToken'>, request: DeleteMetaItemRequest): Promise<{
458458
success: boolean;
459459
message?: string;
460460
reset?: boolean;
@@ -713,23 +713,39 @@ export class ProtocolDiffDeleteLoadFacet {
713713
// door orders it. The rows read here are also what the receipt
714714
// below tells the truth about: what is still stored, and so
715715
// still served, once this row is gone.
716-
const draftAddress = request.packageId == null && targetState === 'draft'
716+
//
717+
// [#34681] …except where the read naming no package serves the
718+
// row-held base of rows bound to two or more packages
719+
// ({@link packagelessRowHeldBaseAddress}): the delete and the
720+
// draft discard remove the base's row or draft, as the request
721+
// naming that base does, and the dependents' rows stay (the
722+
// receipt below names them).
723+
let draftAddress = request.packageId == null && targetState === 'draft'
717724
? await host.packagelessDraftAddress(singularTypeForRepo, request.name, member)
718725
: undefined;
719726
if (draftAddress?.kind === 'ambiguous') {
720-
addressRefusal = packagelessAddressAmbiguityRefusal(
721-
'delete', request.type, request.name, draftAddress.candidates,
722-
);
723-
throw addressRefusal;
727+
const base = await packagelessRowHeldBaseAddress(host, singularTypeForRepo, request.name, member);
728+
if (base === undefined) {
729+
addressRefusal = packagelessAddressAmbiguityRefusal(
730+
'delete', request.type, request.name, draftAddress.candidates,
731+
);
732+
throw addressRefusal;
733+
}
734+
request = { ...request, packageId: base };
735+
draftAddress = undefined;
724736
}
725737
const rowsAtAddress = draftAddress?.drafts ?? await host.packagelessAddress(
726738
singularTypeForRepo, request.name, member, targetState,
727739
);
728740
if (request.packageId == null && draftAddress === undefined && rowsAtAddress.candidates.length > 1) {
729-
addressRefusal = packagelessAddressAmbiguityRefusal(
730-
'delete', request.type, request.name, rowsAtAddress.candidates,
731-
);
732-
throw addressRefusal;
741+
const base = await packagelessRowHeldBaseAddress(host, singularTypeForRepo, request.name, member);
742+
if (base === undefined) {
743+
addressRefusal = packagelessAddressAmbiguityRefusal(
744+
'delete', request.type, request.name, rowsAtAddress.candidates,
745+
);
746+
throw addressRefusal;
747+
}
748+
request = { ...request, packageId: base };
733749
}
734750
// [ADR-0150 D3/D5, red line 2, ruling A] …and the holders the
735751
// read naming no package counts, as the save door asks them

‎packages/metadata-protocol/src/protocol-history-and-publish.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import type { MutationProjectionOutcome } from './protocol-mutation-events.js';
4545
import { PREFLIGHT_AUDIT_CODE, withPendingAudit } from './protocol-audit-entry.js';
4646
import type { PublishMetaItemRequest } from './protocol-door-requests.js';
4747
import { withRefusalAudit } from './protocol-refusal-audit.js';
48-
import { environmentActionPublishSlotRefusal } from './protocol-save.js';
48+
import { environmentActionPublishSlotRefusal, packagelessRowHeldBaseAddress } from './protocol-save.js';
4949
import { overlayMemberWhere } from './migrations/overlay-index.js';
5050
import { isMissingTableError } from '@objectstack/metadata/errors';
5151
import { readPublishBackfillRequest } from './protocol-publish-backfill-request.js';
@@ -202,7 +202,7 @@ async function undoLandedPromotions(host: Pick<ProtocolHost, 'engine' | 'isArtif
202202

203203
export class ProtocolHistoryAndPublishFacet {
204204
/** The body of `ObjectStackProtocolImplementation#historyMetaItem`; the method's docblock there is its contract. */
205-
static async historyMetaItem(host: Pick<ProtocolHost, 'engine' | 'findServedOverlayRow' | 'getOverlayRepo' | 'historyMetaItem' | 'isOverlayAllowed' | 'isRuntimeCreateAllowed' | 'packagelessAddress' | 'resolveRowlessExpandedView' | 'shippedArtifactsOf' | 'storedHashDigest'>, request: {
205+
static async historyMetaItem(host: Pick<ProtocolHost, 'declinesStoredRow' | 'engine' | 'findServedOverlayRow' | 'getOverlayRepo' | 'historyMetaItem' | 'isOverlayAllowed' | 'isRuntimeCreateAllowed' | 'packagelessAddress' | 'readItemActiveRows' | 'resolveRowlessExpandedView' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'shippedArtifactsOf' | 'storedHashDigest'>, request: {
206206
type: string;
207207
name: string;
208208
sinceSeq?: number;
@@ -278,6 +278,8 @@ export class ProtocolHistoryAndPublishFacet {
278278
// holders' rows hold is refused naming both when no package is named,
279279
// and `?package=` reads that holder's versions alone. A name one slot
280280
// holds, named bare, reads its whole log as before.
281+
// [#34681] A row-held base's name, named bare, reads that base's
282+
// versions, as `?package=` naming it does ({@link historySlotOf}).
281283
const slot = await historySlotOf(host, {
282284
type: singularType, name: request.name, ...memberOption(member),
283285
...(request.packageId !== undefined ? { packageId: request.packageId } : {}),
@@ -671,7 +673,7 @@ export class ProtocolHistoryAndPublishFacet {
671673
* `recordPendingDenialAudit`, rethrow. Skip it and the refusal is silent
672674
* again — the pre-#7748 state, not merely a worse one.
673675
*/
674-
static async promoteDraftForPublish(host: Pick<ProtocolHost, 'anonymousElevatedFlowRefusal' | 'assertRuntimeAuthoringRules' | 'classifyObjectContribution' | 'credentialChannelFor' | 'defaultRecordPageSaveRefusal' | 'engine' | 'ensureOverlayIndex' | 'externalBindingSaveRefusal' | 'getOverlayRepo' | 'isArtifactBacked' | 'isOverlayAllowed' | 'isRuntimeCreateAllowed' | 'isSealedManagedItem' | 'lockWriteRefusal' | 'metadataConflictRefusal' | 'namedBaseOverlayWriteRefusal' | 'objectExtensionItemRefusal' | 'objectNamespaceObjectNameClash' | 'objectNamespacePrefixViolation' | 'objectRegistrationRefusal' | 'optimisticConflictAuditEntry' | 'overlayPackageMismatchError' | 'overrideWriteVerdict' | 'packagelessAddress' | 'packagelessDraftAddress' | 'permissionSetNameCollisionRefusal' | 'readItemActiveRows' | 'resolveSduiManifest' | 'seedExternalIdSaveRefusal' | 'uninstalledNamedBaseRefusal' | 'unknownDatasourceSaveRefusal' | 'unknownGrantObjectSaveRefusal' | 'unknownPicklistBindingSaveRefusal'>, request: {
676+
static async promoteDraftForPublish(host: Pick<ProtocolHost, 'anonymousElevatedFlowRefusal' | 'assertRuntimeAuthoringRules' | 'classifyObjectContribution' | 'credentialChannelFor' | 'declinesStoredRow' | 'defaultRecordPageSaveRefusal' | 'engine' | 'ensureOverlayIndex' | 'externalBindingSaveRefusal' | 'getOverlayRepo' | 'isArtifactBacked' | 'isOverlayAllowed' | 'isRuntimeCreateAllowed' | 'isSealedManagedItem' | 'lockWriteRefusal' | 'metadataConflictRefusal' | 'namedBaseOverlayWriteRefusal' | 'objectExtensionItemRefusal' | 'objectNamespaceObjectNameClash' | 'objectNamespacePrefixViolation' | 'objectRegistrationRefusal' | 'optimisticConflictAuditEntry' | 'overlayPackageMismatchError' | 'overrideWriteVerdict' | 'packagelessAddress' | 'packagelessDraftAddress' | 'permissionSetNameCollisionRefusal' | 'readItemActiveRows' | 'resolveSduiManifest' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'seedExternalIdSaveRefusal' | 'shippedArtifactsOf' | 'uninstalledNamedBaseRefusal' | 'unknownDatasourceSaveRefusal' | 'unknownGrantObjectSaveRefusal' | 'unknownPicklistBindingSaveRefusal'>, request: {
675677
type: string; name: string; actor?: string; message?: string;
676678
/**
677679
* [#8907] ADR-0048 — the package binding of the draft being promoted,
@@ -834,7 +836,17 @@ export class ProtocolHistoryAndPublishFacet {
834836
// is the 503 the lock read raised before this read moved above it
835837
// ({@link packagelessAddress} discriminates both).
836838
const address = await host.packagelessDraftAddress(singularType, request.name, request.member);
837-
if (address.kind === 'ambiguous') {
839+
// [#34681] Active rows bound to two or more packages where the read
840+
// naming no package serves the row-held base: the base's draft, as
841+
// the publish naming that base promotes it
842+
// ({@link packagelessRowHeldBaseAddress}).
843+
const base = address.kind === 'ambiguous'
844+
? await packagelessRowHeldBaseAddress(host, singularType, request.name, request.member)
845+
: undefined;
846+
if (base !== undefined) {
847+
draftKey = base;
848+
promoteInto = base;
849+
} else if (address.kind === 'ambiguous') {
838850
draftKey = null;
839851
promoteInto = null;
840852
addressRefusal = packagelessAddressAmbiguityRefusal('publish', request.type, request.name, address.candidates);

‎packages/metadata-protocol/src/protocol-history-slots.ts‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
* by more than one row slot — two packages', or a package's beside the
1818
* package-less row — is refused `409` naming every holder
1919
* (`ambiguous-in-environment`), before any row is read or written: nothing
20-
* picks one (ADR-0150 D3, epic red line 2). So is a name the bare plain
20+
* picks one (ADR-0150 D3, epic red line 2), except where the bare read
21+
* serves the row-held base (#34441 cell 2): there the door addresses the
22+
* base's slot, as naming the base does (#34681,
23+
* `packagelessRowHeldBaseAddress`). So is a name the bare plain
2124
* read refuses (ADR-0150 D5: a holder in code counts, so two packages
2225
* shipping the name are two holders while only one has saved a row): the
2326
* registry's resolver (`resolveItem`, the one the plain read asks) throws
@@ -58,6 +61,7 @@ import type { ProtocolHost } from './protocol-host.js';
5861
import { memberOption } from './protocol-bundle-members.js';
5962
import { shippingPackageIds } from './protocol-environment-rows.js';
6063
import type { HistoryVersionOwner } from './sys-metadata-repository.js';
64+
import { packagelessRowHeldBaseAddress } from './protocol-save.js';
6165

6266
/** What {@link historySlotOf} answers for a door of a by-package type. */
6367
export interface HistorySlot {
@@ -153,21 +157,31 @@ function refuseWhereBareReadRefuses(host: Pick<ProtocolHost, 'engine'>, type: st
153157
* before.
154158
* @throws a `400 VALIDATION_ERROR` for `?package=` on a type not stored per
155159
* `(package, name)`.
160+
* [#34681, epic ruling 6781691009] A bare request of a name whose rows at the
161+
* member the read naming no package serves at the row-held base
162+
* ({@link packagelessRowHeldBaseAddress}) addresses that base's slot, as the
163+
* same request naming it does: the history, diff and rollback naming no
164+
* package read and restore the base's versions, never another holder's.
165+
*
156166
* @throws {PackageScopedNameRefusedError} `ambiguous-in-environment` for a
157-
* bare request of a name two or more row slots hold, or the bare plain
158-
* read's own refusal; `not-held-by-qualifier` for a package that neither
167+
* bare request of a name two or more row slots hold (other than a row-held
168+
* base's, above), or the bare plain read's own refusal; `not-held-by-qualifier` for a package that neither
159169
* holds a row of the name nor ships it, while another slot holds one.
160170
*/
161171
export async function historySlotOf(
162-
host: Pick<ProtocolHost, 'engine' | 'findServedOverlayRow' | 'packagelessAddress' | 'shippedArtifactsOf'>,
172+
host: Pick<ProtocolHost, 'declinesStoredRow' | 'engine' | 'findServedOverlayRow' | 'packagelessAddress' | 'readItemActiveRows' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'shippedArtifactsOf'>,
163173
request: { type: string; name: string; member?: string; packageId?: string },
164174
): Promise<HistorySlot | undefined> {
165175
const { type, name, member, packageId } = request;
166176
refusePackageSelectorOutsideSlottedTypes(type, packageId);
167177
if (!PACKAGE_SLOTTED_STORE_TYPES.has(type)) return undefined;
168178
const slots = await rowSlotsOf(host, type, name, member);
169179
if (packageId === undefined) {
170-
if (slots.length > 1) throw slotRefusal(type, name, 'ambiguous-in-environment', null, slots);
180+
if (slots.length > 1) {
181+
const base = await packagelessRowHeldBaseAddress(host, type, name, member);
182+
if (base !== undefined) return historySlotOf(host, { ...request, packageId: base });
183+
throw slotRefusal(type, name, 'ambiguous-in-environment', null, slots);
184+
}
171185
refuseWhereBareReadRefuses(host, type, name, member);
172186
if (slots.length === 0) return undefined;
173187
return { owner: { packageId: slots[0] ?? null, sole: true }, addressed: false, held: true };

0 commit comments

Comments
 (0)