Repository navigation
Commit 6cb7440
fix(client, app-shell): every draft-then-publish Save publishes only the draft it wrote (#37637)
<!-- claude-projects-attribution: {"github_login":"os-sales"} -->
_Requested by **Sales** · [project
thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuBUGgrNWoBUQKbyS4GaX5vM)_
Fixes #37440
Clause-②: yes (widening: `@objectstack/client` `meta.publishItem`
accepts `draftVersion` and `parentVersion` beside `message` and
`packageId`)
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:管理员在设计器、记录页和导航编辑里点保存时,只会发布自己刚写下的那份草稿;如果有人恰好在这一刻改了同一份草稿,这次保存不会发布,也不会删掉别人的草稿,而是提示草稿待处理。没有冲突时保存和以前完全一样。
-
为什么做:属于「草稿并发写入保护」这条线(替先保存草稿、再立即发布的所有保存入口补上最后一个缺口):服务端早已支持按草稿版本拦截,前端各个保存入口却一直没把自己的版本带上。
-
出错会怎样:最坏情况是某个保存在没有冲突时也被拒,作者看到「草稿待处理」需要再存一次;旧服务端不返回版本号时一切照旧不带锁;整笔可以直接撤回。
- 要你做什么:无。
## What changes
`client.meta.publishItem` takes the two optimistic-concurrency pins the
per-item publish door already judges (ADR-0008,
`PublishMetaItemRequestSchema`). `draftVersion` goes in the body beside
`message` and names the pending draft the publish promotes.
`parentVersion` is sent as `If-Match`, and `null` is sent as
`If-None-Match: *`; it names the live row the publish replaces. With
neither set, the request is byte-identical to before.
Every console Save that writes a draft and publishes it at once now
passes `draftVersion`. The value is the version its OWN draft write
returned: `draftReceiptVersion(receipt)`, or `heldDraftVersion(...)`
right after a guarded save. It is never a fresh re-read, which would pin
another writer's draft. The callers:
- **Studio top-bar Save.** `publishSavedItem` in `studioSaveBar.tsx`
takes `SavedItem.draftVersion`. It is forwarded by DataPillar (objects
and object extensions), AutomationsPillar (flows and the on/off switch),
`objectHooksBuffer`, `pairObjectActions`, PermissionMatrixEditor,
`newAppDoor`, and MetadataListCreateDialog (new object and new flow).
- **Item page Save:** `detailSaveAtOnce` via ResourceEditPage.
- **Sharing-defaults table:** each row of PackageOwdOverviewPanel. This
was deferred in round 1 behind #37554 and is added now that #37554 has
landed.
- **Record page:** 「Configure tabs」 (`recordTabsConfigSave`) and an
installed object's field arrangement (`objectExtensionArrangementSave`).
- **Design mode:** the header pins (`designModeHeaderPinsSave`) and the
menu plus menu labels (`designModeMenuSave`).
A door refusal under the draft pin is `409 METADATA_CONFLICT`, the same
code the live-row pin gets, and the body does not say which pin refused.
The draft-version guard (`draftVersionGuard.ts`, new rule 10 in the
`DraftConflictDialog.tsx` header) tells the two apart with one draft
read after the refusal:
- If the draft is still at the pinned version, the live row moved, and
the existing reload-or-overwrite dialog asks (rule 8).
- If the draft moved, is gone, or cannot be read, the refusal is the
draft's. Nothing is asked, and the error is thrown marked
`isPublishDraftMoved`.
Every caller treats a moved draft the same way: nothing is published and
the draft is **kept**, because it now holds the other writer's change.
The Save reads as refused or says a draft is pending. Every take-back of
the Save's own draft is pinned `If-Match` to that same receipt, so a
refused Save never deletes a draft someone else changed.
## Why
#36350 added `draftVersion` to the publish door, but no caller sent it.
In the window between a Save's draft write and its publish, another
writer's draft write (another tab, the copilot) is promoted live under
the first author's Save. The client test reproduces this at the real
door: the unpinned publish promotes `theirs`.
Read first (risk order):
1.
`ui/packages/app-shell/src/views/metadata-admin/draftVersionGuard.ts`:
the `publish` catch and `draftStillAt`. This is where a refusal is
classified; a misclassification either asks the wrong question or keeps
a draft that should be discarded.
2. `ui/packages/app-shell/src/views/studio-design/studioSaveBar.tsx`:
`publishSavedItem`, which holds `draftMoved`, `discardScope`, and the
skipped discard.
3. `ui/packages/app-shell/src/layout/designModeMenuSave.ts`:
`discardOwnDraft`, the pinned take-back whose `409` means "moved, keep
it".
Two-minute verification: run `pnpm --dir ui exec vitest run
packages/app-shell/src/views/studio-design/studioSaveBar.draftPin-37440.test.ts`.
Expect 5 passed. The PIN case shows the other writer's draft still
pending and the live row unchanged.
## Tests
Each caller got one PIN (another writer's draft lands between the Save's
draft write and its publish: nothing goes live, their draft is kept, no
reset) and one CONTROL (no interleave: the Save's draft goes live), in
that caller's existing harness. The PIN asserts `draftVersion` is the
caller's own receipt; the CONTROLs assert the outcome only.
- `packages/client/src/meta-publish-item-package.test.ts`, Part 3, on
the real per-item publish door: the reproduction, PIN, CONTROL, the wire
shape (body `draftVersion`, `If-Match`, `If-None-Match: *` for `null`,
nothing when unset), and `parentVersion` stale or `null` refused.
- New `studioSaveBar.draftPin-37440.test.ts` and
`detailSaveAtOnce-37440.test.ts`, over a stateful door double,
`views/__tests__/draftPublishDoor-37440.ts`.
- Added describes in `recordTabsConfigSave-36499`,
`objectExtensionArrangementSave-36499`,
`designModeHeaderPinsSave-36366`, `designModeMenuSave-36538` (menu and
translation, plus the published-moved distinction),
`DraftConflictDialog.test.tsx` (guard rule 10: PIN, live-row-moved still
asks, overwrite keeps the draft pin, CONTROL), and
`PackageOwdOverviewPanel.draftPinned-37515`.
- Updated exact-argument asserts to carry `draftVersion:
expect.any(String)`: `AutomationsPillar.customizeFlow-28570`,
`DataPillar.pairActions-30088`,
`StudioDesignSurface.draftVersionConflict-11773`.
Ablation: one per pin (rebuild, on-disk mutation via
`scripts/ablation-replace.mjs`, restore). Every PIN went red with its
CONTROL green, and `git diff HEAD` was empty after each restore.
<details><summary>Local test readings at head 046abbb (each under
scripts/pm/os-verify-lock.sh)</summary>
- Client, `pnpm --filter @objectstack/client exec vitest run
--maxWorkers=2 src/meta-publish-item-package.test.ts`: Test Files 1
passed (1), Tests 15 passed (15), VERDICT command-exit 0.
- UI pins, 9 files (the 8 harnesses above plus
`firstScreenStudioCatalogue-37444`): Test Files 9 passed (9), Tests 112
passed (112), VERDICT command-exit 0.
- Affected app-shell set, 346 files: every test file that imports a
changed module, plus the OWD panel suites and the importers of
`draftVersionGuard.ts` / `customizeOverride.ts`. Result: Test Files 346
passed (346), Tests 2658 passed (2658), VERDICT command-exit 0. This ran
at 8192a73; the only later commit is the changeset.
- `pnpm --filter @object-ui/app-shell type-check`: VERDICT command-exit
0.
- The full app-shell suite was not run locally (it runs over 70 min on
the shared box). It is CI's.
</details>
<details><summary>Ablation readings (every PIN red, CONTROL green,
restored)</summary>
| Ablation | Result |
|---|---|
| client | 2 failed, 13 passed |
| studioSaveBar | 2 failed, 3 passed |
| detailSaveAtOnce | 2 failed, 1 passed |
| recordTabs | 1 failed, 6 passed |
| extension arrangement | 1 failed, 7 passed |
| header pins | 1 failed, 14 passed |
| menu | 1 failed, 16 passed |
| menu labels | 1 failed, 16 passed |
| OWD row | 1 failed, 11 passed |
| guard draft pin forwarded | 2 failed, 37 passed |
| guard classification | 1 failed, 38 passed |
After every restore, `git diff HEAD` was empty.
</details>
## Acceptance notes
- **Re-checked and out of scope (not draft-then-publish of an own
draft):**
- `StudioDesignSurface` `publishDraft('flow')` (about line 655),
`usePublishAllDrafts` and PackagesPage `publishDrafts`. These are
publish-all doors with no draft write of their own, so there is no
receipt to pin.
- `runtime-metadata-persistence` `boundToPackage`, which is already
pinned.
- **Nit N6 does not ride.** Its fix site is ViewConfigPanel /
RuntimeDraftBar, outside this card's surface.
- **Merged with #37589.** #37589 moved the guard's pure half into
`draftVersionGuard.ts`. Rule 10, `draftStillAt`, `isPublishDraftMoved`
and `draftReceiptVersion` now live there; `DraftConflictDialog.tsx`
re-exports them and keeps the header rule and the hook's stable
`heldDraftVersion`. The #37444 first-screen import walk
(`firstScreenStudioCatalogue-37444`) stays green: the list and record
save paths import the new names from `draftVersionGuard.ts`, never from
the dialog.
- **Classification read.** The read happens only after a refusal under
both pins, and it is never itself a pin. An unreadable draft is treated
as moved, which fails safe: nothing is asked and nothing is discarded.
- **Forwarders.** Forwarders that only pass a receipt through
(DataPillar, AutomationsPillar, objectHooksBuffer, pairObjectActions,
PermissionMatrixEditor, newAppDoor, MetadataListCreateDialog,
ResourceEditPage) are covered through the door they forward to
(`publishSavedItem` or `detailSaveAtOnce`) and the updated
exact-argument asserts above, not each by its own PIN.
- **Older servers.** Against a server whose draft save returns no
`version`, every caller publishes unpinned, as before.
## Verification
<details><summary>Derived gate families at head 046abbb</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 74 families. 73 exited 0, including
`pnpm --dir ui exec vitest run scripts/`, `check:type-check-debt` and
`check:skill-examples`, each after building their prerequisite dist.
`pnpm check:dual-build-cjs-loads` exited 3, PREREQUISITE NOT MET: not
every package has a dist in this container. NOT MEASURED locally; it is
read from this PR's checks.
`--ran` reconciliation: 74 derived, 74 run, 0 UNRUN. `node
scripts/check-nul-bytes.mjs`: OK. `node scripts/pm/overlap-check.mjs`:
VERDICT clean exit 0, against origin/main 54d6726 and 0 open PR
heads.
</details>
Merge, not rebase: origin/main (including #37589 and #37554) was merged
into the branch in 6f1e735.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(`packages/spec` untouched.)
- [x] 2. Every name I added uses the casing for its kind.
- [ ] 3. No formatter ran; `pnpm lint` passes. (No formatter ran; `pnpm
lint` is the CI-owned repo scan, read from this PR's checks.)
- [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: its generated artifacts are
regenerated and committed. (Not touched: n/a.)
- [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 fleet's
required maintainer brief, 维护者速读.)
- [ ] The *Before Submitting* list in CONTRIBUTING.md is done. (Local
targeted subset only; the full farm is CI's, see Verification.)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L6bhgWAbKPqt7vTgX5qgUn
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 9ed54cb commit 6cb7440
32 files changed
Lines changed: 1217 additions & 91 deletions
File tree
- .changeset
- packages/client/src
- ui/packages/app-shell/src
- layout
- __tests__
- views
- __tests__
- metadata-admin
- studio-design
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1284 | 1284 | | |
1285 | 1285 | | |
1286 | 1286 | | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
1287 | 1303 | | |
1288 | 1304 | | |
1289 | 1305 | | |
| |||
2725 | 2741 | | |
2726 | 2742 | | |
2727 | 2743 | | |
| 2744 | + | |
| 2745 | + | |
| 2746 | + | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
2728 | 2753 | | |
2729 | 2754 | | |
2730 | 2755 | | |
| |||
2751 | 2776 | | |
2752 | 2777 | | |
2753 | 2778 | | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
| 2794 | + | |
| 2795 | + | |
| 2796 | + | |
| 2797 | + | |
| 2798 | + | |
| 2799 | + | |
| 2800 | + | |
| 2801 | + | |
| 2802 | + | |
| 2803 | + | |
2754 | 2804 | | |
2755 | 2805 | | |
2756 | 2806 | | |
| |||
2764 | 2814 | | |
2765 | 2815 | | |
2766 | 2816 | | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
| 2821 | + | |
| 2822 | + | |
| 2823 | + | |
2767 | 2824 | | |
2768 | 2825 | | |
2769 | | - | |
| 2826 | + | |
| 2827 | + | |
| 2828 | + | |
| 2829 | + | |
| 2830 | + | |
2770 | 2831 | | |
2771 | 2832 | | |
2772 | 2833 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
409 | 409 | | |
410 | 410 | | |
411 | 411 | | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
234 | 235 | | |
235 | 236 | | |
236 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
0 commit comments