Skip to content

Commit fd06b11

Browse files
fix(metadata-protocol)!: a save naming no package at a bundle member only the dependent holds writes the row-held base's row the bare read addresses (#37069)
<!-- claude-projects-attribution: {"github_login":"huangyiirene"} --> _Requested by **Irene** · [project thread](https://claude.ai/code/project/chan_01TJXtQ1tVD26ecLDZxFS67x?thread=cmsg_01TJXtQ1tVD26ecLDZxFS67x8Be2AAcUBhodBsvnWLd3Xs)_ Fixes #35524 Clause-②: no (narrowing) Metadata-protocol: none Skills-docs: none — the moved cell is an authored (row-held) base with an email_template locale only its dependent stores; no skills/** or content/docs page teaches where a save naming no package lands there, and skills/objectstack-platform/SKILL.md's customization paragraph covers the code-shipped base, whose bare save this diff leaves unchanged (pinned in the new test's controls); the spec packageId sentence is #35529's ## 维护者速读 1. 用户能看到什么变化:同一封邮件模板,基座包存了英文版、依赖它的包只存了法文版时,不指定包去保存法文版(直接保存或存草稿),以前改的是依赖包那一份、随后按名字读法文版仍显示“找不到”;现在写进基座包的法文版,与指定基座包保存完全一样,依赖包那一份原样保留,保存后按名字一读就能看到刚存的内容;不指定包的读草稿、发布草稿、丢弃草稿也一并对准基座包那份草稿;法文版此前留有一份不属于任何包的草稿时同样如此,那份旧草稿原样保留。 2. 为什么做:落实「同一个地址,读到谁就写谁」这条已定规则,补上“基座包和依赖包同名邮件模板”这一类里尚未覆盖的一格。 3. 出错会怎样:只影响基座包和依赖包都存了同一邮件模板、且某语言只有依赖包有的环境;基座包没有草稿时,不指定包发布会被拒,丢弃则不动并说明还剩哪份草稿,与指定基座包的回答一致;可直接撤回本次改动,不需要迁移数据。 4. 要你做什么:无。 ## What changes At a named non-canonical member of a bundled type's name no package ships (today `email_template`, e.g. `fr-FR`), where an authored base package holds a stored row of the item at some member (its canonical member, or another one such as `de-DE`) and only a package declaring that base holds a row of the member, the read naming no package takes the base's address (`rowHeldBaseAddressOf`, the S1-guarded arm; unchanged, pinned in `meta-disabled-holder-served-stack.test.ts` M1, M2, S2) and answers 404. The doors naming no package that write or address that member's draft now resolve the same address: - `packagelessRowHeldBaseAddress` (`protocol-save.ts`) also answers the base where the member's active rows are bound to exactly one package, that package is not the base, and the read's own judgment names the base (`rowHeldBaseAddressOf`, asked, not copied). Two or more holders answer exactly as before (#34681). - The publish-mode save naming no package asks it in its one-holder branch (after the holder refusal, so every refusal stands) and writes as the save naming the base does. - The draft doors' address naming no package (`packagelessDraftAddress`, behind the draft save, the strict draft read, the per-item publish and the draft discard) is wrapped by the new `packagelessRowHeldBaseDraftAddress`: at this cell it answers the base's draft, promoted into the base's row. The draft save sets the base as its package (the repository otherwise resolves its own write head), as the #34681 follow arm does, so the named-base rule and the late override re-judgment judge the base. - Contract review S2, option (b) (the seat's route; it replaces the S1 option (a) exemption of the previous head): the package-unbound draft sub-cell moves to the base like the rest of the cell. Where the stored draft address names the package-unbound draft (`key === null`: a package-unbound draft stored at the member with no draft of the dependent beside it, as a bare draft save writes it while no package holds the member), the wrapper still answers the base's address (`none` until the base holds a draft there), and the draft save's follow still names the base. One predicate, `draftAddressFollowsRowHeldBase` (now `into !== null`), is asked by both, so they cannot part. The draft save passes the base to the repository, so the orphan-draft adoption (a save naming no package) does not run: the package-unbound draft stays untouched, as the save naming the base leaves it. Under the S1 exemption the bare draft save adopted that draft into the dependent, after which the bare draft read missed the draft just saved (S2). - The draft discard naming no package at that sub-cell (`protocol-diff-delete-load.ts`): with no base draft it answers the receipt the discard naming the base answers, naming the package-unbound draft still stored (`receiptPackageId`), never `No pending draft for TYPE/NAME.` while a draft is stored. Only the moved address is `none` with a package-unbound draft stored (`packagelessDraftAddress` otherwise makes that draft the address itself), so no other cell's receipt changes. Ruling route: the write follows the read (epic ruling 6781691009, 「a write resolves its address exactly as the read at the same address resolves it」; #34348 ruling (b), 「reads and writes give the same answer」). The read is not changed. FROM to TO (BREAKING, the narrowing arm): - bare save (REST `PUT`, in process), `active`: the dependent's row silently updated, read after it 404 (or 409) → the base's row written at the member, as `?package=BASE` writes it; the dependent's row byte-unchanged; read after it 200 at the base. - bare draft save: the dependent's draft → the base's draft, as `?package=BASE`. - bare draft read / per-item publish / draft discard: the dependent's draft read, promoted, removed → the base's draft read, promoted, removed. With only the dependent's draft stored: publish 200 into the dependent's row → `404 NO_DRAFT` naming that draft; discard removed it → `200` receipt that discards nothing and names the remaining draft. Both equal the same request naming the base. - the package-unbound draft sub-cell: bare draft read served it, bare publish promoted it into the dependent's row, bare discard removed it, bare draft save adopted it into the dependent's draft → bare draft save writes the base's draft beside it (untouched) and the bare draft read reads back what was saved; bare publish after that save promotes the base's draft; a second bare draft save updates the base's draft (no second draft); with no base draft, the bare draft read still serves the package-unbound draft, bare publish `404 NO_DRAFT` and bare discard a `200` receipt naming the package-unbound draft as still stored, all three equal to `?package=BASE`. Files: `packages/metadata-protocol/src/protocol-save.ts` (the helper's one-holder arm, the publish-mode and draft-mode save address, the new draft-address wrapper), `packages/metadata-protocol/src/protocol-diff-delete-load.ts` (the bare discard's receipt at the package-unbound sub-cell), `packages/metadata-protocol/src/protocol.ts` (the facade's `packagelessDraftAddress` forwards through the wrapper; still one forwarding call, `check:facade-delegation-only` green). Pins: `packages/runtime/src/domains/meta-bare-save-dependent-only-member-35524.test.ts` (new, named for this card, the #34681 fixture shape). Changeset: `.changeset/35524-bare-save-follows-base-dependent-member.md` (`@objectstack/metadata-protocol` patch, both declaration lines, BREAKING banner, ADR-0087 disposition `not-required (no-migration-prescription)`). No spec touch: the save request's `packageId` description's row-held-base exception sentence stays true (it covers a member the base and the dependent both hold). Its earlier sentence, "an `active` save then writes the row of the one package the item's active rows are bound to", now has this cell as a second exception; that text is left to sibling card #35529 (see Acceptance notes). Declarations: `Clause-②: no (narrowing)` because a published accept set narrows (the bare publish of the dependent's lone draft at this member moves from 200 to 404 `NO_DRAFT`) and what a bare write lands in moves (the dependent's row → the base's row), the epic ruling's "D's row silently updated → E's row (narrowing)" shape. `Metadata-protocol: none`: no key, accepted value or meaning of authored metadata moves; what moves is the row a request naming no package addresses, as PR #35450 declared for the sibling move. Read first (by risk): 1. `protocol-save.ts`, `packagelessRowHeldBaseAddress`: the new equality `address.candidates.includes(base) === address.candidates.length > 1` (two or more: the base among them; one: the base is not that one). 2. `protocol-save.ts`, `packagelessRowHeldBaseDraftAddress`, `draftAddressFollowsRowHeldBase` (`into !== null`) and the draft save's widened follow condition that asks it; `protocol-diff-delete-load.ts`, `receiptPackageId` (the bare discard's receipt over a package-unbound draft at the base's address). 3. `protocol.ts`, the facade's `packagelessDraftAddress`, now the one resolution every bare draft door shares. Two-minute check: `pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/domains/meta-bare-save-dependent-only-member-35524.test.ts` after building `@objectstack/metadata-protocol`; expect `Tests 10 passed (10)`. ## Tests <details><summary>The card's 3-step sequence, measured on main a73edb3 and on this head (booted kernel, real protocol and sqlite store)</summary> Fixture: authored WA holds `en-US`, authored WD (declares WA) holds `fr-FR`, same `email_template` name. | Step | main, rows stored after boot | main, kernel booted over the rows | this head (both) | |:--|:--|:--|:--| | 1. `GET ?member=fr-FR` | 404 | 404 | 404 | | 2. `PUT` fr-FR, no package | 200, rewrites WD's row | 200, rewrites WD's row | 200, writes a new WA row at fr-FR | | rows after (package_id, bundle_member) | WA/canonical, WD/fr-FR (edited) | same | WA/canonical, WD/fr-FR (unchanged), WA/fr-FR (edited) | | 3. `GET ?member=fr-FR` | 409 RESOURCE_CONFLICT | 404 | 200 at WA, the saved content | Why step 3 answered 409 on main: only where the rows were stored after boot. The registry then held no row of WA's; the save's registry write-through registered WD's fr-FR item, so the registry named WD the name's one holder, and the read, at the base's address, was refused by the exact-qualifier judgment ("not held by package WA ... held by package WD"). `?package=WA&member=fr-FR` answered the same 409. On a kernel booted over the rows (registry hydrated with both), step 3 answered 404. Either way the save wrote a row the read did not serve. The save naming WA at fr-FR on main (in process and REST `PUT ?package=WA`): 200, writes a new WA row at fr-FR, WD's row untouched, and the bare read then serves it (200 at WA). So the stop rule did not trigger; this head makes the bare save answer exactly that. </details> <details><summary>Per-door conclusions at the cell (main → this head)</summary> - save, publish mode (REST and in process): moved, pinned (writes WA's row, as named). - draft save: moved, pinned (writes WA's draft, as named). - strict draft read: moved, pinned (WD's draft → WA's draft; the draft the bare draft save writes). - per-item publish: moved, pinned (promotes WA's draft into WA's row; with only WD's draft, 404 `NO_DRAFT`, equal to `?package=WA`). - draft discard: moved, pinned (removes WA's draft; with only WD's draft, a receipt that discards nothing, equal to `?package=WA`). - a package-unbound draft stored at the member, no draft of WD beside it (contract review S2 option (b)): moved, pinned (the bare draft save writes WA's draft beside it, untouched, and the bare draft read reads it back; the bare publish promotes WA's draft; a second bare draft save writes no second draft; with no WA draft the bare draft read serves the package-unbound draft, the bare publish answers `NO_DRAFT`/404 and the bare discard the named-base receipt, all equal to `?package=WA`). - delete: unchanged, out of scope (still removes WD's row; it asks the row-held base only with two or more holders). See Acceptance notes. - history / diff / rollback: unchanged, out of scope (still WD's versions and row, through `historySlotOf`'s two-or-more guard). See Acceptance notes. - After the first bare save writes WA's row at the member, the cell is the #34681 cell (two holders, the base among them) and every door follows the base as PR #35450 pinned. </details> <details><summary>Pins (new file) and controls</summary> `meta-bare-save-dependent-only-member-35524.test.ts`, 10 tests: 1. REST `PUT` and in-process save on a kernel booted over the rows: step 1 404; WD's row byte-identical before and after (every stored column); rows equal to the save naming WA; no package-unbound row; bare read 200 at WA, `?package=WD` still WD's; and after a restart. 2. Rows stored after boot: the bare save writes WA's row and the bare read serves it (was 409). 3. Draft save: WA's draft, same rows as the named draft save, WD's row byte-identical; bare draft read serves it; bare publish promotes into WA's row; bare read 200; bare discard removes the draft the bare draft save wrote. 4. WD's own draft at the cell: bare publish and discard answer exactly what `?package=WA` answers; `?package=WD` publishes it. 5. Read-only (code) base holding rows: the bare save answers 422 `WRITABLE_PACKAGE_REQUIRED` naming the base, as `?package=BASE` (was the same code naming the dependent). 6. CONTROLS: the canonical member both hold (the #34681 cell) still writes the base's row; the canonical member only the dependent holds (S1) is still read and written at the dependent; two packages with no base relation at a member both hold still 409 naming both, and at a member one of them holds that package's row is read and written; a base that ships the name in code answers as today (bare read 404, bare save writes the dependent's customization row), pinned unchanged. 7. A package-unbound draft stored at the member (contract review S2 option (b); laid by a bare draft save at fr-FR while no package held that member, then WD's fr-FR row stored), four tests: (i) the bare draft save writes WA's draft, rows equal to the draft save naming WA, the package-unbound draft untouched, and the bare draft read then reads back what was saved (`['saved fr', WA]`, equal to the read naming WA); (ii) the bare per-item publish after that save promotes WA's draft, outcome and rows equal to `packageId: WA`; (iii) with no WA draft, the bare draft read equals the named one (`['unbound fr', null]`), the bare publish equals the named one (`NO_DRAFT`, 404) and the bare discard result equals the named discard's (`success`, `reset` and receipt, name blanked), rows unchanged; (iv) a second bare draft save updates WA's draft, one WA draft row. Unchanged and green: `meta-disabled-holder-served-stack.test.ts` (M1, M2, S2 untouched) and `meta-bare-write-doors-follow-base-34681.test.ts`: `Test Files 3 passed (3)`, `Tests 182 passed (182)` at 344fc14. </details> <details><summary>Ablations (one per moved pin; mutation through scripts/ablation-replace.mjs, rebuild, dist preflight, restore to the HEAD blob)</summary> - A, the publish-mode save's one-holder arm blanked (`const resolved = base ?? address.packageId` read as `address.packageId`): marker present in dist; tests 1, 2 and 5 red (`Tests 3 failed | 3 passed (6)`); restored, blob == HEAD, `git diff HEAD` empty. - B, `packagelessRowHeldBaseDraftAddress` returning the stored address: tests 3 and 4 red (`Tests 2 failed | 4 passed (6)`), re-run on 80f540b with the same reading; restored, blob == HEAD. - C, the draft save's follow condition back to ambiguous-only: test 3 red, the draft save writing `package=com.qa.authoredaddon` (`Tests 1 failed | 5 passed (6)`); restored, blob == HEAD. - Restore leg: rebuilt, all three markers absent from the 24 built files, pins `Tests 6 passed (6)`. - D (previous round, contract review S1, the `key !== null` exemption): superseded by this round; E puts it back as the ablation. - E (this round, contract review S2 option (b)), the move of the package-unbound sub-cell undone (`draftAddressFollowsRowHeldBase` read as `address.into !== null && address.key !== null`, both callers at once): anchor x1 -> x0, marker present in 2 built files after the rebuild; test 7 (i) to (iv) red (`Tests 4 failed | 6 passed (10)`: the bare draft save adopted the package-unbound draft into WD's draft, the bare publish then promoted the unbound draft into WD's row and answered 200, not `NO_DRAFT`). Restored, blob == HEAD (2c49e5a), `git diff HEAD` empty, rebuilt, marker absent from all 24 built files. - F (this round), the bare discard's receipt guard removed (`? draftAddress.into` read as `? draftAddress.into && null`): marker present in 2 built files; test 7 (iii) red alone (`Tests 1 failed | 9 passed (10)`), the bare receipt `No pending draft for email_template/NAME.` against the named one `No pending draft of email_template/NAME is bound to package 'com.qa.authoredbase', so nothing was discarded: its package-less draft remains.` (the named-base answer, measured on this head). Restored, blob == HEAD (1c2294d), `git diff HEAD` empty, rebuilt, marker absent from all 24 built files. - After both restores: pins `Tests 10 passed (10)`. E and F ran at 4f232bf; 344fc14 after it changes only a docblock, the changeset and the pin's added draft-read equality (a control of the read, which neither ablated guard decides; not re-ablated), so the guards E and F ablate are byte-identical at the final head. </details> ## Acceptance notes - Not moved, same family (reported to the seat, not built here): at this cell the bare delete still removes WD's row, and the bare history, diff and rollback still read and restore WD's versions, while the bare read answers 404 (measured in process on main and on this head). They ask the row-held base only with two or more holders. Whether they follow the base (where there is nothing of the base's to remove or restore) is a design question for that family, not this card. - Moved this round (contract review S2 option (b)): the package-unbound draft sub-cell. Consequence stated in the changeset: with no base draft the bare draft read still serves it (as the read naming the base does; measured, now pinned in (iii)), while the bare publish and discard leave it stored. The changeset's banner names a base holding a row of any other member (a base holding only `de-DE` beside a dependent's `fr-FR` is the same cell), per the S1 review's ②. - Not moved: a base that ships the name in code, with a dependent's stored row at another member: the bare read at that member answers 404 and the bare save writes the dependent's customization row (measured, pinned unchanged). - `SaveMetaItemRequestSchema.packageId`'s sentence "an `active` save then writes the row of the one package the item's active rows are bound to" now has this cell as an exception at the member grain, and `rowHeldBaseAddressOf`'s docblock says the writes ask it only with two or more holders. Both are text for sibling card #35529, which rewrites those descriptions; untouched here. - On main, the history naming WA at fr-FR (where WA holds no row) answered `RESOURCE_CONFLICT`; observation only. ## Verification <details><summary>Local runs at the final head 344fc14 (this round, contract review S2 option (b))</summary> - `@objectstack/metadata-protocol` typecheck exit 0, `@objectstack/runtime` typecheck (with its test-typecheck) exit 0, and the three files below, in one lock run at 344fc14: `VERDICT command-exit 0`. `@objectstack/metadata-protocol` test at 4f232bf (344fc14 changes only a docblock in that package): `Test Files 370 passed | 9 skipped (379)`, `Tests 23417 passed | 45 skipped (23462)`. - `meta-bare-save-dependent-only-member-35524.test.ts`, `meta-bare-write-doors-follow-base-34681.test.ts`, `meta-disabled-holder-served-stack.test.ts`: `Test Files 3 passed (3)`, `Tests 182 passed (182)`. - Derived gates (`dispatch-gates.mjs --commands` at 344fc14, 75 families, the same list as at 4f232bf): 75 exit 0 (`check:type-check-debt` under the lock, `re-measure: OK`; `check:dual-build-cjs-loads` measured over the dogfood closure's dist, 125 entry points load). `--ran`: 75 derived, 75 run, 0 NOT-MEASURED, 0 UNRUN. - `test:repo`, `pnpm lint` and the full farm are CI's. Check-runs at 344fc14: 53, 37 success, 16 skipped, none failed (Check Changeset, PR-body guards, Test Core 1..10, TypeScript Type Check, Lint & Repo Gates, Dogfood Regression Gate, Governed Surface Queue Guard among them). - Full dogfood battery (the narrowing arm) at 344fc14, closure built first: `os-verify-lock: VERDICT command-exit 0 · held the lock 2915s (48m35s)`, `Test Files 487 passed | 3 skipped (490)`, `Tests 4128 passed | 68 skipped (4196)`, no failures. Also green at 4f232bf (`Tests 4128 passed | 68 skipped (4196)`). </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01J8VVAj3FYe91JCMQZPS88h <!-- signed: repo:objectstack#2 · huangyiirene · session_01J8VVAj3FYe91JCMQZPS88h --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent 8695703 commit fd06b11

5 files changed

Lines changed: 542 additions & 15 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
fix(metadata-protocol)!: a save naming no package, at a bundle member only a dependent package holds, writes the base package's row the read naming no package addresses
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. What moves is which stored row a save, draft read, per-item publish or draft discard that names no package addresses at one cell; no stored row, registry key or authored value is rewritten, so there is nothing for a migration to change and no tombstone. -->
11+
12+
**BREAKING** for a caller that saves, publishes or discards a bundled type's item (today `email_template`) without naming a package, where an authored base package holds a stored row of the item at some member (its canonical member, or another one such as `de-DE`), an authored package that declares the base holds a stored row of another, non-canonical member (for example `fr-FR`), and the base holds no row of that member. The read naming no package already takes the base's address at that member and answers `404`.
13+
14+
- FROM: the save naming no package (REST `PUT` and in process, `active` mode) rewrote the dependent's row at that member, and the read naming no package then still answered `404` (or `409 RESOURCE_CONFLICT` where the rows had been stored after boot). The `draft` save wrote the dependent's draft; the draft read, per-item publish and draft discard naming no package read, promoted or removed the dependent's draft.
15+
- TO: the save naming no package writes the base's row (or, in `draft` mode, the base's draft) at that member, exactly as the same save naming the base (`?package=BASE`, `packageId: BASE`) does; the dependent's row is left byte-unchanged, and the next read naming no package serves the saved content (`200`). The draft read, per-item publish and draft discard naming no package act on the base's draft there. With only the dependent's draft stored at that member, the per-item publish naming no package answers `404 NO_DRAFT` naming that draft, and the draft discard naming no package discards nothing and says which draft remains, as the same requests naming the base answer.
16+
- FROM, a package-unbound draft stored at that member (as a `draft` save naming no package writes it while no package holds the member) with no draft of the dependent beside it: the draft read naming no package served that draft, the per-item publish naming no package promoted it into the dependent's row, the draft discard naming no package removed it, and the `draft` save naming no package adopted it into the dependent's draft, after which the draft doors naming no package still acted on it.
17+
- TO, at that sub-cell: the `draft` save naming no package writes the base's draft beside the package-unbound one and leaves the package-unbound draft untouched, as the save naming the base does; the draft read naming no package then reads back what was saved; the per-item publish naming no package promotes the base's draft into the base's row; a second `draft` save naming no package updates the base's draft (no second draft). With no base draft stored, the per-item publish naming no package answers `404 NO_DRAFT` and the draft discard naming no package discards nothing and names the package-unbound draft as still stored, exactly as the same requests naming the base answer. With no base draft stored, the draft read naming no package still serves the package-unbound draft, as the draft read naming the base does; once the base's draft is saved, both read the base's draft.
18+
19+
**Not moved.** The canonical member (a base and its dependent both holding it, or only the dependent holding it), two packages neither of which declares the other, a base that ships the name in code, and the delete, history, diff and rollback naming no package at this member.
20+
21+
The fix for a caller: to change the dependent's row or draft at that member, name the dependent (`?package=DEPENDENT` on the REST door, `packageId` in process).

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,13 +789,29 @@ export class ProtocolDiffDeleteLoadFacet {
789789
// below nor its "already at artifact default" / "nothing to
790790
// delete" claim holds. A delete naming none never lands here:
791791
// it addresses a row the read above found.
792-
if (!current && request.packageId != null && (rowsAtAddress.candidates.length > 0 || rowsAtAddress.unbound)) {
792+
//
793+
// [#35524, epic ruling 6781691009, contract review S2 option
794+
// (b)] …and a draft discard naming no package at the row-held
795+
// base's draft address over a stored package-unbound draft
796+
// ({@link packagelessRowHeldBaseDraftAddress}): it addresses the
797+
// base's draft, as the discard naming the base does, so with no
798+
// base draft it answers that discard's receipt, naming the
799+
// package-unbound draft still stored, never "No pending draft"
800+
// while one is. Only that address is `none` with a
801+
// package-unbound draft stored: `packagelessDraftAddress` makes
802+
// a stored package-unbound draft the address itself (`draft`,
803+
// key `null`) wherever it does not move to a base.
804+
const receiptPackageId = request.packageId
805+
?? (draftAddress?.kind === 'none' && draftAddress.into !== null && rowsAtAddress.unbound
806+
? draftAddress.into
807+
: null);
808+
if (!current && receiptPackageId != null && (rowsAtAddress.candidates.length > 0 || rowsAtAddress.unbound)) {
793809
return {
794810
success: true,
795811
reset: false,
796812
message: targetState === 'draft'
797-
? `No pending draft of ${request.type}/${request.name} is bound to package '${request.packageId}', so nothing was discarded: ${remainingRowsPhrase(rowsAtAddress.candidates, rowsAtAddress.unbound, 'draft')}.`
798-
: `No row of ${request.type}/${request.name} is bound to package '${request.packageId}', so nothing was deleted: ${remainingRowsPhrase(rowsAtAddress.candidates, rowsAtAddress.unbound, 'row')}.`,
813+
? `No pending draft of ${request.type}/${request.name} is bound to package '${receiptPackageId}', so nothing was discarded: ${remainingRowsPhrase(rowsAtAddress.candidates, rowsAtAddress.unbound, 'draft')}.`
814+
: `No row of ${request.type}/${request.name} is bound to package '${receiptPackageId}', so nothing was deleted: ${remainingRowsPhrase(rowsAtAddress.candidates, rowsAtAddress.unbound, 'row')}.`,
799815
};
800816
}
801817
// [#23495] …and a draft discard naming no package, of an item

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

Lines changed: 115 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,16 @@ export class ProtocolSaveFacet {
869869
host, 'save', request.type, writeType, request.name, itemDiscriminator(writeType, request.item), address,
870870
);
871871
if (holderRefusal) throw holderRefusal;
872-
if (address.packageId !== null) request = { ...request, packageId: address.packageId };
872+
// [#35524] …and a named non-canonical member only a dependent
873+
// holds, where the read naming no package takes the row-held
874+
// base's address: the base's row, as the save naming the base
875+
// writes it ({@link packagelessRowHeldBaseAddress}), never the
876+
// dependent's row the read does not serve there.
877+
const base = address.candidates.length === 1
878+
? await packagelessRowHeldBaseAddress(host, writeType, request.name, member)
879+
: undefined;
880+
const resolved = base ?? address.packageId;
881+
if (resolved !== null) request = { ...request, packageId: resolved };
873882
}
874883
}
875884

@@ -901,8 +910,17 @@ export class ProtocolSaveFacet {
901910
// draft save's inherited package (the named-base rule and the late
902911
// override re-judgment): the base is judged exactly as the save
903912
// naming it is, an id no installed package has refused `422`.
913+
// [#35524] …and the same where the active rows at the member are bound
914+
// to the one dependent whose addition the read naming no package does
915+
// not serve (it takes the base's address there): the base's draft,
916+
// also over a stored package-unbound draft there (epic ruling
917+
// 6781691009, contract review S2 option (b)). The named base is passed
918+
// down, so the repository's orphan-draft adoption (a save naming no
919+
// package) does not run: the package-unbound draft stays untouched, as
920+
// the save naming the base leaves it, and the draft the next bare
921+
// draft read, publish and discard reach is the one written here.
904922
let followedBase: string | undefined;
905-
if (draftAddress?.kind === 'ambiguous') {
923+
if (draftAddress !== undefined && (draftAddress.kind === 'ambiguous' || draftAddressFollowsRowHeldBase(draftAddress))) {
906924
const base = await packagelessRowHeldBaseAddress(
907925
host, singularType, request.name, itemDiscriminator(singularType, request.item),
908926
);
@@ -3247,18 +3265,28 @@ export function disabledHoldersOnlyRefusal(
32473265
* that base does, and every dependent's row stays where it is, read and
32483266
* written at its own `?package=`.
32493267
*
3250-
* Asked only where those doors would refuse naming two or more packages, and
3251-
* answered over the item's ACTIVE rows at `member`, as the read judges them:
3268+
* Asked where those doors would refuse naming two or more packages, and
3269+
* [#35524] by the save (publish and draft mode) and the draft doors'
3270+
* address ({@link packagelessRowHeldBaseDraftAddress}) where the rows are
3271+
* bound to one package; answered over the item's ACTIVE rows at `member`, as
3272+
* the read judges them:
32523273
*
32533274
* - the base, when two or more packages hold a row there, none of them
32543275
* package-less (#33210: a package-less row beside them is a customization
32553276
* of no one holder, and the refusal stands), and one is the row-held base;
3256-
* - `undefined` otherwise, and the door refuses as before: a type with no
3277+
* - [#35524] the base, when one dependent holds the only row there, at a
3278+
* named non-canonical member the base holds no row of: the read takes the
3279+
* base's address there (and answers 404 until the base holds a row), so
3280+
* the bare save writes the base's row or draft, as the save naming the
3281+
* base does, and the next bare read serves it. The canonical member stays
3282+
* the dependent's, as the read serves it (#33210 contract review S1);
3283+
* - `undefined` otherwise, and the door answers as before: a type with no
32573284
* members (#34441 contract review M1: no bundle additions), a name a
32583285
* package ships, holders with no base relation, a disabled holder (the
3259-
* served-holder judgment's), and a member the base holds no row of (the
3260-
* read takes the base's address there and answers 404; that cell is not
3261-
* moved here).
3286+
* served-holder judgment's), and, of the one-holder cell, the base's own
3287+
* row. The bare delete, history, diff and rollback ask only with two or
3288+
* more holders, so at the one-holder cell they still act on the
3289+
* dependent's row.
32623290
*
32633291
* FROM (`main` 8596c80eda): each of those doors refused `409
32643292
* RESOURCE_CONFLICT` naming the base and the dependent while the read
@@ -3285,9 +3313,86 @@ export async function packagelessRowHeldBaseAddress(
32853313
return undefined;
32863314
}
32873315
const address = await host.packagelessAddress(singular, name, member, 'active', activeRows);
3288-
if (address.candidates.length < 2 || address.unbound) return undefined;
3316+
if (address.candidates.length === 0 || address.unbound) return undefined;
32893317
const base = await rowHeldBaseAddressOf(host, singular, name, member, activeRows);
3290-
return base !== undefined && address.candidates.includes(base) ? base : undefined;
3318+
if (base === undefined) return undefined;
3319+
// [#35524] Two or more holders at the member: the base is one of them. One
3320+
// holder: a dependent's addition the base holds no row of, where the read
3321+
// takes the base's address (`rowHeldBaseAddressOf`'s S1-guarded arm).
3322+
return address.candidates.includes(base) === address.candidates.length > 1 ? base : undefined;
3323+
}
3324+
3325+
/**
3326+
* [#35524] Whether a non-ambiguous draft address naming no package is one the
3327+
* row-held base's address may replace ({@link packagelessRowHeldBaseAddress}):
3328+
* bound to a package by the active rows (`into !== null`), whatever draft it
3329+
* names, the dependent's or [contract review S2 option (b)] the
3330+
* package-unbound one (`key === null`). Epic ruling 6781691009, "a write
3331+
* resolves its address exactly as the read at the same address resolves it":
3332+
* the read naming no package takes the base's address at that member however
3333+
* the drafts there are stored, so the draft save and the other draft doors
3334+
* take it too. Keeping the package-unbound draft's own address there (the
3335+
* contract review S1 option (a) this replaces) let the bare draft save adopt
3336+
* that draft into the dependent, after which the bare draft read missed the
3337+
* draft just saved. The one predicate the draft doors' address
3338+
* ({@link packagelessRowHeldBaseDraftAddress}) and the draft save's follow
3339+
* ask, so they cannot part.
3340+
*/
3341+
export function draftAddressFollowsRowHeldBase(address: { into: string | null }): boolean {
3342+
return address.into !== null;
3343+
}
3344+
3345+
/**
3346+
* [#35524, epic ruling 6781691009, #34348 ruling (b)] THE DRAFT ADDRESS the
3347+
* draft doors naming no package take (the draft save, the strict draft read,
3348+
* the per-item publish and the draft discard, through
3349+
* `packagelessDraftAddress`), at a named non-canonical member whose active
3350+
* rows are bound to one dependent only, where the read naming no package
3351+
* takes the row-held base's address ({@link packagelessRowHeldBaseAddress}):
3352+
* that base's draft, promoted into the base's row, as the same request naming
3353+
* the base addresses it. So the draft a bare draft save writes there is the
3354+
* draft the bare draft read, publish and discard act on, and the dependent's
3355+
* draft is read, published and discarded at its own `?package=`.
3356+
*
3357+
* [#35524 contract review S2 option (b), epic ruling 6781691009] That
3358+
* includes a PACKAGE-UNBOUND draft stored at the member (`key === null`: no
3359+
* draft of the dependent beside it, as a bare draft save at the member writes
3360+
* it while no package holds that member): the address is still the base's
3361+
* (`none` until the base holds a draft there), because the read naming no
3362+
* package takes the base's address there however the drafts are stored. So
3363+
* the bare draft save writes the base's draft (the package-unbound draft is
3364+
* left untouched, as the save naming the base leaves it), the bare draft read
3365+
* reads back what it saved, the bare per-item publish promotes the base's
3366+
* draft, and the bare draft discard with no base draft answers as the discard
3367+
* naming the base does, naming the remaining package-unbound draft
3368+
* (`protocol-diff-delete-load.ts`). With no base draft there, the bare draft
3369+
* read still serves the package-unbound draft, as the draft read naming the
3370+
* base does, while the bare publish and discard leave it stored, as the
3371+
* requests naming the base do.
3372+
*
3373+
* `pending` (the draft address the stored rows give) itself otherwise: an
3374+
* ambiguous address (the doors ask {@link packagelessRowHeldBaseAddress} for
3375+
* it themselves, #34681), an address not bound to a package by the active
3376+
* rows ({@link draftAddressFollowsRowHeldBase}), and every cell that judgment
3377+
* declines.
3378+
*
3379+
* FROM (`main` a73edb3cd7): the bare draft save wrote the dependent's draft
3380+
* there (or adopted a stored package-unbound draft into the dependent) and
3381+
* the bare publish promoted it into the dependent's row, while the bare read
3382+
* at the member answered 404 (the base's address).
3383+
*/
3384+
export async function packagelessRowHeldBaseDraftAddress(
3385+
host: Pick<ProtocolHost, 'declinesStoredRow' | 'engine' | 'packagelessAddress' | 'readItemActiveRows' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'shippedArtifactsOf'>,
3386+
type: string,
3387+
name: string,
3388+
member: string | undefined,
3389+
pending: ReturnType<ProtocolHost['packagelessDraftAddress']>,
3390+
): Promise<Awaited<ReturnType<ProtocolHost['packagelessDraftAddress']>>> {
3391+
const address = await pending;
3392+
if (address.kind === 'ambiguous' || !draftAddressFollowsRowHeldBase(address)) return address;
3393+
const base = await packagelessRowHeldBaseAddress(host, type, name, member);
3394+
if (base === undefined) return address;
3395+
return { kind: address.drafts.candidates.includes(base) ? 'draft' : 'none', key: base, into: base, drafts: address.drafts };
32913396
}
32923397

32933398
/**

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ import { ProtocolWriteGatesTables } from './protocol-write-gates-tables.js';
619619
import { ProtocolRegistryHydrationFacet, type ObjectRegistryRefusal, type RegistryHealStop, type RegistryWriteThroughRequest } from './protocol-registry-hydration.js';
620620
import type { HealPackageBinding } from './protocol-heal-binding.js';
621621
// [#29985 codemod] Save refusals, saveMetaItem, saveConflict, migrateStoredMetadata: the members below delegate to its facet, `ProtocolSaveFacet`.
622-
import { ProtocolSaveFacet } from './protocol-save.js';
622+
import { ProtocolSaveFacet, packagelessRowHeldBaseDraftAddress } from './protocol-save.js';
623623
// [#29985 codemod] History, publish, drafts, publish backfill: the members below delegate to its facet, `ProtocolHistoryAndPublishFacet`.
624624
import { ProtocolHistoryAndPublishFacet } from './protocol-history-and-publish.js';
625625
import type { RegistryQuestion } from './registry-question.js';
@@ -7976,7 +7976,12 @@ export class ObjectStackProtocolImplementation implements
79767976
getOverlayRepo: (...a) => this.getOverlayRepo(...a),
79777977
readItemActiveRows: (...a) => this.readItemActiveRows(...a),
79787978
};
7979-
return packagelessDraftAddress.call(host, type, name, member, body);
7979+
// [#35524] …at the draft address the read naming no package takes
7980+
// there: the row-held base's, where the member's active rows are
7981+
// bound to one dependent only ({@link packagelessRowHeldBaseDraftAddress}).
7982+
return packagelessRowHeldBaseDraftAddress(
7983+
protocolHost(this), type, name, member, packagelessDraftAddress.call(host, type, name, member, body),
7984+
);
79807985
}
79817986

79827987
/**

0 commit comments

Comments
 (0)