Repository navigation
Commit 7b68db9
feat(data): one record lock read owned by the data layer (ADR-0162 D9) (#38913)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwB8bGG76Ba3qpTAkGh8yPgHA)_
Fixes #37770
Clause-②: yes (widening)
Metadata-protocol: added
Skills-docs: follow-up #38961
## 维护者速读
- 新增一个由数据层回答的锁读取(单条和一页最多 200 条),告诉任何能读记录的人它是否被锁、是因关闭态还是因审批锁住。
- 不装审批插件也能用,此时只有关闭态会锁;审批原有的读取、SDK 方法和服务成员一字未改。
- 上传链接在发放前改问这个读取,关闭的记录用新句子拒绝,审批中的记录仍用原句子。
- 控制台记录页、表格和明细表格改问这个读取的工作归 #37773,不在本 PR。
## What changes
ADR-0162 D9: one answer to "is this record locked, and by which lock",
for both locks a record can be under.
- **Answer shape** (`packages/spec/src/api/record-lock.zod.ts`):
`RecordLockSchema`, `GetRecordLocksRequestSchema`,
`RecordLockEntrySchema`, `GetRecordLocksResponseSchema`,
`RECORD_LOCKS_MAX_RECORD_IDS = 200`. Spelled as two strict arms
(`locked: true` with both kinds, `locked: false` with none) so the
published JSON Schema carries the "both kinds exactly when locked" rule
too. Done-when item 5 (N12): **the internal seam requires the source**,
so `lockSource` is never optional under `approval`.
- **The read** (`packages/objectql/src/record-lock-read.ts`,
`ObjectQL#getRecordLock` / `#getRecordLocks`). Readability is read as
the caller, with each form's approvals-counterpart anchor (seat ruling
7152650156): the single read counts any row its by-id read returns and
judges the engine-spelled id; the page counts a row only when its id is
the asked id. The closed-state producer reads straight from the driver,
above the caller's grants (so field permissions on the state field do
not hide the answer, per D9) and inside the caller's org scope
(`buildDriverOptions`). A store read that fails is thrown, never read as
open. Order: `closed_state` before `approval`; within a reason `master`
before `record`.
- **The approvals producer**
(`packages/plugins/plugin-approvals/src/record-lock-producer.ts`):
pending under a locking node, or a passage on a `closedStates` object,
for the record itself and for `master_detail` lines of such a master. It
reuses the lock hooks' own helpers (four of them gain `export` in
`lifecycle-hooks.ts`, which the package entry does not re-export). It is
bound beside the lock hooks inside the `disableAutoHooks` block and
cleared in `destroy()`, so a composition that binds no approval lock
answers no approval lock.
- **Data protocol**
(`packages/metadata-protocol/src/protocol-record-lock.ts`):
`getRecordLock` / `getRecordLocks`, the object-existence gate first,
then the engine. An engine without the read answers `undefined`, which
the REST doors turn into 501.
- **REST** (`packages/rest/src/record-lock-routes.ts`, registered from
`data-action-routes.ts`, so `rest-server.ts` does not move): closed
empty query sets, `sendOk` envelope, the by-id read's localized `404
RECORD_NOT_FOUND` with `Vary`, 400 for a bad page body, 501 when the
read is missing. Two ledger rows (`data.getRecordLock`,
`data.getRecordLocks`) with their response schemas.
- **SDK** (`packages/client`): `data.getRecordLock(object, id)` and
`data.getRecordLocks(object, recordIds)`, with the types re-exported.
- **Upload-link door**
(`packages/services/service-storage/src/record-file-access.ts`): asks
`engine.getRecordLock` as the caller before it issues a field link and
refuses `409 RECORD_LOCKED` with "the record is closed, so no file can
be added to it" on `closed_state`, or the existing approval sentence on
`approval`. An engine without the read falls back to the approvals
service, as before.
- **Docs**: `content/docs/api/data-api.mdx` § Record locks,
`content/docs/api/client-sdk.mdx`, and a pointer from the approvals lock
reads in `content/docs/automation/approvals.mdx`.
- **Engine line ceiling**: `engine.ts` gains one import line and two
one-statement forwarders (+3, 6857 → 6860). The
`check:facade-delegation-only` row is raised by that measured growth,
per the maintainer's ruling record
[7314474264](#37770 (comment))
on #37770 (「提到 6861」): `baseLines` 6860 at `dd7675de60`, `maxLines`
6860. No other engine growth is covered by that ruling.
- **Level**: the two new request and response shapes enter the `api`
authorable-surface shard, which the changeset level axis reads as
`Metadata-protocol: added`, so `@objectstack/spec` is a `minor`; the
other packages are `patch`.
Out of scope here: moving the console askers (record page, grid, line
grid) onto this read belongs to #37773, together with its wording.
Follow-ups: #38961 (the skills page § Reading the lock points at this
read) and #38962 (the contract review's nits: pin the passage arm and
the read's jsdoc on a failed store read; the closed-state lines'
semi-join and the repeated foreign-key read).
## Why
A client could only ask the approvals read, which knows nothing of
closed states, so a closed invoice looked editable until the save was
refused. ADR-0162 D9 (adopted, ruling record 7200732942) puts one read
in the data layer for both.
## Tests
- `plugin-approvals/src/record-lock-one-read-37770.integration.test.ts`
(11): real ObjectQL over better-sqlite3 with the real
`ApprovalsServicePlugin`. Every Done-when combination: closed own, line
of a closed master, held by an approval, line of a held master, both at
once, neither, unreadable, missing; agreement with the write path; the
reader whose field permissions hide the state field is told
`closed_state`; no read on the object refuses the same for every id;
`lockRecord: false` and a decided request let go; the approvals-family
read still calls a closed record unlocked; without the plugin only
closed states lock; `destroy()` empties the slot, and the cross-package
key is the one the engine reads; the page answers entry by entry,
refuses 201 ids and takes 200.
- `rest/src/record-lock-routes.test.ts` (10): both doors, parsed against
the ledgered schemas; only the three members are served; 404/Vary;
relayed refusals; 501; 400 for each bad body; closed query sets.
- `rest/src/rest-write-route-hook-refusal-sentence.ledger.test.ts`: the
page door's write-verb row is driven.
- `service-storage/src/record-file-access.integration.test.ts`: the
fixture's approvals stand-in now also fills the engine slot; a new case
pins the closed-state sentence and that closed wins over held.
## Acceptance notes
- `git diff origin/main -- packages/rest/src/approvals-routes.ts
packages/spec/src/contracts` and the client's `approvals.*` methods: no
change (Done-when item 7).
- The read answers for a caller. A system context is bound by neither
lock and is not described.
- No permission or sharing boundary moves: readability is the caller's
existing read, and the answer carries no field, value, request id or
participants.
## Verification
- Package typechecks: objectql, metadata-protocol, rest, client,
plugin-approvals, service-storage — clean.
- Spec build with generated baselines regenerated and committed
(authorable surface, json-schema manifest, api surface, export origins,
strictness ledger counts, reference pages, llms.txt inventory).
- `dispatch-gates --commands`: every derived gate was run locally. The
ones that failed were fixed (route envelope, query-options erasure,
ADR-0122 alias pins, api surface, docs, export origins, llms.txt, facade
ceiling under ruling 7314474264). Four could not run here, for
environment reasons only: `check-plugin-teardown-shape --self-test`
needs an unshallow clone, and `check:skill-examples`,
`check:dual-build-cjs-loads` and `check:i18n` need built dists. CI runs
all four.
- Package suites: objectql 14662, rest census and route tests,
plugin-approvals, service-storage 94, metadata-protocol canonical-fold
census — green.
- `overlap-check`: clean against origin/main, #38908, #38888.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes.
- [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.
- [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.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01WGufzfGw8DS75kHUYrjbLM
<!-- signed: repo:objectstack@os-support-ai · os-support-ai ·
session_01WGufzfGw8DS75kHUYrjbLM -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 0543d59 commit 7b68db9
40 files changed
Lines changed: 1907 additions & 39 deletions
File tree
- .changeset
- content/docs
- api
- automation
- references
- docs/audits/2026-07-unknown-key-strictness-ledger.counts
- packages
- client/src
- metadata-protocol/src
- objectql/src
- plugins/plugin-approvals/src
- rest/src
- services/service-storage/src
- spec
- api-surface
- authorable-surface
- docs/references
- api
- export-origins
- json-schema.manifest
- src
- api
- 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 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
328 | 328 | | |
329 | 329 | | |
330 | 330 | | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
331 | 347 | | |
332 | 348 | | |
333 | 349 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
616 | 616 | | |
617 | 617 | | |
618 | 618 | | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 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 | + | |
619 | 676 | | |
620 | 677 | | |
621 | 678 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
520 | 520 | | |
521 | 521 | | |
522 | 522 | | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
523 | 529 | | |
524 | 530 | | |
525 | 531 | | |
| |||
1836 | 1842 | | |
1837 | 1843 | | |
1838 | 1844 | | |
1839 | | - | |
1840 | | - | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
1841 | 1849 | | |
1842 | 1850 | | |
1843 | 1851 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| 110 | + | |
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
8662 | 8664 | | |
8663 | 8665 | | |
8664 | 8666 | | |
| 8667 | + | |
| 8668 | + | |
| 8669 | + | |
| 8670 | + | |
| 8671 | + | |
| 8672 | + | |
| 8673 | + | |
| 8674 | + | |
| 8675 | + | |
| 8676 | + | |
| 8677 | + | |
| 8678 | + | |
| 8679 | + | |
| 8680 | + | |
| 8681 | + | |
| 8682 | + | |
| 8683 | + | |
| 8684 | + | |
| 8685 | + | |
| 8686 | + | |
| 8687 | + | |
| 8688 | + | |
| 8689 | + | |
| 8690 | + | |
| 8691 | + | |
| 8692 | + | |
| 8693 | + | |
| 8694 | + | |
| 8695 | + | |
| 8696 | + | |
| 8697 | + | |
| 8698 | + | |
| 8699 | + | |
| 8700 | + | |
8665 | 8701 | | |
8666 | 8702 | | |
8667 | 8703 | | |
| |||
9651 | 9687 | | |
9652 | 9688 | | |
9653 | 9689 | | |
| 9690 | + | |
| 9691 | + | |
| 9692 | + | |
| 9693 | + | |
9654 | 9694 | | |
9655 | 9695 | | |
9656 | 9696 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
78 | 89 | | |
79 | 90 | | |
| 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 | + | |
0 commit comments