Repository navigation
Commit 70f454a
fix(metadata): two Studio Saves over one published item are no longer last-writer-wins (#36720)
<!-- claude-projects-attribution: {"github_login":"os-alice"} -->
_Requested by **Alice** · [project
thread](https://claude.ai/code/project/chan_01NoziMoftaSPmzgKNjJGePH?thread=cmsg_01NoziMoftaSPmzgKNjJGePHJDtYrcfiNfCiqhM4g8dFWZ)_
Fixes #36601
Clause-②: yes (widening) — two new optional members join what the API
accepts and answers: `PublishMetaItemRequestSchema.parentVersion` (the
`If-Match` / `If-None-Match: *` pin on `POST /meta/:type/:name/publish`)
and `GetMetaItemLayeredResponseSchema.overlayVersion` (served on `GET
/meta/:type/:name/layers`); nothing is removed or narrowed, and a
publish that names no version behaves as before
Metadata-protocol: added
Skills-docs: none — the two members are REST wire members (a publish
precondition and a layered-read answer member) that Studio sends and
reads; no metadata author writes them and no published skill teaches the
publish route's headers
## 维护者速读
- 在 Studio
对象页,两位管理员同时改同一个已发布对象时,后保存的人不再悄悄覆盖先保存的人,而是看到“你打开之后这里已被修改”,可选重新加载、确认覆盖或继续编辑。
- 属于元数据并发保护:草稿已有版本锁,这次补上“直接发布”这一步,替同时编辑的管理员解决改动丢失。
- 出错的话,最坏是保存时多弹一次冲突对话框或保存被拒;不带版本的旧客户端行为不变,撤回本次合并即可恢复原状。
- 要你做的事:无。
## What changes
**Server (`@objectstack/spec`, `metadata-protocol`, `rest`, `runtime`)**
- `GET /meta/:type/:name/layers` answers `overlayVersion`: the keyed
version token of the stored active row at the read's address
(`?package=`). It is the same token the plain uncached read serves as
`version` and a publish receipt serves as `version`; `null` when no
active row is stored there. Opt-in on the protocol (`withVersion`),
turned on by the REST route and the runtime meta domain, so in-process
layered readers pay no extra read.
- `POST /meta/:type/:name/publish` takes that token as `If-Match`, or
`If-None-Match: *` for "no active row here". The headers are parsed by
the save door's own parser (`metaSaveRequestOptions`), so the two doors
refuse the same malformed preconditions with `400 VALIDATION_ERROR`.
- A stale pin is refused `409 METADATA_CONFLICT` with `currentVersion`,
through the existing `metadataConflictRefusal`. Nothing is promoted and
the draft stays pending.
- The pin is checked by the store's put lock on the promoting write
(`promoteDraft`'s new `expectedActiveHash` becomes the put's
`parentVersion`), not by an earlier separate read. The token is
converted with the existing `storedParentForToken`.
- A publish with neither header is unpinned, exactly as before.
**Studio (`@object-ui/data-objectstack`, `app-shell`, `i18n`)**
- `MetadataClient.publish` takes `ifMatch` / `ifNoneMatch` and sends
them as headers.
- `DraftVersionGuard` holds a second pin per item, for the published
row: `recordPublished` (from the load's `/layers` read, via
`publishedPinOf`) and `publish` (sends the pin, then holds the receipt's
version so one editor's Saves chain).
- On a conflict, the guard asks through the same dialog as a stale
draft, with `layer: 'published'` wording ("This changed since you opened
it"):
- **Reload** takes back the draft the Save wrote, then re-reads the live
object.
- **Overwrite**, after a confirmation, re-publishes pinned to the
refusal's `currentVersion`. A publish landing in between is asked about
again.
- **Keep editing** publishes nothing, takes back the saved draft, and
leaves the edits on the page with the draft conflict's own "Not saved"
line.
- `publishSavedItem` takes the guard's publish as an optional `pinned`
argument. Overloads keep the unpinned callers' outcome type unchanged.
- Studio's object page (`StudioDesignSurface` data pillar) is wired: its
load records the published pin and its Save publishes through it.
- New studio locale keys (en, zh):
`engine.draftConflict.publishedTitle`, `publishedDescription`,
`publishedOverwriteTitle`, `publishedOverwriteDescription`.
**Not in this PR.** The object extension, hooks, pair-actions and flow
editors still publish unpinned, so their behaviour is unchanged. Each
needs its own load to read `/layers`. This is reported to the seat as
follow-up.
## Tests
- `packages/rest/src/meta-item-publish-version-pin.test.ts` (new, real
stack: better-sqlite3, cache off). Cases:
- the unpinned control (last writer wins, as before)
- two pinned Saves: the second gets `409`, `currentVersion` equals A's
receipt and the next `/layers` token, B's draft stays pending, and an
overwrite pinned to `currentVersion` is accepted
- the token agrees across `/layers`, the plain read and the publish
receipt
- a draft-only item serves `null`, its first `If-None-Match: *` publish
succeeds and a second is refused
- a guessed raw token gets `409`
- two malformed header pairs get `400`
- `DraftConflictDialog.test.tsx`, new describe for the published pin:
- `publishedPinOf`
- pin then receipt chaining
- reload order (publish, then discard, then reload, with pins cleared)
- overwrite and keep-editing (the kept-editing error is told apart)
- a `null` pin, and unpinned
- `StudioDesignSurface.draftVersionConflict-11773.test.tsx`, new
describe "two Saves over one published object are not last-writer-wins":
- keep editing
- reload
- overwrite
- one editor's pins chain
- a server without `overlayVersion` gets an unpinned publish
- Ablation: with the Save's publish unpinned again, 4 of the 5 race
cases fail. The control stays green, as it should.
## Acceptance notes
- Ruling ①: the publish answer already served `version` (the active
token). The new piece is the read Studio loads from, so `/layers` now
answers `overlayVersion`, the same token.
- Ruling ②: the refusal is the typed `409 METADATA_CONFLICT` with
`currentVersion`, the draft door's own. Studio shows the draft
conflict's reload-or-overwrite dialog, worded for a live change.
- Ruling ③: no header means unpinned. The control test pins today's
behaviour.
- Seat ruling on #36511 (no client-only re-read before save): the check
is server-side, inside the promoting write's lock.
- Read first, by risk:
- `packages/metadata-protocol/src/protocol-history-and-publish.ts`: the
token-to-hash conversion and the first-write pin passed to
`metadataConflictRefusal`.
-
`ui/packages/app-shell/src/views/metadata-admin/DraftConflictDialog.tsx`:
`DraftVersionGuard.publish`, especially the reload ordering.
- `ui/packages/app-shell/src/views/studio-design/studioSaveBar.tsx`:
`publishSavedItem`'s `pinned` branch.
- Two-minute check: `pnpm --filter @objectstack/rest exec vitest run
src/meta-item-publish-version-pin.test.ts` should report 7 passed.
## Verification
Head `263b1dc5`, base `3cf6a44b`; merges cleanly onto current
`origin/main` (`overlap-check`: VERDICT clean).
- Premise on main `3cf6a44b`: the unpinned control showed B's publish
replacing A's, the publish ignored `If-Match`, and `/layers` served no
version.
- Server suites: `@objectstack/metadata-protocol` 23352 passed / 45
skipped; `@objectstack/rest` 8794 passed / 351 skipped, with 1 failure:
an existing assertion on the layered route's options, updated for
`withVersion` and re-run green (13 passed in that file);
`@objectstack/runtime` 11845 passed / 25 skipped.
- New and neighbouring server files: `meta-item-publish-version-pin`,
`meta-item-layered-route`, `meta-item-version-token-occ`: 35 passed.
- UI: `DraftConflictDialog.test.tsx` +
`StudioDesignSurface.draftVersionConflict-11773.test.tsx` 41 passed; the
36511 save suites plus `data-objectstack` and `i18n`: 237 files, 3413
passed; `ui/scripts`: 5127 passed.
- Type checks: `spec`, `metadata-protocol`, `rest`, `runtime`,
`app-shell` (both tsconfigs), `data-objectstack`, `i18n`: clean.
- Generated: `check:generated --fix` regenerated
`content/docs/references/api/protocol.mdx` (committed).
- Derived gate families (`dispatch-gates --ran`): 126 derived, 125 run
with exit 0, 1 NOT-MEASURED: `check-plugin-teardown-shape --self-test`
exit 3, its positive control is pinned to a commit this shallow clone
cannot reach. Declared to CI. `check:dual-build-cjs-loads` needs a
whole-repo `pnpm build` and is likewise declared to CI.
- Two gates went red on this branch and are fixed in it:
`check:facade-delegation-only` (the protocol facade was 10 lines over
its ceiling; its layered-read answer type now reuses the facet's
declared type, and the file is 30 lines shorter than base) and
`check:test-source-alias` (the edited layered-route test pays the engine
load at collection).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_011y7As7qXR2zTnbLDZgn218
<!-- signed: repo:objectstack#7 · os-alice ·
session_011y7As7qXR2zTnbLDZgn218 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 81eae2b commit 70f454a
21 files changed
Lines changed: 993 additions & 76 deletions
File tree
- .changeset
- content/docs/references/api
- packages
- metadata-protocol/src
- rest/src
- runtime/src/domains
- spec
- authorable-surface
- src/api
- ui/packages
- app-shell/src/views
- metadata-admin
- studio-design
- data-objectstack/src
- i18n/src/namespaces/studio
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1521 | 1521 | | |
1522 | 1522 | | |
1523 | 1523 | | |
| 1524 | + | |
1524 | 1525 | | |
1525 | 1526 | | |
1526 | 1527 | | |
| |||
2649 | 2650 | | |
2650 | 2651 | | |
2651 | 2652 | | |
| 2653 | + | |
2652 | 2654 | | |
2653 | 2655 | | |
2654 | 2656 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
674 | 674 | | |
675 | 675 | | |
676 | 676 | | |
677 | | - | |
| 677 | + | |
678 | 678 | | |
679 | 679 | | |
680 | 680 | | |
| |||
728 | 728 | | |
729 | 729 | | |
730 | 730 | | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
731 | 739 | | |
732 | 740 | | |
733 | 741 | | |
| |||
1330 | 1338 | | |
1331 | 1339 | | |
1332 | 1340 | | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
1333 | 1360 | | |
1334 | 1361 | | |
1335 | 1362 | | |
| |||
1358 | 1385 | | |
1359 | 1386 | | |
1360 | 1387 | | |
| 1388 | + | |
| 1389 | + | |
1361 | 1390 | | |
1362 | 1391 | | |
1363 | 1392 | | |
| |||
1377 | 1406 | | |
1378 | 1407 | | |
1379 | 1408 | | |
| 1409 | + | |
| 1410 | + | |
1380 | 1411 | | |
1381 | 1412 | | |
1382 | 1413 | | |
| |||
0 commit comments