Repository navigation
Commit ad3d04f
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
File tree
- .changeset
- packages
- metadata-protocol/src
- spec/src/migrations/entries/semantic
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
1098 | 1099 | | |
1099 | 1100 | | |
1100 | 1101 | | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
1101 | 1113 | | |
1102 | 1114 | | |
1103 | 1115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
0 commit comments