Skip to content

Commit ad3d04f

Browse files
fix(metadata-protocol)!: publish judges an object draft by the current ObjectSchema (#38299)
Fixes #35924 Clause-②: no (narrowing) Metadata-protocol: narrowed Skills-docs: none — every body this refuses at publish is one a save of the same body already refuses; the published skills' procedure (fix what the refusal names, save the item again) is unchanged and is the remedy ## 维护者速读 - 用户能看到什么变化:在 Studio 里发布对象草稿时,若草稿是在某条更严格的对象校验规则上线之前保存的,发布现在会像保存一样拒绝它,草稿原样保留;正常草稿照旧发布。 - 为什么做:替数据域把保存与发布两道门对齐,避免旧草稿绕过新校验规则直接上线(例如封存审计对象缺少组织链列)。 - 出错会怎样:升级时仍有待发布旧草稿的环境,这些草稿发布会被拒(已标为破坏性变更并写入升级指南);作者按提示修正后重新保存即可;改动可直接撤回,不涉及数据迁移。 - 要你做什么:无 ## What changes `ProtocolHistoryAndPublish.promoteDraftForPublish` now asks the save door's spec parse of an object draft before `repo.promoteDraft` writes. This is the one save-door judge the promotion did not re-run. Before this change, an object draft saved before a narrowing `ObjectSchema` refinement landed went live at publish without that refinement judging it. - **New module** `packages/metadata-protocol/src/protocol-promoted-draft-spec-refusal.ts`: `promotedObjectDraftSpecRefusal(name, body)` parses the draft against `resolveOverlaySchema('object')`, the save door's own resolver (it resolves to `getMetadataTypeSchema('object')`). It refuses with the save door's envelope: `INVALID_METADATA` / `422`, `issues[]` from `zodIssuesToMetadataIssues(..., { refusalParams: true })`, and the save door's default-face sentence (`object/NAME failed spec validation: ...`). - **The body judged is the body the publish serves.** A stored row is read and registered through the ADR-0087 chain (`applyConversionsToStoredItem`), so the parse judges `convertStoredItemDetailed('object', body).item`, not the raw stored bytes. A draft stored in a spelling a later release retired, which the chain converts, still publishes exactly as before. Without this step the fix would falsely refuse such drafts (ablation 2 below shows it). - **Placement:** in the object block of the promotion, after the package-mismatch refusal and before the registry's `objectRegistrationRefusal`. That is the order the save door uses, so a body both refuse keeps the structured `issues[]` (#5364). The block already skips sealed managed items, which the store refuses `NOT_OVERRIDABLE` anyway. The refusal is thrown before the `judgeOnly` return, so the judge pass of a package publish on a store that cannot roll back raises it too. - `scripts/engine-double-contract.pinned.json`: three rows recording the new test's engine-double pins, written by `node scripts/check-engine-double-contract.mjs --write` as the gate prescribes. It adds no other row. - `.changeset/35924-publish-reparses-object-draft.md`: `@objectstack/metadata-protocol` **minor**, `@objectstack/spec` patch, `Metadata-protocol: narrowed`, a **BREAKING** banner and a `FROM → TO` section with the author's fix, and the ADR-0087 disposition `registered publish-refuses-object-draft-the-current-schema-refuses`. - `packages/spec/src/migrations/entries/semantic/19.publish-refuses-object-draft-the-current-schema-refuses.ts`: the upgrade-guide entry that disposition names. It is notice only: no key is removed and no D2 conversion is added, because the fix is the author's choice. This is the shape of the landed `19.publish-refuses-views-and-dashboards-that-save-and-do-not-work.ts`. ## Why The card's Done-when items: 1. **Reach measured once on main.** It reproduces. On `origin/main` at `e3bdc748`, the harness below saved a valid sealed audit object draft and rewrote its stored row to the pre-ADR-0154-D10 body (no `tenant_id` chain column, the checksum the store would write). The save door refuses that body `422 INVALID_METADATA`. Then: - per-item publish answered `{"success":true,"version":"hmac-sha256:a77d...","seq":1,"message":"Published draft — type=object, name=crm_ledger [seq=1]"}`, and the stored rows became `[{"state":"active","package_id":"com.acme.alpha"}]`; - package publish answered `{"success":true,"outcome":"published","publishedCount":1,"failedCount":0,...}` with the same active row. 2. **The promotion parses an object draft against the current `ObjectSchema`** and refuses it before `repo.promoteDraft` writes: the per-item publish answers the save door's `422 INVALID_METADATA` with its `issues[]`, and the package publish answers `outcome: 'refused'` with the draft in `failed[]` under `code: 'INVALID_METADATA'` and the same `issues[]`. Judge-only batches judge it too. 3. **Pins:** a pre-refinement draft is refused at publish (per item, per package, and in the judge-only pass), with CONTROLs where a valid draft still publishes. 4. **Declaration:** a narrowing, by the seat's ruling below. A pending object draft that published before is refused at publish now. The card's triage comment (7049063373), verbatim: "Triage: lands in `domain:server` (metadata publish) · `pm:queue`; rationale: area:data · Bug · a draft saved before an ObjectSchema refinement landed is promoted at publish without being parsed again; latent for every schema narrowing; no wrong answer measured → p3 as filed · size S." The card has no ruling comment. ### Seat ruling — the declaration The claim carried `Metadata-protocol: none`. The card's Done-when 4 says: "Declare it as a narrowing if a body that published before is now refused at publish." That condition holds as measured (the per-item publish answered 200 on main and 422 with the fix; the package publish answered `outcome: 'published'` on main and `outcome: 'refused'` with the fix), so the dev reported the fork rather than shipping it under `none`. The seat (`repo:objectstack#8`, session `session_017xRBcSAaBEfQpU2yJexSJ8`, 2026-11-28T10:00Z) ruled, verbatim: "Q2 = A — narrowed (the card's own Done-when 4 criterion is met as measured)." The declaration lines above, the changeset, the `!` in the title and the upgrade-guide entry follow that ruling. ## Tests New file `packages/metadata-protocol/src/protocol.publish-draft-schema-reparse.test.ts` (9 cases). The harness is the real save, publish and repository paths over a stub engine whose write verbs are held to ObjectQL's own dispatch decisions: - PREMISE: the two fixtures straddle the refinement (one parses, the other does not). - The save door refuses the pre-refinement body `INVALID_METADATA` / `422`, and nothing is stored. - The per-item publish refuses the pre-refinement draft with `code: 'INVALID_METADATA'` and `status: 422`. Its `lifecycle.seal` issues equal the save door's for the same body, and the draft stays a draft. - The package publish refuses it into `failed[]` (`outcome: 'refused'`, `code: 'INVALID_METADATA'`), and nothing is promoted. - The package publish on a store that cannot roll back (judge-only pass) refuses it, and neither it nor a valid sibling draft goes live. - CONTROL: a fresh valid draft publishes per item, per package, and per package on a store that cannot roll back. - CONTROL: a draft stored with the tombstoned `externalSharingModel`, which the chain strips (`object-external-sharing-model-removed`), still publishes. <details><summary>Run readings (local, at the head named)</summary> - New file, with the fix: `Tests 9 passed (9)`, lock `VERDICT command-exit 0`. - Package suite at `c3c5411f`, run as `pnpm --filter @objectstack/metadata-protocol exec vitest run --maxWorkers=2` (the following commit only adds three JSON ledger rows): `Test Files 373 passed | 9 skipped (382)` · `Tests 23614 passed | 45 skipped (23659)` · `VERDICT command-exit 0`. - `pnpm --filter @objectstack/metadata-protocol typecheck`: `VERDICT command-exit 0`. `tsc --listFiles` lists both new files, so the test is type-checked. - **Ablation 1** (`scripts/ablation-replace.mjs`, anchor `if (specRefusal) throw specRefusal;` deleted; `anchor 1 -> 0, blob 9f79c4b -> e7959dfad426`): `Tests 3 failed | 6 passed (9)`. The three failures are the per-item, package and judge-only refusal pins. The premise, the save-door pin and all four CONTROLs stay green. Restored: `blob == HEAD (9f79c4b) and git diff HEAD is empty`. - **Ablation 2** (the converted body replaced by the raw stored body, `const served = body;`; `anchor 1 -> 0, blob 3528de1 -> 0c1293f4f03d`): `Tests 1 failed | 6 passed (7)`. The one failure is the legacy-spelling CONTROL. This run is from before the judge-only pins were added. Restored: `blob == HEAD (3528de1)`. - The subject is imported as `./protocol.js`, a relative source specifier, so neither ablation needed a `dist/` rebuild. - `pnpm --filter @objectstack/spec exec vitest run --maxWorkers=2 src/migrations` (the new ledger entry): `Test Files 5 passed (5)` · `Tests 207 passed (207)` · `VERDICT command-exit 0`. - **Dogfood battery** at `f7534a646` (the title carries `!`), run as CI runs it: the closure was built with `pnpm --workspace-concurrency=2 --filter '@objectstack/dogfood^...' build` (`VERDICT command-exit 0`), then `pnpm --filter @objectstack/dogfood test` was run under the lock with no shard and no path. Result: `Test Files 491 passed | 3 skipped (494)` · `Tests 4148 passed | 68 skipped (4216)` · `VERDICT command-exit 0`, with no failures. A first attempt is void and not counted: I mis-spelled the concurrency flag, which forwarded `--concurrency=2` into the CLI's build script and broke it, so the test step ran against a partial closure. I stopped that run. </details> ## Acceptance notes - **Other types (read only, not measured):** the save door parses every type with a registered schema, but the promotion now re-parses only `object`, the type this card names. Whether every type's stored draft should be re-parsed at promotion is not asked here. The stored-draft populations differ: a `flow` is judged through `storedFlowVerdictBody`, and a `view` stores its parsed projection. carrier: none. - **File surface:** beyond the claimed publish path, co-located test and changeset, the diff writes two more files. (1) The three `scripts/engine-double-contract.pinned.json` rows the gate requires for any new pinned engine double, generated by the gate's own `--write`; the diff adds no other row. (2) One file under `packages/spec/src/migrations/entries/semantic/`, the ledger entry `check:adr-0087-registration` requires for a declared narrowing, written on the seat's order ("whatever ADR-0087 registration `check:adr-0087-registration` then demands (ledger entry under semantic/19.*)"). No other file in `packages/spec/src/**` is touched, and no `ObjectSchema` refinement. - `overlap-check.mjs` before each push: `VERDICT clean exit 0`. At the last run it merges cleanly with `origin/main` (`e2a0e9002`); an earlier run also showed it merging cleanly with #37924, which shares the engine-double ledger file. ## Verification Read first, by risk: 1. `packages/metadata-protocol/src/protocol-promoted-draft-spec-refusal.ts`: the parse, the conversion step and the envelope. 2. The new block in `packages/metadata-protocol/src/protocol-history-and-publish.ts`, right after the `overlayPackageMismatchError` throw in `promoteDraftForPublish`. 3. `packages/metadata-protocol/src/protocol.publish-draft-schema-reparse.test.ts`: the `rewriteStoredDraft` setup and the CONTROLs. Two-minute check: `pnpm --filter @objectstack/metadata-protocol exec vitest run src/protocol.publish-draft-schema-reparse.test.ts` should show `9 passed`. Delete the `if (specRefusal) throw specRefusal;` line and run it again: the three refusal pins go red. Local gates: the full `dispatch-gates.mjs --commands` list for this diff, 102 families at `f7534a646`, was run and reconciled (`--ran`: `102 derived famil(ies) accounted for`). The 25 families the spec ledger entry added all exit 0, among them `check:spec-changes`, `check:upgrade-guide`, `check:api-surface` (unchanged), `check:authorable-surface`, `check:docs`, `check:liveness` and the CLI's `migrate-meta-engine-guidance` test (3/3). `spec check:generated`: all 14 artifacts are up to date after a spec build. `check:adr-0087-registration`: `1 declared-breaking changeset(s), each carrying an ADR-0087 disposition … registered publish-refuses-object-draft-the-current-schema-refuses (new here …)`. All exit 0 except one that is NOT MEASURED locally and is carried by CI: `check-plugin-teardown-shape --self-test` exits 3 because it needs an unshallow clone. `check:dual-build-cjs-loads` and `check:lean-entry-closure` first exited 3 (no `dist/`); after the dogfood closure build they exit 0 at `f7534a646`. `check:engine-double-contract` went red until its ledger rows were written, then exited 0. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (The only `packages/spec` change is one data-only upgrade-guide entry.) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` is left to CI. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched (one migration-ledger entry): spec rebuilt and `check:generated` reports all 14 artifacts up to date, so there is nothing to regenerate. The registry it feeds is gitignored. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English, except the Chinese maintainer summary the repo requires. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_017xRBcRoJWF7MQr6HoRgBeC --- _Generated by [Claude Code](https://claude.ai/code/session_017xRBcRoJWF7MQr6HoRgBeC)_ <!-- signed: repo:objectstack#8 · sunhaolin · session_017xRBcSAaBEfQpU2yJexSJ8 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent fd9ac00 commit ad3d04f

6 files changed

Lines changed: 492 additions & 0 deletions
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
'@objectstack/metadata-protocol': minor
3+
'@objectstack/spec': patch
4+
---
5+
6+
fix(metadata-protocol)!: publishing an object draft judges it by the current ObjectSchema
7+
8+
Clause-②: no (narrowing)
9+
Metadata-protocol: narrowed
10+
11+
<!-- adr-0087: registered publish-refuses-object-draft-the-current-schema-refuses -->
12+
13+
**BREAKING** for an object draft the current `ObjectSchema` refuses. Before this change it published; now it is refused at publish, and the refusal names the fix. Stored metadata is not rewritten or refused at boot, and an active row is unchanged. The refusal comes at the next publish of such a draft.
14+
15+
A save checks an object body against the current `ObjectSchema` and refuses it with `422 INVALID_METADATA`. Publishing a draft did not repeat that check. So an object draft saved before a stricter `ObjectSchema` rule landed went live at publish, even though that rule refuses it. One example is a sealed object with no `tenant_id` chain column (ADR-0154 D10).
16+
17+
Both publishes now check the draft the same way a save does: per item (`POST /api/v1/meta/object/:name/publish`) and per package (`POST /api/v1/packages/:id/publish-drafts`), including the pass that judges a batch before it writes on a store that cannot roll back. Each answers with the save door's refusal before anything is written. The per-item publish answers `422 INVALID_METADATA` with the same `issues[]` a save of that body gets. The package publish answers `outcome: 'refused'` (read `outcome`, not the HTTP status), with the draft in `failed[]` under `code: 'INVALID_METADATA'` and the same `issues[]`, and its whole batch is refused with nothing promoted. Either way the draft stays a draft. The draft is checked as the publish would serve it, after the stored-row conversions are applied. So a draft stored in a spelling a later release retired, which those conversions rewrite, still publishes as before.
18+
19+
## FROM → TO
20+
21+
- A pending object draft the current schema refuses, for example a sealed audit object (`lifecycle.seal`) with no `chainField` and no `tenant_id` field. That draft is refused at publish. The fix: declare the chain column, `fields: { tenant_id: { type: 'lookup', reference: 'sys_organization' } }`, or name one, `lifecycle: { seal: { valueFields: [...], chainField: 'organization_id' } }`. Then save the draft again and publish. Whatever the refusal's `issues[]` names, the fix is the one a save of the same body asks for. To find such drafts before upgrading, read each pending object draft: those whose `_diagnostics.valid` is `false` are the ones a publish will refuse.
22+
23+
`@objectstack/spec` adds only the upgrade-guide entry `publish-refuses-object-draft-the-current-schema-refuses`.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import { historySlotOf, refusePackageSelectorOutsideSlottedTypes } from './proto
6969
import { captureStoredExpressionChange, fillStoredExpressionChange, type StoredExpressionFillCapture } from './protocol-stored-expression-fill.js';
7070
import { OBJECT_REGISTRY_REFUSED, reportObjectRegistryRefusal } from './protocol-registry-hydration.js';
7171
import { OBJECT_EXTENSION_TYPE, registrableObjectExtension } from './protocol-object-extension-item.js';
72+
import { promotedObjectDraftSpecRefusal } from './protocol-promoted-draft-spec-refusal.js';
7273
import { retireOverlayCacheOnRollback } from './meta-overlay-cache.js';
7374

7475
/**
@@ -1098,6 +1099,17 @@ export class ProtocolHistoryAndPublishFacet {
10981099
},
10991100
);
11001101
}
1102+
// [#35924] …and the save door's spec parse, asked of the draft
1103+
// this promotion makes live: a draft stored before a narrowing
1104+
// `ObjectSchema` refinement landed was never judged by it, and was
1105+
// promoted unjudged. Judged as the publish serves it (the ADR-0087
1106+
// chain applied), with the save door's `422 INVALID_METADATA` and
1107+
// `issues[]`, before `repo.promoteDraft` writes; a judge-only call
1108+
// raises it too. Asked ahead of the registry's refusal, as the save
1109+
// door orders them, so a body both refuse keeps the structured
1110+
// `issues[]` (#5364). See {@link promotedObjectDraftSpecRefusal}.
1111+
const specRefusal = promotedObjectDraftSpecRefusal(request.name, draftForGate.body);
1112+
if (specRefusal) throw specRefusal;
11011113
// [#29673] …and the registry's refusal of the body this promotion
11021114
// makes live, on the same row and for the D9.9 refusal's reason:
11031115
// the write-through runs after the row is active, where a refusal
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#35924] The save door's spec parse, asked again of an object draft at its
5+
* promotion.
6+
*
7+
* `saveMetaItem` parses every object body against the current `ObjectSchema`
8+
* (`resolveOverlaySchema` → `getMetadataTypeSchema('object')`) and refuses a
9+
* body it rejects `422 INVALID_METADATA`. `promoteDraftForPublish` re-runs the
10+
* save door's other refusals on the stored draft, because a draft stored
11+
* before a rule landed was never judged by it (#4463 D1), but it did not ask
12+
* the parse. So an object draft saved before a narrowing `ObjectSchema`
13+
* refinement landed was promoted live at publish, unjudged by that refinement
14+
* — the ADR-0154 D10 chain-column rule's sealed object without `tenant_id`
15+
* is the first measured case. This is the parse, asked of the draft the
16+
* promotion reads, with the save door's envelope: the same code and status,
17+
* the same `issues[]` (registered refusal params included, #36594) and the
18+
* same sentence on the default face.
19+
*
20+
* ## The body judged is the body the publish serves
21+
*
22+
* A stored row is read through the ADR-0087 conversion chain
23+
* (`applyConversionsToStoredItem`, replayed with its retired entries by the
24+
* protocol's read and by the database loader that registers the row), so a
25+
* draft stored in a spelling a later release retired is served — and
26+
* registered — in today's canonical shape. The parse judges that converted
27+
* body ({@link convertStoredItemDetailed}, no notice logged here: the read
28+
* warns once when it serves the row), not the stored bytes, so a draft the
29+
* chain converts keeps publishing exactly as before. What is still refused
30+
* after the chain is what the publish would make live while the current
31+
* schema refuses it.
32+
*
33+
* `object` only: the type the card measured. The save door parses every type
34+
* with a registered schema; whether the promotion should ask every one of
35+
* them is a separate question (each type's stored-draft population differs —
36+
* a `flow` is judged through `storedFlowVerdictBody`, a `view` stores its
37+
* parsed projection), and is not answered here.
38+
*/
39+
40+
import { resolveOverlaySchema } from './protocol-meta-type-schema.js';
41+
import { zodIssuesToMetadataIssues, type MetadataIssueEntry } from './protocol-metadata-issues.js';
42+
import { convertStoredItemDetailed } from './protocol-stored-item-conversion.js';
43+
import { specValidationFindings } from './protocol-write-face.js';
44+
45+
/** The refusal {@link promotedObjectDraftSpecRefusal} answers: the save door's spec-validation 422. */
46+
export type PromotedDraftSpecRefusal = Error & { code: 'INVALID_METADATA'; status: 422; issues: MetadataIssueEntry[] };
47+
48+
/**
49+
* The save door's spec-validation refusal of the object draft `body` the
50+
* promotion of `object/name` reads, judged as the publish would serve it;
51+
* `undefined` when the current `ObjectSchema` admits it (or no schema is
52+
* registered for `object`, as the save door then parses nothing).
53+
*/
54+
export function promotedObjectDraftSpecRefusal(name: string, body: unknown): PromotedDraftSpecRefusal | undefined {
55+
const schema = resolveOverlaySchema('object', body);
56+
if (!schema) return undefined;
57+
const served = convertStoredItemDetailed('object', body).item;
58+
const parsed = schema.safeParse(served);
59+
if (parsed.success) return undefined;
60+
const issues = zodIssuesToMetadataIssues(parsed.error.issues, { refusalParams: true });
61+
// No write face: the publish doors declare none, so the sentence carries
62+
// the findings in full, as every undeclared face of the save door does.
63+
const err = new Error(
64+
`object/${name} failed spec validation: ${specValidationFindings(undefined, issues)}`,
65+
) as PromotedDraftSpecRefusal;
66+
err.code = 'INVALID_METADATA';
67+
err.status = 422;
68+
err.issues = issues;
69+
return err;
70+
}

0 commit comments

Comments
 (0)