Skip to content

Commit 9404cb1

Browse files
fix(metadata-protocol): a bare save of a name an enabled and a disabled package hold writes the enabled holder's row (#33889)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbBePzY6g11h3hyWk5ud4vWy)_ Fixes #32605 Clause-②: yes (widening) — a bare save of a name an enabled and a disabled package both hold, refused 409 naming both when each held a stored row, now writes the enabled holder's row; nothing the save door accepted is refused Metadata-protocol: none ## 维护者速读 - 改了什么:一个名字同时被启用包 E 和停用包 D 持有时,不带包名的保存现在写 E 的行(和不带包名的读取落在同一处)。不再写无归属行,不再改 D 的行,也不再报出 D 的名字。 - 为什么改:以前读取答的是 E,保存却落到别处:要么写出一个以后会遮住两个包的"环境自有"行,要么悄悄改了停用包的行,下次读取还看不到改动。 - 风险与回滚:只在环境里有停用包、且它和启用包持有同一个名字时生效,第一方应用里 0 处。原来两行并存时的 409 变成写入 E 的行(放宽,已声明)。回滚就是撤掉这个 PR,存储的数据不需要迁移。 - 先看:`packages/metadata-protocol/src/protocol-save.ts` 文件末尾的 `servedPackagelessSaveAddress`,以及保存门里调用它的那段(不带包名的发布态保存)。 - 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run src/domains/meta-disabled-holder-served-stack.test.ts -t 32605`,预期 48 个用例全部通过(两种传输 × 两种注册顺序)。 - 需要你做的:无,席位落地。 ## What changes The epic ruling 6781691009 on #32354 decides this card: "a write resolves its address exactly as the read at the same address resolves it (D3/D5 symmetry)". It also says: "A bare save of that name is therefore E's write. It is E's customization (D4: a package-less save under a name one package holds is that holder's), it is bound to E, and it never touches D's row." `saveMetaItemUnaudited` resolves the address of a publish-mode save that names no package. That step now asks a new module helper, `servedPackagelessSaveAddress`, in `protocol-save.ts`, before it falls back to `packagelessAddress` as before: 1. **The read's own judgment.** The helper first asks `servedAddressJudgment`, the one judgment the bare reads use since #32183 and #32354. The import is unchanged. When that judgment names a served holder, the save writes there. When it refuses because two or more holders are served, the save refuses too, with the save door's own 409 sentence, naming only the served holders. 2. **The row-only gap.** Some names a disabled package holds only as a stored row, while an enabled package ships them. The read judgment leaves that case to the read's content rule. If a disabled package is among the stored rows' bindings, the address is judged over the enabled bindings. One enabled binding is the address. Two or more are refused, naming them. If none is left, the address is the package-unbound row when one is stored (the row the read serves), otherwise the one enabled package that ships the name. 3. Otherwise nothing changes. That covers a name no disabled package holds, and a name only disabled packages hold. `protocol.ts`, `registry-question.ts`, `seed-loader.ts` and `protocol-meta-item-face.ts` are not edited. | bare save, name held by enabled E and disabled D | FROM (main 1e65a38) | TO | |---|---|---| | both ship it, no stored row | package-unbound row written (200) | row bound to E written (200) | | both ship it, D's row only | D's row updated (200); next read still E's code | E's row written; D's row byte-unchanged | | both ship it, a row of each | 409 naming E and D | E's row updated (widening); D's unchanged | | two authored row holders E, D | 409 naming E and D | E's row updated (widening); D's unchanged | | E ships it, authored D holds a row | D's row updated; read serves E | E's row written; D's unchanged | | E ships it, package-unbound row plus D's row | D's row updated; read serves the unbound row | the unbound row updated; D's unchanged | | three row holders, D disabled | 409 naming E, F and D | 409 naming E and F only | | D enabled again (after the save) | 409 naming both | unchanged: read and save 409 naming both | | CONTROL: a name only E ships, an unrelated package disabled | package-unbound overlay row | unchanged | | CONTROL: a name only D holds (its row alone) | D's row updated | unchanged (see open question in the report) | ## Tests The new top-level `describe('[#32605] …')` goes into the shared harness `packages/runtime/src/domains/meta-disabled-holder-served-stack.test.ts` (ruling record 6583487846). It boots a real kernel (registry, metadata service, `sys_metadata` on SQLite) and drives `PUT /meta/dashboard/:name` with no package. It runs on both transports, the runtime `HttpDispatcher` and `RestServer`'s `PUT` route, in both registration orders, with save orders where two rows are stored. That is 12 cases × 4 = 48. Each case asserts the stored rows by binding, byte-identity of D's row, the next bare read, and the 409 naming both once D is re-enabled. Ablations, each through `scripts/ablation-replace.mjs`. Every leg rebuilt `@objectstack/metadata-protocol`, proved its marker in `dist/` with `ablation-dist-preflight.mjs`, restored to HEAD's blob (`git diff HEAD` empty), rebuilt, and proved the marker `--absent`: <details><summary>ablation readings</summary> - A, helper off (main's behaviour): `Failed Tests 40`. All 10 negative cases fail × 4, both CONTROLs stay green. One failure reads `expected [ 'null' ] to deeply equal [ 'com.qa.save_alpha' ]`. - B, the row-only gap off: 12 failed (E ships with authored D row; unbound plus D row; two authored beside D). - C, the read-judgment refusal names every row binding: 4 failed. One reads `expected '{"success":false,"error":{"code":"RES…' not to contain 'com.qa.save_authored_beta'`. - D, the gap's two-holder refusal names every binding: 4 failed, same message. - E, the unbound arm off: 4 failed. One reads `expected [ 'com.qa.save_alpha', …(2) ] to deeply equal [ 'com.qa.save_authored_beta', 'null' ]`. </details> ## Verification <details><summary>suites and gates</summary> - `@objectstack/metadata-protocol` test: 340 files passed, 9 skipped; 22883 tests passed. Typecheck clean. - `@objectstack/runtime` test: 603 files passed; 10954 tests passed. Typecheck plus `check:test-typecheck` OK. - `@objectstack/rest` test: 412 files passed; 8442 tests passed. - `pnpm lint`: exit 0. - `dispatch-gates --commands`: 69 families derived. Run locally with exit 0, and reconciled with `--ran` (see the report). `check:dual-build-cjs-loads` is left to CI. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- signed: domain:server#5 · zhuangjianguo · session_01QsR2jUcj2x2Wr4UErwBi12 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent a91ae04 commit 9404cb1

3 files changed

Lines changed: 376 additions & 4 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
fix(metadata-protocol): a bare save of a name an enabled and a disabled package both hold writes the enabled holder's row, where the bare read serves it
6+
7+
Clause-②: yes (widening) — a bare save of a name an enabled and a disabled package both hold, refused 409 naming both when each held a stored row, now writes the enabled holder's row; nothing the save door accepted is refused
8+
Metadata-protocol: none
9+
10+
A save that names no package (`PUT /meta/:type/:name` with no `?package=`, or `saveMetaItem` with no `packageId`) now resolves its address the way the read at the same address does (ADR-0150 D3/D5). A disabled package holds nothing an address reaches. Before this fix the save door still counted a disabled package as a holder of the name. So when an enabled package E and a disabled package D both held the name, the save could:
11+
12+
- write a new package-unbound row, an environment-own item that shadows both packages once D is enabled again;
13+
- update D's row silently, so the next read kept serving E's item and the edit never showed;
14+
- refuse 409 naming D, while the read served E without ambiguity.
15+
16+
The bare save of such a name is now E's write (ADR-0150 D4). It writes E's row, D's row stays byte-unchanged, and D is never named. When two or more enabled packages hold the name beside the disabled one, the save refuses 409 and names only the enabled ones. When a package-unbound row already stands in for the item, the save edits that row, which is the one the read serves. Once D is enabled again, the bare read and the bare save both answer 409 naming both packages. A name no disabled package holds saves exactly as before. So does a name only disabled packages hold.
17+
18+
What moves, for a bare save of a name held by an enabled package E and a disabled package D:
19+
20+
- FROM D's row silently updated TO E's row written, D's row unchanged.
21+
- FROM a package-unbound row written TO a row bound to E.
22+
- FROM 409 naming E and D TO E's row updated (a widening: the save now writes where it refused).
23+
24+
Nothing to migrate. To edit D's own row while D is disabled, name it: `?package=` on the REST door, `packageId` in process.

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

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ import type { ProtocolHost } from './protocol-host.js';
8686
import type { ObjectStackProtocolImplementation } from './protocol.js';
8787
import { saveRegistryQuestion } from './registry-question.js';
8888
import { OBJECT_EXTENSION_TYPE, registrableObjectExtension } from './protocol-object-extension-item.js';
89+
import { servedAddressJudgment } from './protocol-meta-item-face.js';
90+
import { packagelessContentPackage, shippingPackageIds } from './protocol-environment-rows.js';
8991
import { BatchRowHealError, canJudgeBatchObjects, isBatchObjectType, readActiveBatchRow, settleBatchObjectRows, undoBatchRowWrite, undoOutcomeForLog, type WrittenBatchRow } from './batch-object-registration.js';
9092

9193
export class ProtocolSaveFacet {
@@ -331,7 +333,7 @@ export class ProtocolSaveFacet {
331333
}
332334

333335
/** [#28355] The body of {@link saveMetaItem} before its refusal audit; that method's docblock is the contract. */
334-
static async saveMetaItemUnaudited(host: Pick<ProtocolHost, 'anonymousElevatedFlowRefusal' | 'applyRegistryWriteThrough' | 'assertLockAllowsWrite' | 'assertRuntimeAuthoringRules' | 'authoredLockFamily' | 'authoringChannel' | 'carryForwardRedactedCredentials' | 'classifyObjectContribution' | 'codeOnlyCreateError' | 'codeOnlyOverrideError' | 'credentialChannelFor' | 'defaultRecordPageSaveRefusal' | 'emitMetadataMutation' | 'engine' | 'ensureObjectStorage' | 'ensureOverlayIndex' | 'envWritableTypes' | 'externalBindingSaveRefusal' | 'flowCanonicalizeFallbackWarned' | 'flowSaveReplaysRetired' | 'getOverlayRepo' | 'isArtifactBacked' | 'isOverlayAllowed' | 'isRuntimeCreateAllowed' | 'isWritablePackage' | 'namedBaseOverlayWriteRefusal' | 'objectExtensionItemRefusal' | 'objectNamespaceObjectNameClash' | 'objectNamespacePrefixViolation' | 'objectRegistrationRefusal' | 'overlayPackageMismatchError' | 'overrideWriteVerdict' | 'packagelessAddress' | 'packagelessDraftAddress' | 'packagelessOverlayWriteRefusal' | 'permissionSetNameCollisionRefusal' | 'readMetaItem' | 'receiptVersion' | 'recordMetadataAudit' | 'refuseOrganizationScopedWrite' | 'refusePackagedBaseOverride' | 'refuseUngrammaticalMetaItemName' | 'refuseUnmintableMetaType' | 'registryAllowsOverlay' | 'resolveFlowCanonicalizer' | 'resolveSduiManifest' | 'restoreInjectedColumnEchoes' | 'restoreTranslatedObjectEchoes' | 'restoredCredentialPathsFor' | 'runAuthoringGate' | 'runMutationProjector' | 'saveConflict' | 'saveWriteBinding' | 'seedExternalIdSaveRefusal' | 'storableViewFallbackWarned' | 'storedParentForToken' | 'stripServedObjectColumns' | 'tenantAuthoredWriteRefusal' | 'uninstalledNamedBaseRefusal' | 'unknownDatasourceSaveRefusal' | 'unknownGrantObjectSaveRefusal' | 'unknownPicklistBindingSaveRefusal' | 'viewContainerNameCollisionRefusal'>, request: SaveMetaItemRequest) {
336+
static async saveMetaItemUnaudited(host: Pick<ProtocolHost, 'anonymousElevatedFlowRefusal' | 'applyRegistryWriteThrough' | 'assertLockAllowsWrite' | 'assertRuntimeAuthoringRules' | 'authoredLockFamily' | 'authoringChannel' | 'carryForwardRedactedCredentials' | 'classifyObjectContribution' | 'codeOnlyCreateError' | 'codeOnlyOverrideError' | 'credentialChannelFor' | 'declinesStoredRow' | 'defaultRecordPageSaveRefusal' | 'emitMetadataMutation' | 'engine' | 'ensureObjectStorage' | 'ensureOverlayIndex' | 'envWritableTypes' | 'externalBindingSaveRefusal' | 'flowCanonicalizeFallbackWarned' | 'flowSaveReplaysRetired' | 'getOverlayRepo' | 'isArtifactBacked' | 'isOverlayAllowed' | 'isRuntimeCreateAllowed' | 'isWritablePackage' | 'namedBaseOverlayWriteRefusal' | 'objectExtensionItemRefusal' | 'objectNamespaceObjectNameClash' | 'objectNamespacePrefixViolation' | 'objectRegistrationRefusal' | 'overlayPackageMismatchError' | 'overrideWriteVerdict' | 'packagelessAddress' | 'packagelessDraftAddress' | 'packagelessOverlayWriteRefusal' | 'permissionSetNameCollisionRefusal' | 'readItemActiveRows' | 'readMetaItem' | 'receiptVersion' | 'recordMetadataAudit' | 'refuseOrganizationScopedWrite' | 'refusePackagedBaseOverride' | 'refuseUngrammaticalMetaItemName' | 'refuseUnmintableMetaType' | 'registryAllowsOverlay' | 'resolveFlowCanonicalizer' | 'resolveSduiManifest' | 'restoreInjectedColumnEchoes' | 'restoreTranslatedObjectEchoes' | 'restoredCredentialPathsFor' | 'rethrowUnlessMetadataStoreUnprovisioned' | 'runAuthoringGate' | 'runMutationProjector' | 'saveConflict' | 'saveWriteBinding' | 'seedExternalIdSaveRefusal' | 'shippedArtifactsOf' | 'storableViewFallbackWarned' | 'storedParentForToken' | 'stripServedObjectColumns' | 'tenantAuthoredWriteRefusal' | 'uninstalledNamedBaseRefusal' | 'unknownDatasourceSaveRefusal' | 'unknownGrantObjectSaveRefusal' | 'unknownPicklistBindingSaveRefusal' | 'viewContainerNameCollisionRefusal'>, request: SaveMetaItemRequest) {
335337
// [ADR-0131 D6] FIRST, before every other gate and every read: an
336338
// organization-scoped write is refused for every type, draft or
337339
// publish. See {@link organizationScopedWriteRefusal}.
@@ -810,10 +812,22 @@ export class ProtocolSaveFacet {
810812
const address = await host.packagelessAddress(
811813
writeType, request.name, itemDiscriminator(writeType, request.item),
812814
);
813-
if (address.candidates.length > 1) {
814-
throw packagelessAddressAmbiguityRefusal('save', request.type, request.name, address.candidates);
815+
// [#32605, epic ruling 6781691009] A name a disabled package also
816+
// holds is written where the read naming no package serves it
817+
// ({@link servedPackagelessSaveAddress}): never the disabled
818+
// package's row, never a new package-unbound row beside an
819+
// enabled holder, and a refusal names only the served holders.
820+
const served = await servedPackagelessSaveAddress(
821+
host, writeType, request.name, itemDiscriminator(writeType, request.item), address,
822+
);
823+
if (served !== undefined) {
824+
if (served.packageId !== null) request = { ...request, packageId: served.packageId };
825+
} else {
826+
if (address.candidates.length > 1) {
827+
throw packagelessAddressAmbiguityRefusal('save', request.type, request.name, address.candidates);
828+
}
829+
if (address.packageId !== null) request = { ...request, packageId: address.packageId };
815830
}
816-
if (address.packageId !== null) request = { ...request, packageId: address.packageId };
817831
}
818832

819833
const singularType = PLURAL_TO_SINGULAR[request.type] ?? request.type;
@@ -2780,3 +2794,58 @@ export class ProtocolSaveFacet {
27802794
return report;
27812795
}
27822796
}
2797+
2798+
/**
2799+
* [#32605, epic ruling 6781691009 on #32354, ADR-0150 D3/D4/D5] THE WRITE
2800+
* ADDRESS of a publish-mode save naming no package, for a name a DISABLED
2801+
* package also holds: the address the read naming no package serves, so the
2802+
* save writes exactly the row the next read answers. A disabled package holds
2803+
* nothing an address reaches, so it is never the address and never named.
2804+
*
2805+
* - The read's own judgment first ({@link servedAddressJudgment}, the one
2806+
* #32183 and #32354 gave the reads): its served holder is the address; its
2807+
* refusal (two or more served holders) is the save's refusal, naming only
2808+
* the served holders.
2809+
* - Otherwise, when a disabled package is among the packages the stored rows
2810+
* are bound to (`address.candidates`, {@link packagelessAddress}), the
2811+
* address is judged over the enabled bindings: one is the address, two or
2812+
* more are refused naming them. With none left, the row the read serves:
2813+
* the package-unbound row when one is stored (the save edits it, as the
2814+
* read serves it), else the one enabled package that ships the name (the
2815+
* read's content package, {@link packagelessContentPackage}).
2816+
* - `undefined` leaves the address to {@link packagelessAddress}, as before:
2817+
* no disabled holder, or one only disabled packages hold (no served holder
2818+
* to take the write; the save keeps naming that package, as it did).
2819+
*
2820+
* Without it the save door counted the disabled holder as a holder: over no
2821+
* stored row it wrote a package-unbound row (an environment-own item that
2822+
* shadows both holders once the package is enabled again), over the disabled
2823+
* package's row alone it updated that row (the read kept serving the enabled
2824+
* holder's item, so the edit never showed), and over a row of each it refused
2825+
* `409` naming the disabled package while the read served the enabled one.
2826+
*/
2827+
async function servedPackagelessSaveAddress(
2828+
host: Pick<ProtocolHost, 'engine' | 'packagelessAddress' | 'shippedArtifactsOf' | 'readItemActiveRows' | 'declinesStoredRow' | 'rethrowUnlessMetadataStoreUnprovisioned'>,
2829+
type: string, name: string, member: string | undefined,
2830+
address: { readonly packageId: string | null; readonly candidates: readonly string[]; readonly unbound: boolean },
2831+
): Promise<{ packageId: string | null } | undefined> {
2832+
const registry = host.engine?.registry as { isPackageDisabled?: (id: string) => boolean } | undefined;
2833+
if (typeof registry?.isPackageDisabled !== 'function') return undefined;
2834+
const disabled = (id: string): boolean => registry.isPackageDisabled?.(id) === true;
2835+
const judged = await servedAddressJudgment(host, type, name, member);
2836+
if (judged?.kind === 'served') return { packageId: judged.packageId };
2837+
if (judged?.kind === 'refused') {
2838+
const served = judged.error.refusal.candidates
2839+
.map((candidate) => (candidate as { packageId?: unknown }).packageId)
2840+
.filter((id): id is string => typeof id === 'string');
2841+
throw packagelessAddressAmbiguityRefusal('save', type, name, served);
2842+
}
2843+
if (!address.candidates.some(disabled)) return undefined;
2844+
const enabled = address.candidates.filter((id) => !disabled(id));
2845+
if (enabled.length > 1) throw packagelessAddressAmbiguityRefusal('save', type, name, enabled);
2846+
if (enabled.length === 1) return { packageId: enabled[0] ?? null };
2847+
if (address.unbound) return { packageId: null };
2848+
const shippers = [...shippingPackageIds(host.shippedArtifactsOf(type, name, undefined, member))].filter((id) => !disabled(id));
2849+
const content = packagelessContentPackage({ packageId: null, candidates: [] }, shippers.map((id) => ({ _packageId: id })));
2850+
return typeof content === 'string' ? { packageId: content } : undefined;
2851+
}

0 commit comments

Comments
 (0)