Repository navigation
Commit fd462c5
feat(plugin-approvals): the record lock reads say whether a row is held by its own approval or by its master's (#37191)
repo:objectstack#3 · os-support-ai · session_01WGufzeiHatzB4rRx1t4Php
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBEaJzgBWzjWCNjBjkVoeRto)_
Fixes #37151
Clause-②: yes (widening: both lock doors' published entry gains a field)
Metadata-protocol: none
Ruling-ref: 7148480184 (maintainer, option A, 2026-11-25T00:22Z; seat
record 7148474531). Execution, not a decision.
## 维护者速读
-
列表页和单条记录的“查锁”接口现在多回答一项:被锁的记录是自己的审批锁住的,还是所属主记录的审批锁住的;页面上暂时无变化,表格据此隐藏删除按钮由另一张卡(表格行菜单)接着做。
- 按你选定的方案 A 落地,替审批中报销单、订单的明细行使用者解决“列表给了删除、点了却被拒”的问题。
- 出错时最坏情况是某行的锁类型标错,表格多藏或少藏一个删除按钮,不会写错任何数据;可直接撤回。
- 无
## What changes
- **Both lock doors answer the kind.** `IApprovalService.getRecordLock`
and `getRecordLocks` (and their REST doors `GET
/api/v1/approvals/records/:object/:recordId/lock`, `POST
/api/v1/approvals/records/:object/locks`) answer a locked readable row
`{ locked: true, lockSource: 'record' | 'master' }`, an unlocked one `{
locked: false }`; `null` (404 / `locked: null`) still means
unreadable-or-missing, never told apart.
- `'record'`: a pending request on the row itself under a locking node.
Its delete is accepted and cancels the request.
- `'master'`: the row is a `master_detail` line of a held record
(`bindDetailRowLockHook` refuses insert, update and delete). It **wins
when both hold** (a self-held line under a held master), because that is
the delete the server refuses.
- **One spelling of the answer:** `recordLockAnswer(heldByMaster,
heldItself)` in `approval-service.ts` builds it for both doors. The
single door asks the master's lock first (so a self-held line under a
held master answers `'master'`); the page door now asks the detail-row
lock of every readable row, not only of the rows its record lookup left
unlocked. Read counts per page are unchanged (the two existing
read-count pins hold byte for byte).
- **Spec contract** (`packages/spec/src/contracts/approval-service.ts`):
both return types gain the optional `lockSource?: 'record' | 'master'`
(optional, so an implementation answering `{ locked }` alone still
conforms — a pure widening; no exported type or const is added, as with
the original member). The #25934 ruling A sentence "What is answered:
`locked` only." is revised to state the new answer and cites ruling
7148480184; the batch docblock's "exactly what `getRecordLock` answers
for that id" now says "spelled as the engine spells it" and names the
anchor difference.
- **REST** (`approvals-routes.ts`): both doors serve the answer through
one projection, `recordLockPayload`, field by field — `locked`, and
`lockSource` only on a locked answer and only when it is `'record'` or
`'master'`. Anything else an implementation hands back (a request id,
`pending`, an unknown kind) is not served; a locked answer naming no
kind is served `{ locked: true }`. The route comment's parity sentence
("Each entry is exactly the single-record door's answer for that id")
now adds "as the engine spells it" and names the anchor difference.
- **Readability anchors, unchanged at both doors** (item 7148285178;
Round 2 below). The two doors keep different readability anchors on
purpose: the single door counts any returned row, the batch door only
the row whose id is the asked id; aligning them would narrow a published
answer (seat ruling on PR #37191). Pinned both ways: the single door
answers the lock for a loosely spelled id, the batch door answers it
`null`, and the two agree for every id spelled as the engine spells it.
- Docs: `content/docs/automation/approvals.mdx` states `lockSource`
where it states the lock answer, and the exact-spelling rule.
- Changeset: spec, plugin-approvals, rest at `patch`
(`Metadata-protocol: none` ⇒ patch under the changeset-level ruling; the
widening is declared on the `Clause-②` line).
**Disclosure bound (#8652 ruling 5299823744).** The field adds one kind
bit to an answer already served only to a caller who can read the row:
no request id, node, participants, approver identity, `pending` flag or
request content. A caller who can write the line already learns the kind
from the `RECORD_LOCKED` sentence; a read-only line reader learns which
of the row and its master holds it, where before they learned that one
of the two does.
**Field name, measured.** `lockSource`, as claimed: spec
`api/protocol.zod.ts` `lockSource` ("Which layer asserted the lock", an
enum beside the lock flag, `kernel/metadata-protection.zod.ts`
`MetadataLockSourceSchema`). Other `lock*` keys measured in
`packages/spec/src`: `lockedBy` (a user id, `ui/view.zod.ts`),
`lockScope` (`automation/execution.zod.ts`: global / per_record /
per_user, the scope a concurrency lock covers, not its origin),
`lockState`, `lockReason`; `heldBy` in `packages/cli` names holder
packages (a principal). None is closer.
### Read these first
1. `packages/plugins/plugin-approvals/src/approval-service.ts` —
`getRecordLock` (master asked first) and `getRecordLocks` (detail lock
over every readable row). Riskiest hunk: the master-first order in
`getRecordLock`.
2. `packages/rest/src/approvals-routes.ts` — `recordLockPayload`, the
disclosure projection.
3. `packages/spec/src/contracts/approval-service.ts` — the revised ruled
sentence.
### Two-minute verification
`pnpm --filter @objectstack/plugin-approvals exec vitest run
--maxWorkers=2 src/record-lock-read.integration.test.ts` — expect 20
tests passed, including the `lockSource` describe (self-held record
`'record'`, line of a held master `'master'`, self-held line under a
held master `'master'` and its delete refused `RECORD_LOCKED`, self-held
line under an unheld master `'record'` and its delete accepted) and the
describe pinning each door's own readability anchor for a loosely
spelled id.
## Tests
- `record-lock-read.integration.test.ts` (real ObjectQL + better-sqlite3
+ `ApprovalsServicePlugin.start()`): existing pins re-expressed with the
kind; new top-level describes — `lockSource` single/batch parity for a
self-held record, a line of a held master, a self-held line under a held
master, an unheld record and line, a self-held line under an unheld
master, the decided state; each kind tied to the delete the server
refuses or accepts; and the readability anchor: a
case-insensitive-collation stand-in (a read middleware folding `id`
predicates), with a CONTROL that the engine does hand the row back under
the loose spelling; the single door answers the lock for it, the batch
door `null`; parity for every caller on ids the engine echoes; and a
read-count pin for a page with a missing id.
- `client.test.ts`: both SDK answers carry and type `lockSource` (a
typed assignment the test program compiles).
- `rest-approvals-record-lock-route.test.ts`: both doors serve
`lockSource` on a locked answer, drop it on an unlocked one, drop an
unknown kind and extra fields.
- `approval-record-lock-read.dogfood.test.ts`: the fixture's `LOCKED`
body gains `lockSource: 'record'` (stale-fixture consequence of this
change).
<details><summary>Run readings (head 00e32ec)</summary>
Union of the derived local families at a453d12; the two ratchet
families re-run at the final head 00e32ec (its only change types two
test-call option bags).
- `pnpm --filter @objectstack/plugin-approvals test` (a453d12): `Test
Files 128 passed (128)`, `Tests 1928 passed (1928)`, lock `VERDICT
command-exit 0`.
- `pnpm --filter @objectstack/plugin-approvals typecheck` + `vitest run
src/record-lock-read.integration.test.ts` (00e32ec):
`check:test-typecheck: OK ... 8 file(s) / 321 error(s)` (unchanged
debt), `Tests 20 passed (20)`, `VERDICT command-exit 0`.
- `pnpm --filter @objectstack/rest test` (a453d12): `Test Files 429
passed (429)`, `Tests 8819 passed | 351 skipped (9170)`, `VERDICT
command-exit 0`; `pnpm --filter @objectstack/rest typecheck`: exit 0.
- `pnpm --filter @objectstack/spec build && pnpm --filter
@objectstack/spec check:generated`: `All 14 generated artifacts are up
to date`, exit 0.
- Dogfood, this file only (`pnpm --filter '@objectstack/dogfood^...'
build`, then `vitest run
test/approval-record-lock-read.dogfood.test.ts`): `Tests 1 passed (1)`,
`VERDICT command-exit 0`. Full battery not owed (no `!`, widening arm).
- `dispatch-gates --ran`: `119 derived famil(ies) accounted for — 116
run, 3 NOT-MEASURED`. NOT MEASURED (exit 3, PREREQUISITE NOT MET, all in
CI): `check-plugin-teardown-shape --self-test` (shallow clone cannot
reach its pinned fixture commit), `spec check:skill-examples`
(`client-react` not built in this worktree),
`check:dual-build-cjs-loads` (unbuilt packages).
`check:query-options-erasure` was red at a453d12 (test surface 236 to
237, two new `as any` option bags) and green at 00e32ec (`ratchet
holds`, `test surface: 236`). `check:nul-bytes` at 00e32ec: OK.
- `overlap-check`: `VERDICT clean exit 0` (origin/main and #37148).
</details>
## Round 2 (seat ruling on PR #37191), head e99cf2c
- **Anchor: not narrowed.** The single door's readability anchor is
restored byte for byte to `origin/main` (any returned row counts as
readable); the batch door keeps its strict anchor. The two doors keep
different readability anchors on purpose: the single door counts any
returned row, the batch door only the row whose id is the asked id;
aligning them would narrow a published answer (seat ruling on PR
#37191). I found no reason the single door cannot keep its anchor: the
`lockSource` master check reads the row through the engine
(`detailRowHeldByLockingApproval`, whose existing pin answers from the
row it found, not from the engine's spelling), so a loosely spelled line
of a held master answers `'master'` at the single door. The round-1
anchor-parity pin is replaced by pins for the two kept behaviours.
Changeset, `approvals.mdx`, both docblocks, the plugin docblocks and the
batch route comment now state the two anchors instead of an alignment.
- **Client SDK:** `client.approvals.getRecordLock` and `getRecordLocks`
(`packages/client/src/index.ts`) type the answer with the optional
`lockSource?: 'record' | 'master'`; pinned in `client.test.ts` with a
typed assignment. `@objectstack/client` patch added to the changeset.
Still a widening under the declared `Clause-②`.
- **Not touched:** `record-page-routes.ts` and the skills sentence
(routed to triage by the seat).
<details><summary>Round 2 run readings (head e99cf2c)</summary>
- `pnpm --filter @objectstack/plugin-approvals test`: `Test Files 128
passed (128)`, `Tests 1928 passed (1928)`; `rest` `vitest run
src/rest-approvals-record-lock-route.test.ts
src/rest-write-response-internal-fields.tripwire.test.ts`: `Tests 36
passed (36)`; `pnpm --filter @objectstack/client test`: `Test Files 59
passed (59)`, `Tests 820 passed (820)`; one lock run, `VERDICT
command-exit 0`.
- Typecheck plugin-approvals (test-layer debt unchanged at 321), rest
and client (test layer 0 errors): exit 0. `spec build &&
check:generated`: `All 14 generated artifacts are up to date`.
- Reverse checks (fix committed, worktree-only restores, both files
restored with `git checkout HEAD`, hashes equal to HEAD's):
`approval-service.ts` from 00e32ec (the strict single-door anchor)
makes the kept-anchor pin red (`1 failed | 19 passed`);
`packages/client/src/index.ts` from `origin/main` makes the client
test-layer typecheck red (`src/client.test.ts: 2 type error(s)`).
- `dispatch-gates --ran`: `120 derived famil(ies) accounted for — 116
run, 4 NOT-MEASURED`. NOT MEASURED (exit 3, PREREQUISITE NOT MET; all
run in CI): `check-plugin-teardown-shape --self-test` (shallow clone),
`spec check:skill-examples` (client-react not built),
`check:dual-build-cjs-loads` and `check:i18n` (workspace packages and
the CLI not built in this fresh worktree). `check:query-options-erasure`
and `check:nul-bytes`: exit 0.
- `overlap-check`: `VERDICT clean exit 0` (origin/main 893eac8 and
#37148).
</details>
## Round 3 (L1 7152634100, L2 PASS with S1 7152618670), head 030cd91
Wording only; no behaviour change.
- **S1:** round 2 said the single door answers "the lock" for a loosely
spelled id. That is only half true. Measured against the code:
`getRecordLock` counts any returned row as readable. Its master half
(`detailRowHeldByLockingApproval`) reads the row the engine found, so a
loosely spelled line of a held master answers `'master'` (pinned in
round 2). Its own half (`recordHeldByLockingApproval`) looks up the
pending request by the id as asked, so a record held by its own request
may answer `{ locked: false }` under another spelling. That is main's
behaviour. The spec batch docblock, the changeset and `approvals.mdx`
now say exactly this; the plugin's `getRecordLock` docblock says it too.
- **S2:** the anchor ruling is cited by comment id: seat ruling
7152650156 on #37151. It withdraws the "built with a parity pin" line of
7148480184. The citation is in the spec docblock, the changeset and
`approvals.mdx`, and also in the plugin docblocks, the batch route
comment and the test header, replacing "seat ruling on PR #37191".
Triage's anchor row 7148285178 is carried, not ticked: the seat asked
triage to move it to a carrier (mailbox #36743 comment 7152670747).
- **Nits:** the spec `getRecordLock` docblock now says an implementation
may omit `lockSource` on a locked answer (the REST doors then serve `{
locked: true }` alone); the changeset says the same. The broken sentence
in the client `getRecordLock` docblock is joined.
- **Routing:** the skills sentence is a row on #35769 (triage
7151747767), and the record-page composite is #37195 (Acceptance notes
updated).
<details><summary>Round 3 run readings (head 030cd91)</summary>
- `overlap-check`: `VERDICT clean exit 0` (origin/main bc3ec37,
#37148), run before the push.
- One lock run (`VERDICT command-exit 0`): closure build of client and
plugin-approvals (spec rebuilt), `spec check:generated` `All 14
generated artifacts are up to date`, typecheck client / plugin-approvals
(test debt 321, unchanged) / rest exit 0,
`record-lock-read.integration.test.ts` `Tests 20 passed (20)` (test
header text changed).
- Text gates, exit 0: `check:doc-authoring`, `check:issue-citations`,
`check:docs-transcript-drift`, `check:nul-bytes`, `spec check:docs`,
`check-affected-docs`, `check-empty-changeset`,
`check-changeset-no-major`, `check:spec-docblock-symbol-anchors`.
</details>
## Acceptance notes
- **Not changed, carried elsewhere:** the published skill sentence in
`skills/objectstack-automation/references/state-machines-and-approvals.md`
("`locked` and nothing else") is carried as a row on the skills sweep
card #35769 (triage 7151747767); the record-page composite
(`packages/rest/src/record-page-routes.ts`, which serves its `lock` as
`{ locked }` alone) is #37195.
- **Read-only inference, not filed:** the record-lock write hook keys a
by-id write on the id as the writer spells it; on a driver whose id
column matches a spelling the request bookkeeping does not (a numeric id
asked as `07`), the hook's request lookup and the driver's row match
could disagree. No public entry was shown to send such an id; no reach
measured.
- `ui/packages/plugin-grid/**` untouched: hiding Delete on `lockSource:
'master'` is seat 4's half under #36911.
## Verification
- Reverse verification (fix committed first): `approval-service.ts`
restored from `origin/main` (a10345a) into the worktree only,
`record-lock-read.integration.test.ts` run: 11 failed / 9 passed (round
1, at db800fe: every new and kind-bearing pin red); restored with `git
checkout HEAD --`, blob hash equal to HEAD's, `git diff HEAD` empty.
- Cross-package type check: the plugin's `getRecordLock` return type
widened to admit a third kind ⇒ `tsc --noEmit` red `TS2416 Property
'getRecordLock' in type 'ApprovalService' is not assignable to the same
property in base type 'IApprovalService'` against the rebuilt spec
`dist`; restored, hash verified.
- `overlap-check --branch=claude/issue-37151-lock-source-field`:
`VERDICT clean exit 0` — merges cleanly with origin/main and with #37148
(shares both `approval-service.ts` files, different regions).
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufzeiHatzB4rRx1t4Php)_
<!-- signed: repo:objectstack#3 · os-support-ai ·
session_01WGufzeiHatzB4rRx1t4Php -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 3d4f423 commit fd462c5
11 files changed
Lines changed: 445 additions & 98 deletions
File tree
- .changeset
- content/docs/automation
- packages
- client/src
- plugins/plugin-approvals/src
- qa/dogfood/test
- rest/src
- spec/src/contracts
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
450 | 450 | | |
451 | 451 | | |
452 | 452 | | |
453 | | - | |
| 453 | + | |
454 | 454 | | |
455 | 455 | | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
463 | 473 | | |
464 | 474 | | |
465 | 475 | | |
| |||
473 | 483 | | |
474 | 484 | | |
475 | 485 | | |
476 | | - | |
| 486 | + | |
477 | 487 | | |
478 | 488 | | |
479 | 489 | | |
480 | 490 | | |
481 | 491 | | |
482 | 492 | | |
483 | | - | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
484 | 501 | | |
485 | 502 | | |
486 | 503 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
758 | 758 | | |
759 | 759 | | |
760 | 760 | | |
761 | | - | |
| 761 | + | |
762 | 762 | | |
763 | | - | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
764 | 767 | | |
765 | 768 | | |
766 | 769 | | |
767 | 770 | | |
768 | 771 | | |
769 | 772 | | |
770 | | - | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
771 | 778 | | |
772 | 779 | | |
773 | 780 | | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
774 | 784 | | |
775 | 785 | | |
776 | 786 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7148 | 7148 | | |
7149 | 7149 | | |
7150 | 7150 | | |
7151 | | - | |
7152 | | - | |
| 7151 | + | |
| 7152 | + | |
| 7153 | + | |
| 7154 | + | |
| 7155 | + | |
7153 | 7156 | | |
7154 | 7157 | | |
7155 | 7158 | | |
7156 | 7159 | | |
7157 | | - | |
| 7160 | + | |
| 7161 | + | |
| 7162 | + | |
| 7163 | + | |
7158 | 7164 | | |
7159 | 7165 | | |
7160 | 7166 | | |
7161 | 7167 | | |
7162 | | - | |
| 7168 | + | |
7163 | 7169 | | |
7164 | 7170 | | |
7165 | 7171 | | |
| |||
7173 | 7179 | | |
7174 | 7180 | | |
7175 | 7181 | | |
7176 | | - | |
| 7182 | + | |
7177 | 7183 | | |
7178 | 7184 | | |
7179 | 7185 | | |
7180 | 7186 | | |
7181 | 7187 | | |
7182 | | - | |
| 7188 | + | |
| 7189 | + | |
| 7190 | + | |
7183 | 7191 | | |
7184 | 7192 | | |
7185 | 7193 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2232 | 2232 | | |
2233 | 2233 | | |
2234 | 2234 | | |
| 2235 | + | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
| 2240 | + | |
| 2241 | + | |
| 2242 | + | |
| 2243 | + | |
| 2244 | + | |
| 2245 | + | |
| 2246 | + | |
| 2247 | + | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
2235 | 2252 | | |
2236 | 2253 | | |
2237 | 2254 | | |
| |||
11313 | 11330 | | |
11314 | 11331 | | |
11315 | 11332 | | |
11316 | | - | |
| 11333 | + | |
| 11334 | + | |
| 11335 | + | |
| 11336 | + | |
| 11337 | + | |
| 11338 | + | |
| 11339 | + | |
| 11340 | + | |
| 11341 | + | |
| 11342 | + | |
| 11343 | + | |
| 11344 | + | |
| 11345 | + | |
| 11346 | + | |
| 11347 | + | |
11317 | 11348 | | |
11318 | 11349 | | |
11319 | 11350 | | |
11320 | 11351 | | |
11321 | 11352 | | |
11322 | 11353 | | |
11323 | 11354 | | |
11324 | | - | |
| 11355 | + | |
11325 | 11356 | | |
11326 | 11357 | | |
11327 | 11358 | | |
| |||
11335 | 11366 | | |
11336 | 11367 | | |
11337 | 11368 | | |
11338 | | - | |
11339 | | - | |
11340 | | - | |
11341 | | - | |
| 11369 | + | |
| 11370 | + | |
| 11371 | + | |
| 11372 | + | |
11342 | 11373 | | |
11343 | | - | |
| 11374 | + | |
11344 | 11375 | | |
11345 | 11376 | | |
11346 | 11377 | | |
| |||
11438 | 11469 | | |
11439 | 11470 | | |
11440 | 11471 | | |
11441 | | - | |
11442 | | - | |
11443 | | - | |
11444 | | - | |
11445 | | - | |
11446 | | - | |
11447 | | - | |
11448 | | - | |
11449 | | - | |
11450 | | - | |
| 11472 | + | |
| 11473 | + | |
| 11474 | + | |
| 11475 | + | |
| 11476 | + | |
| 11477 | + | |
| 11478 | + | |
| 11479 | + | |
| 11480 | + | |
| 11481 | + | |
| 11482 | + | |
| 11483 | + | |
| 11484 | + | |
| 11485 | + | |
| 11486 | + | |
| 11487 | + | |
| 11488 | + | |
| 11489 | + | |
| 11490 | + | |
| 11491 | + | |
| 11492 | + | |
| 11493 | + | |
| 11494 | + | |
11451 | 11495 | | |
11452 | 11496 | | |
11453 | 11497 | | |
11454 | 11498 | | |
11455 | 11499 | | |
11456 | | - | |
| 11500 | + | |
11457 | 11501 | | |
11458 | 11502 | | |
11459 | 11503 | | |
| |||
11462 | 11506 | | |
11463 | 11507 | | |
11464 | 11508 | | |
11465 | | - | |
11466 | | - | |
11467 | | - | |
| 11509 | + | |
| 11510 | + | |
11468 | 11511 | | |
11469 | 11512 | | |
11470 | 11513 | | |
| |||
0 commit comments