Repository navigation
Commit 5af956f
fix(objectql)!: a bare doc read refuses a name two enabled packages hold, naming both (#34036)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbBePzY6g11h3hyWk5ud4vWy)_
Fixes #33264
Clause-②: no (narrowing) — narrowed: a by-name read of a doc that names
no package (`GET /meta/doc/NAME` and the doors that read through it,
`MetadataFacade.get`/`getEntry`), of a name two or more enabled packages
hold, moves from one holder's body, picked by registration order, to
`409 RESOURCE_CONFLICT` naming every holder. Unchanged: one holder, a
read that names the package, the environment's own item.
Metadata-protocol: none
Skills-docs: none — `content/docs/api/client-sdk.mdx` (the `/meta` 409
section) already teaches that an ambiguous bare read answers `409
RESOURCE_CONFLICT` listing the holders; this PR makes the doc read
honour it. The `?package=` remedy for a doc on a composed artifact
server is tracked in #34040 / #34041.
Follow-ups named by ruling 6893582352: #34069 (domain:skills, ADR-0048
status line) and #34070 (domain:ui, Console `/docs/NAME` candidates on a
409). Composed-rig pins (review N2/N6) are carried by #34040 (acceptance
item 4).
## 维护者速读
- 改了什么:两个启用的包都带同名帮助文档(doc)时,不指明包的按名读取(REST `/meta/doc/名字` 与进程内
`MetadataFacade.get`)不再按注册顺序随便给一份,而是回 409 并列出所有持有包。
- 为什么改:落实裁决 6893582352(选项 A「拒绝并列出候选」):有歧义就报出来,不猜;与已经拒绝的裸保存、删除、发布、分层读取对齐。
- 风险与回滚:只影响「两个及以上启用包同名 doc」这一情形,一方实测零存量;单持有者、指明包的读取、环境自己的 doc 都不变。回滚即还原本
PR。
- 先看:`packages/objectql/src/registry.ts` 的
`readBareDoc`(判定本身);`packages/metadata-protocol/src/protocol-meta-item-reads.ts`
的 `refuseAmbiguousBareDocRead`
调用点(在任何层读取之前);`packages/objectql/src/package-scoped-e8-readers.test.ts`
末尾新增的 describe。
- 两分钟验证:`pnpm --filter @objectstack/objectql exec vitest run
src/package-scoped-e8-readers.test.ts -t ruling`,预期 7 个用例(按两种注册顺序展开共 12
个)全部通过。
- 需要你做的:按 Clause-② 收窄面安排一次契约复审(contract review)。
## What changes
The ruling on #33264 (comment 6893582352, option A) chose: a
context-free read of a `doc` name held by two or more enabled packages
answers `409 RESOURCE_CONFLICT` naming every holder, at the REST door
and the in-process facade. `doc` stays in ADR-0150 D1 bucket 1; no
address form changes.
- `packages/objectql/src/registry.ts`:
`SchemaRegistry.resolveItem('doc', name)` with no caller package goes
through a new private `readBareDoc`. It counts the served holders with
`packageScopedHoldersOf` (a disabled package holds no name) and throws
`PackageScopedNameRefusedError` (`ambiguous-in-environment`, the same
refusal the package-scoped types give) when two or more hold the name. A
package-less bare-slot entry (the environment's own item) answers first,
as `getItem` served it. With one enabled holder beside a disabled one,
it answers the enabled holder's item; otherwise it is `getItem`,
unchanged. `MetadataFacade.get` / `getEntry` / `exists` already read
through `resolveItem`.
- `packages/metadata-protocol/src/protocol-meta-item-reads.ts`:
`readMetaItem` asks that judge (`refuseAmbiguousBareDocRead`) before any
layer is read, for a read naming no package of type `doc`. It is a judge
only: when the registry answers, the read's layers run exactly as
before.
Seam: both. Measured on a composed server (below), the REST bare read
never reached the registry for this answer: the metadata service keeps a
doc by name alone and answered the package registered LAST. So a
registry-only judge would have missed the REST door, and a protocol-only
judge would have missed the facade. The judge lives once, in the
registry; the protocol only asks it.
| Read | FROM (origin/main) | TO (this PR) |
|:---|:---|:---|
| `GET /meta/doc/NAME`, two enabled holders (composed server: dispatcher
and RestServer; `/layers` and `/published` too) | `200`, the holder
registered last | `409 RESOURCE_CONFLICT`, both holders named |
| `MetadataFacade.get('doc', NAME)` / `getEntry`, two enabled holders |
the holder registered first | `409 RESOURCE_CONFLICT`
(`PackageScopedNameRefusedError`), both named |
| `MetadataFacade.exists('doc', NAME)`, two enabled holders | `true` |
`true` (unchanged) |
| one holder; `?package=`; a package caller; the environment's own item
| as before | as before |
| `MetadataFacade.get`, two holders, one disabled | the first registered
(may be the disabled one's) | the enabled holder's |
| `GET /meta/doc/NAME`, two holders, one disabled | `404` when the
disabled one registered last, else the enabled one's | unchanged |
## Tests
New top-level describe in the shared harness
`packages/objectql/src/package-scoped-e8-readers.test.ts` (real
`SchemaRegistry`, real `ObjectStackProtocolImplementation`, real
`MetadataFacade`), every two-holder pin in both registration orders.
Refusal pins assert `code` `RESOURCE_CONFLICT`, `status` `409`, the
reason and each holder named.
- FROM one holder's body TO 409: the protocol read on both faces, the
facade (`get`, `getEntry`) and the registry refuse; `exists` stays
`true`.
- FROM the service's copy TO 409: with a metadata service that keeps the
doc registered last, the read is refused before that layer is read.
- A package-less row only the store holds is no exemption: the read's
layers do not serve such a row for a `doc` (measured), so exempting it
would reopen the registration-order pick.
- CONTROLs: one holder at every reader; the exact address and the
package caller read their own holder in both orders; a disabled package
holds no name (the facade serves the enabled one, re-enabled it refuses
again); the environment's own item answers first beside two holders.
Ablation, each leg through `scripts/ablation-replace.mjs` (anchor 1 to
0, blob moved, restored blob equal to HEAD and `git diff HEAD` empty),
pins run with `-t ruling`:
<details><summary>Four legs, each red, each restored</summary>
- A, the registry refusal never fires (`served.length >= 2` to `>= 99`):
7 failed, 5 passed. Red: both FROM pins in both orders, the
disabled-holder CONTROL (it asserts the refusal on re-enable) and the
store-only-row pin.
- B, the protocol never asks the judge (`request.type === 'doc'` to
`'docABLATED'` in `readMetaItem`; `metadata-protocol` rebuilt,
`ablation-dist-preflight.mjs` found the marker in `dist/`): 5 failed, 7
passed, each `the read refuses: expected undefined to be an instance of
PackageScopedNameRefusedError`. Restored, rebuilt, preflight `--absent`
passes on all 24 built files and the tree.
- C, a disabled package counts as a holder (`includeDisabledPackages:
true`): 2 failed (the disabled-holder CONTROL, both orders).
- D, the environment's own item no longer answers first: 2 failed (the
environment CONTROL, both orders).
</details>
## Acceptance notes
- Reading of the ruling's "the environment's own saved row still answers
first": the row answers first where the registry holds it (the
package-less bare slot that hydration and the save write). A row only
the store holds is not served by the read's layers for a `doc` (step 1
does not adopt it, measured on the composed server and on the harness),
so it is not an exemption: exempting it measured `200` with the holder
registered last. Named in the report.
- Out of this PR, measured on origin/main on the composed server and
unchanged here: `GET /meta/doc/NAME?package=com.qa.alpha` answers the
OTHER package's doc (the one the metadata service kept); and with one
holder disabled and registered last, the bare read, `/layers` and
`/published` answer `404` although an enabled package holds the name.
Both are in the report for the seat.
- Owed elsewhere, per the ruling: the ADR-0048 status-line edit (a
`domain:skills` card) and the Console `/docs/NAME` display of the
candidates on a 409 (a UI-lane follow-up).
## Verification
All readings at head `e4b68eb2b` (this branch with `origin/main` merged
at `db1dde9f`), objectstack-ai/objectstack.
<details><summary>Composed server: the mechanism, measured before and
after</summary>
A throwaway rig (not committed) booted the way a compiled artifact
composes: `MetadataPlugin` artifact door plus `AppPlugin` over one
artifact whose two package bodies (`com.qa.alpha`, `com.qa.beta`) each
ship doc `shared_doc`; both transports (`HttpDispatcher.dispatch` and
`RestServer`'s registered handler), both registration orders.
- origin/main `1e65a389`: the metadata service holds the doc registered
LAST; the registry's `getItem` answers the one registered first. The
bare read, `/layers` and `/published` all answered `200` with the LAST
registered holder's doc, in both orders. So the PM hypothesis H1 (the
REST read ends at the registry's first composite) is refuted for this
door, and H2 (one judge at the registry covers both doors) holds only
because the protocol now asks that judge before any layer.
- this head: the bare read, `/layers` and `/published` answer `409
RESOURCE_CONFLICT` on both transports, in both orders. One holder
disabled: identical to main on every door (`404` when the disabled one
registered last, the enabled one's doc otherwise). A package-less
`sys_metadata` row only the store holds: `409` (with an exemption it
answered `200` with the last registered holder's doc, because the read's
layers do not serve such a row for a doc).
</details>
<details><summary>Suites, typecheck, gates, dogfood</summary>
- `pnpm --filter @objectstack/objectql test`: 596 files, 13165 tests
passed. `typecheck`: exit 0.
- `pnpm --filter @objectstack/metadata-protocol test`: 341 files passed,
9 skipped; 22894 tests passed. `typecheck`: exit 0.
- `pnpm --filter @objectstack/runtime test`: 605 files, 10958 tests
passed (19 skipped).
- `pnpm --filter @objectstack/rest test`: 412 files, 8442 tests passed
(332 skipped).
- `pnpm check:type-check-debt`: exit 0. `pnpm lint`: exit 0.
- `dispatch-gates.mjs --commands`: 72 derived; 70 run, each exit 0;
`check:type-check-debt` run under the lock (exit 0);
`check:dual-build-cjs-loads` left to CI.
- Changeset and body gates: `check-adr-0087-registration` (1
declared-breaking changeset, disposition present),
`check-changeset-no-major` (reads `no (narrowing)` / `none` at `patch`),
`check-empty-changeset`, `check-closing-keyword-parity`,
`check-partof-closing-keyword`: each exit 0.
- Dogfood battery (narrowing arm), `pnpm --filter @objectstack/dogfood
test` under the verify lock after the closure build: Test Files 467
passed, 3 skipped (470); Tests 3959 passed, 42 skipped. VERDICT
command-exit 0.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12
<!-- signed: domain:server#5 · zhuangjianguo ·
session_01QsR2jUcj2x2Wr4UErwBi12 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 6844e6b commit 5af956f
4 files changed
Lines changed: 169 additions & 1 deletion
File tree
- .changeset
- packages
- metadata-protocol/src
- objectql/src
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
316 | 340 | | |
317 | 341 | | |
318 | 342 | | |
| |||
601 | 625 | | |
602 | 626 | | |
603 | 627 | | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
604 | 633 | | |
605 | 634 | | |
606 | 635 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
639 | 639 | | |
640 | 640 | | |
641 | 641 | | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
10096 | 10096 | | |
10097 | 10097 | | |
10098 | 10098 | | |
| 10099 | + | |
10099 | 10100 | | |
10100 | 10101 | | |
10101 | 10102 | | |
10102 | 10103 | | |
| 10104 | + | |
| 10105 | + | |
| 10106 | + | |
| 10107 | + | |
| 10108 | + | |
| 10109 | + | |
| 10110 | + | |
| 10111 | + | |
| 10112 | + | |
| 10113 | + | |
| 10114 | + | |
| 10115 | + | |
| 10116 | + | |
| 10117 | + | |
| 10118 | + | |
| 10119 | + | |
| 10120 | + | |
| 10121 | + | |
| 10122 | + | |
| 10123 | + | |
| 10124 | + | |
| 10125 | + | |
| 10126 | + | |
| 10127 | + | |
| 10128 | + | |
| 10129 | + | |
| 10130 | + | |
| 10131 | + | |
| 10132 | + | |
| 10133 | + | |
| 10134 | + | |
| 10135 | + | |
| 10136 | + | |
| 10137 | + | |
| 10138 | + | |
| 10139 | + | |
| 10140 | + | |
| 10141 | + | |
| 10142 | + | |
| 10143 | + | |
| 10144 | + | |
| 10145 | + | |
| 10146 | + | |
10103 | 10147 | | |
10104 | 10148 | | |
10105 | 10149 | | |
| |||
0 commit comments