Skip to content

fix(approvals): the opening refusal says the object closes on its approval field only where a gap is about that field - #38546

Merged
os-project-manager merged 3 commits into
claude/o5-data-approvals-trunkfrom
claude/issue-37766-opening-lead
Nov 29, 2026
Merged

os-project-manager merged 3 commits into
claude/o5-data-approvals-trunkfrom
claude/issue-37766-opening-lead

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Leehom · project thread

Part of #37766 — the review follow-up of the opening check (slice B) named in claim amendment 7252959941; the card stays open for slice D and the held N45 work.

Clause-②: yes (widening)
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:审批因为宿主没有定时任务服务、或流程读不到而在首次提交时被拒时,提示的开头和运维日志里的那一行都不再错误地说"该对象在审批字段上关闭",改为说"这次审批会作用到一个声明了关闭状态的对象";其余被拒情形的提示和日志不变。
  • 为什么做:属于"单据关闭后锁定"这一史诗(审批与关闭状态的衔接),修正上一步审批开启检查里一句在部分情形下不属实的提示。
  • 出错会怎样:最坏情况只是被拒提示的开头一句措辞不准,不影响审批是否被拒,可以直接撤回。
  • 要你做什么:无。

What changes

The refusal at an approval's first request (openingRefusalText) always led with approvalOpeningRefusedLead, "the object closes on its approval field". Two of the gaps the opening check raises are not about that field:

  • no_job_service is raised for any object a step can act on that declares closedStates on any field (approval-opening-check.ts, section 6, the host);
  • unreadable_flow is raised before anything about the field is known (the early return for a missing root flow, and every callee that cannot be read).

Every other gap kind is pushed only inside the loop over objects that close on the step's own approval field (section 5, concernedObjects), so the field lead is true for them. Where every gap is no_job_service or unreadable_flow, the lead is now the new catalog sentence approvalOpeningRefusedClosedStatesLead: "The approval of OBJECT RECORD was not started: it can act on an object that declares closedStates." Any field gap, alone or beside those two, keeps the field lead. The per-gap sentences are unchanged.

  • src/approval-opening-refusal.ts — the lead choice: NOT_ABOUT_THE_FIELD, read through the exported predicate gapsAreAboutTheField.
  • src/approval-service.ts — the warn line logged at every opening refusal picks its wording with the same predicate (the fold below).
  • src/translations/messages.ts — the new id in all 11 packs (en, zh-CN, ja-JP, es-ES, zh-Hant, ar, fr, pt-BR, ru, de, ko).
  • src/approval-opening-refusal.test.ts — new, 6 tests.
  • src/approval-opening-check-37766.integration.test.ts — one nested describe with 2 tests on the log line (host-only refusal, plus a field-gap control). boot() gains an optional warns sink for the service logger.
  • .changeset/37766-opening-lead.md — @objectstack/plugin-approvals patch.

Authorship. The patch was written, built and reverse-verified by the slice B card thread on the trunk, which could not push it; this PR carries it after a hunk-by-hunk read. Corrections made on top of it:

  1. zh-CN, zh-Hant, ja-JP and ar said the approval acts on such an object (会作用到 / 作用します / يمكنها); the English says it can act on one, and for an unreadable flow the check does not know. Those four now carry the modal (可能作用到 / 作用する可能性があります / قد تعمل). The other six packs already read as "can".
  2. The tests no longer write the catalog's sentences out: they read both leads and the gap sentences from approvalMessages, so what they hold is which lead is chosen and in which pack, not the prose. One test added: the two leads differ in every pack. The field-gap test gains the order [host, pause].
  3. The changeset file is named 37766-opening-lead.md.

Fold: the same false claim in the refusal's log line (area decision)

The first round listed this as out of scope. approval-service.ts logged "the record's object closes on its approval field and the approval cannot show it in progress" at warn for every opening refusal, including host-only and unreadable-only ones. The area folded it into this PR. The warn now reads gapsAreAboutTheField(judgement.gaps), the one predicate the lead already uses (exported, no second copy). Where it is false, the log says "it can act on an object that declares closedStates, and this host runs no job service or a flow it runs could not be read". The logged gaps kinds are unchanged.

The four adjacency conditions, each with evidence:

  1. Same defect class as this card's fix. It is the same sentence ("closes on its approval field"), chosen under the same condition (every gap is no_job_service or unreadable_flow), at the same call site: the if (judgement.gaps.length > 0) block that throws openingRefusalText.
  2. Mechanical, with its form already fixed. The message is picked with the predicate this PR introduced; no new rule is written.
  3. No other claim holds the file. approval-service.ts is on slice C's file surface (claim 7250894927), and that claim belongs to this area. The area decision names it as its own.
  4. Same gate family, no new verification surface. The derivation for the 6 paths adds 8 families only because approval-service.ts is now in the set: check:error-code-provenance, check:adr-symbol-anchors, check:cli-command-ids, check:dispatcher-error-vocabulary, check:error-status-conformance, check:object-def-param-keys, check:optional-error-sink, check:settings-bind-window. All of them were run here and exit 0. The new tests go into the existing integration harness, not a new file.

The three checks the PM asked for

  1. reviewFace on this diff (6 paths after the fold, re-read) — reviewFace(paths, objectstack, { declaredOn: [the changeset] }) answers face declaration, tier TIER_DEFAULT, hits.schema: [], hits.rules: []. No face beyond the Clause-②: yes declaration is hit: no packages/spec path, no governed path.
  2. The new key is reachable from what the plugin publishes — confirmed. files is dist, README.md, CHANGELOG.md. After the build, approvalOpeningRefusedClosedStatesLead is in dist/index.js and dist/index.mjs; the positive control approvalOpeningRefusedLead is in the same two files. It reaches a caller two ways: as the refusal text through the request door (VALIDATION_FAILED: …, thrown at approval-service.ts around line 5259), and as messages.approvalOpeningRefusedClosedStatesLead in the i18n service, because ApprovalsTranslations loads approvalMessages as each locale's messages face on kernel:ready (approvals-plugin.ts). So Clause-②: yes (widening) is right, and so is Metadata-protocol: none: it adds nothing a metadata author can write.
  3. Each test, and the ablation — see Tests.

Tests

The tests import ./approval-opening-refusal.js relatively, from src, so neither leg needs a rebuild to reach dist.

# Test Fix in place Ablated
1 the two leads are two sentences, in every pack pass pass (catalog only, by design)
2 host's gap alone: neutral lead + the host sentence pass fail
3 unreadable flow alone: neutral lead + its sentence pass fail
4 host + unreadable only: neutral lead, never the field lead pass fail
5 a field gap, alone, before or after the host's: field lead pass pass (it pins the branch that stays)
6 zh-CN: the zh-CN neutral lead, not the field lead, not the en text pass fail
7 log line, host-only refusal: does not say "closes on its approval field" pass fail (log ablation)
8 log line, field gap (control): says it pass pass (log ablation)
Ablations: every lead forced to the field lead (head cf61012); every log line forced to the field claim (head 2668361)

node scripts/ablation-replace.mjs on approval-opening-refusal.ts, anchor aboutTheField ? pack.approvalOpeningRefusedLead : pack.approvalOpeningRefusedClosedStatesLead replaced by pack.approvalOpeningRefusedLead /* ABLATED: always the field lead */:

ablation-replace: ok mutation landed: anchor 1 -> 0, blob fa1b1a4a64ec -> a77ef02ff1a3
     × does not say the object closes on its approval field where the host's gap is the only one
     × does not say it where a flow that could not be read is the only gap
     × does not say it where the host's gap and an unreadable flow are the only gaps
     × words the lead that says nothing about the field in the run's locale
      Tests  4 failed | 2 passed (6)
ablation-replace: ok restored: blob == HEAD (fa1b1a4a64ec) and `git diff HEAD` is empty

Log ablation (head 2668361). In approval-service.ts, the anchor this.logger?.warn?.(gapsAreAboutTheField(judgement.gaps) was replaced by this.logger?.warn?.(true /* ABLATED: always the field claim */:

ablation-replace: ok mutation landed: anchor 1 -> 0, blob 99f0f8489032 -> 5d77f9ccd112
       × does not say it where the host's gap is the only one
      Tests  1 failed | 8 passed (9)
ablation-replace: ok restored: blob == HEAD (99f0f8489032) and `git diff HEAD` is empty

A first attempt at the lead ablation used the bare replacement pack.approvalOpeningRefusedLead, which is a substring of the anchor. The tool refused it ("the replacement count moved 1 -> 1"), restored the file and ran nothing. That attempt is void, not a reading.

Package suite and typecheck (head 2668361)
  • pnpm --filter @objectstack/plugin-approvals test: Test Files 137 passed (137) · Tests 2114 passed (2114) · lock VERDICT command-exit 0 (at cf61012: 2112/2112).
  • pnpm --filter @objectstack/plugin-approvals typecheck: VERDICT command-exit 0; check:test-typecheck: OK … 8 file(s) / 321 error(s) / 27 pinned signature(s) held in test-typecheck-debt.json. tsc -p tsconfig.test.json --listFiles lists approval-opening-refusal.test.ts (1 hit), so the test layer compiles the new file.
  • approval-notification-keyed-text.integration.test.ts ("every shipped locale carries every sentence, with the same holes") passes in that run and covers the new id in all 11 packs.

Acceptance notes

Verification

Read first (by risk):

  1. packages/plugins/plugin-approvals/src/approval-opening-refusal.ts, gapsAreAboutTheField, and its second caller in approval-service.ts (the warn line): does any gap kind other than the two in NOT_ABOUT_THE_FIELD get raised outside concernedObjects in approval-opening-check.ts? (Read on this head: no. Sections 5 and 6, and the early return.)
  2. packages/plugins/plugin-approvals/src/translations/messages.ts: the 11 new lines, especially the four modal corrections.
  3. packages/plugins/plugin-approvals/src/approval-opening-refusal.test.ts and the new nested describe at the end of approval-opening-check-37766.integration.test.ts.

Two-minute check: pnpm --filter @objectstack/plugin-approvals exec vitest run --maxWorkers=2 src/approval-opening-refusal.test.ts src/approval-opening-check-37766.integration.test.ts should report Tests 15 passed (15).

Local gates (head 2668361)

The derivation was dispatch-gates.mjs --commands --repo objectstack-ai/objectstack with the 6 changed paths passed explicitly (72 families; 64 at cf61012). Each one was re-run on 2668361 with its exit code captured before any pipe, plus check:i18n-coverage and check:i18n-walk-parity. --ran gives: 72 derived, 70 run, 2 NOT-MEASURED, 0 UNRUN (both derived from a recorded exit 3).

  • pnpm check:i18n (2668361: EXIT=0 after the same closure build, in sync (21 bundle(s))): at cf61012 the first run exited 3 (PREREQUISITE NOT MET — the workspace CLI is not built). After its one-command closure build under the verify lock (VERDICT command-exit 0, 70 tasks), the re-run gave EXIT=0: plugins/plugin-approvals in sync (21 bundle(s)) · check-i18n-bundles: OK (10 package(s) — all bundles in sync, no undeclared authoring keys).
  • pnpm check:i18n-coverage: EXIT=0, OK (15 config(s), 577 baselined untranslated string(s), none new).
  • pnpm check:i18n-walk-parity: EXIT=0, 19 declared group(s), 17 walked, 2 exempted.
  • pnpm check:keyed-text-bounds, pnpm check:i18n-stale-fill, pnpm check:doc-authoring, pnpm check:issue-citations, check-changeset-no-major.mjs --base origin/main, check-adr-0087-registration.mjs --base origin/main, check-empty-changeset.mjs, pnpm check:nul-bytes, and the other derived families: exit 0.
  • NOT MEASURED: check-plugin-teardown-shape.mjs --self-test. Exit 3: its positive control is pinned to a commit that this shallow clone cannot reach. CI runs it.
  • NOT MEASURED: pnpm check:dual-build-cjs-loads. Exit 3: it reads every package's dist, and only the approvals closure was built here. Build Core in CI runs it.
  • CI families: cited from the PR's check-runs once they report.

Generated by Claude Code

…e a gap is about that field

The host's gap and an unreadable flow are raised on an object that declares
closedStates on any field; where they are the only gaps, the opening
refusal's lead now says the approval can act on an object that declares
closedStates, in all 11 locale packs of the plugin's catalog.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5phEgfPTCgvPqh4ER2
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 29, 2026
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

7 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run.

What this run could not see
  • the SDK route bridge reached 69 of 253 client-bound route-ledger rows — the other 184 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 184: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 125 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 6 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 4cc09b16f4eae866c94e99a12bde24470bf1eab4 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 26f1ee75276edbd75bea96133e4f95a5edf1ba18 — the merge of head 2668361c1b12b3c7504dd8ee2311ef1c2c6fa78c into base 4cc09b16f4eae866c94e99a12bde24470bf1eab4, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older claude/o5-data-approvals-trunk holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 26f1ee75276edbd75bea96133e4f95a5edf1ba18 && git checkout 26f1ee75276edbd75bea96133e4f95a5edf1ba18
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 4cc09b16f4eae866c94e99a12bde24470bf1eab4 2668361c1b12b3c7504dd8ee2311ef1c2c6fa78c && git checkout -B drift-repro 4cc09b16f4eae866c94e99a12bde24470bf1eab4 && git merge --no-ff 2668361c1b12b3c7504dd8ee2311ef1c2c6fa78c

node scripts/docs-audit/affected-docs.mjs --json 4cc09b16f4eae866c94e99a12bde24470bf1eab4

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

… on its approval field only where a gap is about that field

The service's warn line at every opening refusal now chooses its wording by
the same predicate as the refusal's lead, exported from
approval-opening-refusal.ts, so a refusal whose only gaps are the host's or
an unreadable flow no longer logs that the object closes on its approval
field.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5phEgfPTCgvPqh4ER2
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-project-manager · session_01FEkQ5phEgfPTCgvPqh4ER2

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 2668361c1b12b3c7504dd8ee2311ef1c2c6fa78c
Local-runs: none

Face: reviewFace on the six changed paths decides no face; the changeset's Clause-②: yes (widening) line decides the declaration face, so the review is at TIER_DEFAULT (record-recognisers.mjs --face declaration). No published schema, no governed path, no narrowing line.

① Derived judgments

  • The widening: one new sentence approvalOpeningRefusedClosedStatesLead in the plugin's message catalog, present in all 11 packs (en, zh-CN, ja-JP, es-ES, zh-Hant, ar, fr, pt-BR, ru, de, ko), each with the same two placeholders {{object}} and {{record}} as the lead it sits beside. ApprovalMessages is a module-private type over AuthoredMessageId and is not on the package's exports entry, so no consumer implements the pack; adding a key takes nothing away.
  • The predicate gapsAreAboutTheField (approval-opening-refusal.ts) is the one rule for both texts that say "closes on its approval field": the refusal lead and the service's warn line (approval-service.ts) import the same export, so there is no second copy that can drift.
  • Truth of each text: when every gap is no_job_service or unreadable_flow, nothing about the field is known, so the new lead claims only that the approval can act on an object that declares closedStates, which holds for both gap kinds as approval-opening-check.ts raises them. One field gap beside a host gap keeps the field lead, which is then true of the refusal. The per-gap sentences are unchanged.
  • Tests: the host-only, unreadable-only, both, field-gap-alone and field-gap-beside-host arms and zh-CN in approval-opening-refusal.test.ts; the host-only log arm and a field-gap control in the integration harness. The dev's ablations (lead 4 failed, log 1 failed) show both branches are pinned.

② Semver level

patch for @objectstack/plugin-approvals, as the changeset says: an added message key on an unexported catalog type and a corrected sentence choice; no member, signature or wire shape changes.

③ Boundary flags

  • Dev open question (a dev patched its own PR body after pr_create): answered A. The area ordered that edit; it went through the relay's issue_patch, read back identical, signed on its last line.
  • The CI reds on cf61012af8 were lanes cancelled by the push of this head; at this head every check is success or expected skip, with one still running when read.
  • Known textual overlap only with the closed feat(approvals): the opening check's conditions are reported where a flow or an object is published (ADR-0162 item 7, slice N45) #38527 (N45 is redone as a new slice PR under ruling 7253749311); the later of the two resolves it.
  • SQL push-down: no query, id materialisation or in-app join is added.

Implemented-by: claude/issue-37766-opening-lead
Reviewed-by: session_01FEkQ5phEgfPTCgvPqh4ER2

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-project-manager · session_01FEkQ5phEgfPTCgvPqh4ER2

Final green head · 2026-11-29T09:31Z — 2668361c1b12b3c7504dd8ee2311ef1c2c6fa78c

  • Checks at this head (pr-state.mjs --pr 38546): 41 success · 16 expected skip · 0 unexpected skip · 0 failed · 0 pending; mergeable_state clean. The two reds on the earlier head were lanes cancelled by this push.
  • Base: the closed-state trunk claude/o5-data-approvals-trunk at 4cc09b16f (not main); no auto-merge.
  • Contract face: the declaration alone (Clause-②: yes (widening), one catalog key); L2 at TIER_DEFAULT PASS on this head, record 7253820549. Metadata-protocol: none.
  • Delta since the first head: the service's warn line takes the same predicate as the lead (report 7253794078 on Approvals: refuse an approval that cannot show itself on a closing field when it opens, and never write a closed value for an abandoned request (ADR-0162 item 7) #37766).
  • L1: requested from thread L1-b on this head. After ACCEPT, the area merges the slice into the trunk (--no-ff, no rebase, no force).

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-project-manager · session_01FEkQ5kjJ6Qm1z2mRox4ZbB

席位核对 — ACCEPT · L1-b · area o5-data · Head-sha 2668361c1b12b3c7504dd8ee2311ef1c2c6fa78c · 2026-11-29T09:33Z

L1 of PR #38546, the slice B follow-up of #37766 (claim amendment 7252959941), net diff from trunk claude/o5-data-approvals-trunk at 4cc09b16f4eae866c94e99a12bde24470bf1eab4 (three commits, 6 files +150/−5). L2 owed and present: TIER_DEFAULT PASS on this head, record 7253820549 (declaration face only, one catalog key; no packages/spec or governed path).

Checklist (l1-face --pr 38546 at 2668361: 1 flag, read below)

  • Shape flag: base is the trunk, not main. Expected for a trunk slice; the area merges it into the trunk with --no-ff. Part of #37766, no closing keyword, no other card bound.
  • Changeset: @objectstack/plugin-approvals patch, the one published package moved. Clause-②: yes (widening) (the catalog gains one sentence, published through ApprovalsTranslations and the request door's refusal text) · Metadata-protocol: none. gapsAreAboutTheField is exported from its module only, not from the package index, so it is not public surface.
  • Gates at this head: 41 success, 16 expected skip, 0 failed, 0 pending, mergeable_state clean. The two reds on cf61012 were lanes cancelled by this push.
  • Not Tier H: no governed path, no narrowing, small.

My readings, at this head

  • The rule is true on the tree. In approval-opening-check.ts every gap kind except two is pushed inside section 5, only for objects in concernedObjects (objects that close on the step's own approval field): the six field conditions, other_field / no_field, pause_between_steps and map_with_approval. no_job_service (section 6) is pushed for any step object that declares closedStates on any field, and unreadable_flow is pushed in the early return and for each unreadable callee, before anything about the field is known. So NOT_ABOUT_THE_FIELD = {no_job_service, unreadable_flow} is exactly the set for which the field lead can be false, and "any other gap ⇒ field lead" holds.
  • One predicate, two callers. The lead in openingRefusalText and the warn line in approval-service.ts both read gapsAreAboutTheField; no second copy. The logged gaps kinds are unchanged. The fold of the log line onto approval-service.ts is the area's decision, on its own slice C surface (claim 7250894927), and meets the four adjacency conditions as the body evidences them.
  • The 11 catalog lines. Each pack's new sentence keeps the {{object}} {{record}} holes and says only that the approval can (may) act on an object declaring closedStates; the four modal corrections (zh-CN, zh-Hant, ja-JP, ar) match the English "can". The keyed-text integration test holds every pack to the same ids and holes, and check:i18n is in sync.
  • Tests and ablations. The 6 unit tests read both leads from the catalog and pin which lead is chosen, including mixed orders and zh-CN; the 2 integration tests pin the log line with a field-gap control. Lead ablation: 4 of 6 red, restored to the HEAD blob. Log ablation at this head: 1 red, its control green, restored. The lead ablation was run at cf61012a, before the local aboutTheField became the exported predicate; cf61012a..2668361c moves that expression into gapsAreAboutTheField unchanged, and the 4 lead tests stay green at this head in Test Core, so I take the reading as carried.
  • Overlap. Merges cleanly into the trunk at 4cc09b16f; a textual conflict with feat(approvals): the opening check's conditions are reported where a flow or an object is published (ADR-0162 item 7, slice N45) #38527 (N45, held for the maintainer) in two files, resolved by whichever lands second, as the body states.

No must-fix or should-fix. After this ACCEPT the area merges into the trunk with --no-ff. #37766 stays open for slice D and the held N45 work.

@os-project-manager
os-project-manager merged commit d313098 into claude/o5-data-approvals-trunk Nov 29, 2026
57 checks passed
@os-project-manager
os-project-manager deleted the claude/issue-37766-opening-lead branch November 29, 2026 09:34
zhuangjianguo pushed a commit that referenced this pull request Nov 29, 2026
…ry locale (closedStates slice C, ADR-0162 D8) (#38516)

<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XM4tETbvX1rGDEEdPX6wiRw)_

Part of #37768

Clause-②: yes (widening: new keys in the published Operation Message
Catalog and the upload-link copy; contract-review-tier review owed)
Metadata-protocol: none

## 维护者速读

-
用户能看到什么变化:业务用户改动、删除一张已关闭(已结清、已完成)的单据或它的明细时,看到的是用自己语言写的一句话,说清是哪张单据、为什么改不了。
- 为什么做:这是「单据关闭后锁定」这项能力的第三部分,补上用户看到的提示文字;前两部分(锁本身、审批状态写回)已在同一主干上。
- 出错会怎样:最坏是提示句措辞不准或落成笼统说法,锁本身照常拦截、数据不受影响;本改动只换文字,可整体撤回。
- 要你做什么:无(合同层评审由席位按档安排)。

## What changes

This slice gives the closed-state refusal (`409 RECORD_LOCKED`,
ADR-0162) the person-facing sentence D8 rules, in every locale each
surface carries. Lands on the trunk `claude/o5-data-approvals-trunk`
(978bb2b: bfe2df8 plus #37766 slices C and B, the opening-refusal
lead #38546 and #37767 piece 3 #38540, merged into this branch with
`--no-ff` at 26b9eec, 470235d, 63d1e62 and 8b1644b); the
trunk's own PR carries the card.

**New catalog keys** (`packages/spec/src/system/operation-message.ts`,
`BUILTIN_OPERATION_MESSAGES`), in en, zh-CN, ja-JP and es-ES. The en
sentences, for review:

| key | en |
|---|---|
| `record_closed` | `{{object}} '{{title}}' is closed, so it and its
lines can no longer be changed or deleted` |
| `record_closed_unlabeled` | `'{{title}}' is closed, so it and its
lines can no longer be changed or deleted` |
| `record_closed_untitled` | `This {{object}} is closed, so it and its
lines can no longer be changed or deleted` |
| `record_closed_opaque` | `This record is closed, so it and its lines
can no longer be changed or deleted` |
| `record_closed_delete_blocked` | `{{object}} '{{title}}' cannot be
deleted: deleting it would also remove a closed {{blockingObject}} or
one of its lines` |
| `record_closed_delete_blocked_untitled` | `This {{object}} cannot be
deleted: deleting it would also remove a closed {{blockingObject}} or
one of its lines` |
| `record_closed_delete_blocked_opaque` | `This record cannot be
deleted: deleting it would also remove a closed record or one of its
lines` |

Upload-link page: a closed-state refusal reaches the page with the
engine's declared catalog sentence as its `userMessage`, and the page
shows that sentence (`storage-routes.ts` `relayUploadLinkRefusal`). The
page's `recordLocked` answers only a `RECORD_LOCKED` with no declared
sentence. `upload-link-copy.ts` also gains `recordClosed` in all 11
languages, en: `Nothing was attached: the record is closed, so no file
can be added to it.`; choosing it by the lock read's reason stays with
item 2.

**The engine words the refusal**
(`packages/objectql/src/closed-state-lock.ts`):

- The refusal names a title only from a field that holds display text
and that the writer's generic read returns: the display field gives no
title when it is a field the generic read withholds (`internal`, or a
credential type: `collectInternalReadFields`,
`collectCredentialFields`), a reference field (`REFERENCE_VALUE_TYPES`),
or a field the object's `closedStates` names.
- The title is also one the writer is served: the security service's
`getReadableFields` and `getQueryableFields` for the writer both hold
the field. The service comes from the engine's existing security-service
slot (the one `ObjectQLPlugin` fills). An empty slot, or a source that
answers `null` or nothing, is no field-level security, so the title is
served. So it is when the source throws and no `security` service is
registered at all: `ObjectQLPlugin` fills a second slot beside the
source (`SECURITY_SERVICE_REGISTERED_SLOT`, not public surface) with a
probe that answers whether one is registered, read without building one,
and only this title rule reads it. A source that throws for a service
that is registered (a factory that throws, or one the sync accessor does
not build), a service that cannot say, or a field the writer is not
served or is served masked, gives the label form. The rules on which
field a title is read from apply first, on every kernel.
- A record's own write (by id): titled, or the label form. A predicate
write: the label form.
- A line's write, a new line, a line moved, a line restored: the
master's label alone (`record_closed_untitled` of the master).
- A delete refused for what it would also remove: the record asked to be
deleted, plus the label of the object in the way. The root's title is
used only when the delete names exactly one record by id and its title
is served; a delete that names its rows by a predicate, one row matched
or many, takes the untitled form.
- An object with no label: the `_unlabeled` / `_opaque` forms. Never the
API name.
- On the error: `userMessage` = the sentence; `message` =
`RECORD_LOCKED: ` followed by the sentence (the pending lock's shape);
`developerMessage` = the developer sentence (API names), which the REST
layer does not relay. No new member on the published error body;
`ClosedStateRefusalWording` is module-internal (not exported from the
package index).
- `packages/objectql/src/plugin.ts` sets the registration probe beside
the security source. The probe answers `false` only on the kernel's
branded "never registered" rejection (`isServiceNotRegisteredError`); a
factory-registered service the sync accessor refuses ("is async") counts
as registered and is not built. Every other reader of the source slot
(the `ReadableIds` resolution, the search's queryable-field read) reads
only the source and answers as before.
- Plumbing only: `engine-cascade-planning.ts`,
`engine-delete-and-aggregate.ts` and `engine.ts` pass `facade`,
`validationMessageContext` and `logger` into the hosts that judge the
cascade and the delete, and the by-id delete passes the id it names to
the cascade. `engine.ts` keeps its line count (the facade ceiling).

### Measured answers to the four mechanism assumptions

1. **Held.** At the trunk tip (bfe2df8) the refusal carried only the
developer `message`, with no `userMessage`. REST `mapDataError` writes
the `message` (without its `CODE: ` head) to the body's `error`, which
the Console toast shows. Pinned on the wire now
(`closed-state-refusal-wire.dogfood.test.ts`): `error` and `userMessage`
both carry the catalog sentence; `developerMessage`, `reason`,
`lockReason` and `blockingObject` are not in the body.
2. **Held in part; no new seam needed.** The pending lock
(plugin-approvals `lifecycle-hooks.ts`, `lockedError` + `recordTitleOf`)
carries its sentence as `userMessage` and `RECORD_LOCKED: sentence` as
`message`, and REST relays a declared `userMessage`
(`withDeclaredUserMessage`). The engine reaches the same
field-permission reading through the security-service slot objectql
already owns (`SECURITY_SERVICE_SOURCE_SLOT`), with a registration probe
beside it in a second internal slot (`SECURITY_SERVICE_REGISTERED_SLOT`,
not public surface). No dependency on plugin-approvals, no new service,
no new published type or error member. So no `needs_decision`.
3. **Counted from the tree.** The catalog carries 4 locales (en, zh-CN,
ja-JP, es-ES), and each new key is in all 4. The upload-link copy
carries 11 (one per platform locale tag, as its test pins), and
`recordClosed` is in all 11.
4. **Approval mirror held; assignment rules: there is no write to
exempt.** The approval status mirror's `pending` (on opening) and
`approved` (on decision) both land on a record closed by another field.
They are system writes, and the caller's own write is refused 409
between and after (`closed-state-system-writes.test.ts`). The assignment
rules write no stored record: the engine evaluates them only on a row it
is inserting, before the write, and an update never evaluates a rule
(`assignment-rules.ts` docblock, "An update never evaluates a rule"). A
caller inserting a row already in its closed state has it routed, and
the insert lands (an insert of the record itself is not judged). The
caller's later write is refused, and the refused update ran no rule.

## Tests

- `packages/spec/src/system/operation-message.test.ts`, new describe for
the D8 keys. Checks: each key in every locale with placeholder parity;
translations differ from en; each form differs from its pending twin and
carries no approval word; no `RECORD_LOCKED`, `closedStates`,
`master_detail`, `_id` or cascade wording; distinct from every other
key; zh and ja render, de falls back to en; a deployment override wins.
- `packages/services/service-storage/src/upload-link-copy.test.ts`:
`recordClosed` exists in every platform locale and differs from
`recordLocked`; a `RECORD_LOCKED` with no declared sentence reads
`recordLocked`; the table's locales equal the platform's.
- `packages/qa/dogfood/test/closed-state-refusal-sentence.test.ts`,
engine over SQLite with a field-security stand-in in the engine slot.
Covers:
  - titled, unread-field and masked-field forms, and no service at all;
- a security-service source that throws gives the label form, and one
that answers `null` gives the title;
- a title field the generic read withholds (`internal`, credential), a
reference title field, and a title field `closedStates` names: the label
form on the record's update, its delete, and a cascade-delete root, with
a display-text control;
- a delete that names its rows by a predicate takes the cascade's label
form, one row matched or many;
  - a service lacking `getQueryableFields` falls to the label form;
  - predicate writes;
  - line update, delete, create and move, all with the master label;
- cascade titled and untitled, and a cascade through a lookup reaching a
closed invoice's line;
  - many-root delete;
  - unlabeled and opaque forms;
  - zh-CN and es-ES;
  - restore;
  - `developerMessage` keeps the API name;
  - could-not-judge carries no `userMessage`;
- a title read that fails on the refusal path is reported at `warn` and
the refusal stands in the label form (ablation: with the report removed
from the rebuilt dist, this case goes red with `expected [] to have a
length of 1`);
- ablation for the title-field, source and named-ids rules: with the
three rules reverted in a rebuilt dist, the 6 cases above go red, and
they are green with the rules restored.
- Every case asserts `code` + `status`, and every person-facing string
is checked for the absence of every API name, record id and state value.
- `packages/qa/dogfood/test/closed-state-refusal-wire.dogfood.test.ts`,
`bootStack` with the real `SecurityPlugin`. Covers:
  - titled update;
- the field-withheld writer gets the label form (control: its read
carries no title field);
  - closed delete;
  - line update and create;
  - cascade delete, titled;
  - zh-CN;
  - what the wire does not relay;
- D10 at the security layer: object permission refuses, so the closed
and open records give the same status and body (403
`PERMISSION_DENIED`); row access refuses, so the same body with the ids
normalized (control: the owner gets 409).
- `packages/qa/dogfood/test/closed-state-system-writes.test.ts`: the
approval mirror and assignment-rule results above. The host runs the
approvals sweeps (`noteSweepClockScheduled`), as #37766 slice B's
opening check requires. It registers no `security` service, so the
caller's refusal there names the record's title.
-
`packages/qa/dogfood/test/closed-state-refusal-security-source.test.ts`,
real `ObjectKernel` with `ObjectQLPlugin`, by what the kernel registers
under `security`. Covers:
- no `security` service registered: the title on update, delete and a
cascade-delete root;
- on that kernel, a title field the generic read withholds (`internal`,
credential), a reference title field and a title field `closedStates`
names: the label form, on update, delete and a cascade-delete root;
- a `security` service registered as a factory that throws: the label
form;
- a `security` service registered as a factory the sync accessor does
not build: the label form, and the refusal builds nothing (the factory's
call count and the other readers' answers are the same before and
after);
- the other readers of the source (`resolveReadableIdsSecurity`,
`resolveSearchQueryableFields`) give the same answer before and after a
refusal, with no service registered and with a factory that throws;
  - a source that throws with no probe beside it: the label form.
- Ablation: with the probe read removed from the rebuilt dist, the
no-security title case here and both system-writes cases go red (3
failed, 8 passed). With the "is async" line removed from the probe, the
builds-nothing case goes red. All are green with the source restored.

<details><summary>Suite readings (head 8b1644b, the merge of trunk
978bb2b; the slice's 14 paths are byte-identical to
37e4afa)</summary>

- On the merged tree 8b1644b, closure rebuilt first: plugin-approvals
full suite (138 files / 2142 passed) and `typecheck`; the slice's
dogfood files with `closed-state-lock.test.ts` (5 files / 108 passed,
`closed-state-system-writes` 2/2) and dogfood `typecheck`; objectql
`registry-closed-state-fold.test.ts` and
`federated-injected-column-readers.test.ts` (2 files / 18 passed) and
`typecheck`; spec `operation-message.test.ts` (112 passed) and
`typecheck`; service-storage `upload-link-copy.test.ts` (7 passed).
Every run VERDICT command-exit 0.
- On the earlier merged tree 63d1e62 (trunk d313098), closure
rebuilt first: plugin-approvals `approval-opening-refusal.test.ts` and
`approval-opening-check-37766.integration.test.ts` (2 files / 15 passed)
and `typecheck`; objectql `registry-closed-state-fold.test.ts` and
`federated-injected-column-readers.test.ts` (2 files / 18 passed) and
`typecheck`; spec `operation-message.test.ts` (112 passed) and
`typecheck`; service-storage `upload-link-copy.test.ts` (7 passed); the
slice's dogfood files with `closed-state-lock.test.ts` (5 files / 108
passed). Every run VERDICT command-exit 0.
- The readings below were taken at 37e4afa (the 7f9538f tree plus
the changeset), before the merge.

- `pnpm --filter @objectstack/objectql typecheck` then the full objectql
vitest run: Test Files 644 passed (644) · Tests 14559 passed. VERDICT
command-exit 0, at 7f9538f's tree.
- Dogfood: `closed-state-refusal-security-source` (9),
`closed-state-refusal-sentence` (19),
`closed-state-refusal-wire.dogfood` (9), `closed-state-system-writes`
(2) and the trunk's `closed-state-lock.test.ts`: 5 files / 108 tests
passed, then dogfood `typecheck`. VERDICT command-exit 0. The closure
(`@objectstack/dogfood^...`) was rebuilt from this tree first.
- service-storage `upload-link-copy.test.ts` (7 passed) and `typecheck`;
spec `operation-message.test.ts` (112 passed) and `typecheck`. VERDICT
command-exit 0. This round changed only docblocks in those two packages.
- Earlier rounds, sources unchanged since: service-storage full test (88
files, 1745 passed, 1 skipped); spec full test (915 files, 28942 passed,
1 todo, at 67dd8de); plugin-approvals opening-check and status-mirror
integration files (4 files / 112 tests).
</details>

## Acceptance notes

- **Could-not-judge keeps the developer sentence.** A refusal the lock
gives because it could not judge the write (an unsupported predicate
shape, for example) sets no `userMessage`; its `message` is the
developer sentence. This follows the pending lock's bound refusal. D8's
family has no form for it; see the report's open question. Carrier for a
sentence form of its own: #38518.
- **No `security` service registered names the title; a registered one
that cannot be resolved does not.** On a kernel with `ObjectQLPlugin`
and no `security` service, the source throws and the registration probe
answers that nothing is registered, so the refusal names the title D8
gives (after the title-field rules). A service registered as a factory,
one that throws or one the sync accessor does not build, takes the label
form, as does an engine whose source throws with no probe beside it. An
engine whose slot is empty, or whose source answers `null`, names the
title.
- **The probe reads one message.** To avoid building a
factory-registered service, the probe treats the sync accessor's "is
async" refusal (the message the kernel keeps verbatim for callers that
match on it) as registered. That read can only make the answer
"registered", which names no title. If the message ever changed, the
probe would fall through to the async accessor, which builds the
factory; the builds-nothing test pins that it does not. Carrier for a
public, non-building registration read in core that would remove this
message read: #38559.
- **The untitled cascade form is pinned at the engine, not on the
wire.** On the booted stack, a writer whose permission set has the
customer's title field `readable: false` is refused the delete of its
own customer, in its own organization, with 403 `PERMISSION_DENIED`
(`record_access_denied`). The security layer refuses before the engine
is reached, while the same writer's GET of that row answers 200.
Reported out of scope (plugin-security lease), not worked around.
Carrier: #38517.
- The PR base is the trunk; `dispatch-gates.mjs` was given this slice's
14 paths explicitly, because its default change set is measured against
`origin/main` and would include slices A and B.
- A title read that fails on the refusal path is reported at `warn`
through the engine's logger (threaded to the cascade judge's host), and
the refusal stays whole in the label form
(`check:durability-log-level`).
- `overlap-check` (base `origin/claude/o5-data-approvals-trunk`):
VERDICT overlap exit 1, for the one known #38268 conflict in
`engine-delete-and-aggregate.ts` and `engine-update.ts`, which exists
between the trunk tip and #38268 already (measured with `git
merge-tree`). This slice adds no new conflicted file.

## Verification

Read first, by risk:
1. `packages/objectql/src/closed-state-lock.ts`, `titleFieldOf`,
`titleFieldIsServed` and `servedTitleOf`, with
`packages/objectql/src/plugin.ts` `securityServiceRegistered`: the rules
that decide whether a title appears.
2. `closed-state-lock.ts`, `judgeClosedStateCascadeSet`, and
`engine-cascade-planning.ts` `cascadeDeleteRelations`: the `named` ids
decide titled versus untitled for a cascade.
3. `packages/spec/src/system/operation-message.ts`: the seven new keys
in four locales.

Two-minute check: `pnpm --filter @objectstack/dogfood exec vitest run
--maxWorkers=2 test/closed-state-refusal-wire.dogfood.test.ts`. Expect 9
passed, including "a writer whose field permissions withhold the title
field is told the label form, never the stored title".

<details><summary>Gates (run at 37e4afa; reconciled at
8b1644b)</summary>

- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` was given this slice's 14 paths (the diff
against the trunk, then 4cc09b1; the same 14 paths against
978bb2b) and derived 101 commands (the 98 of last round plus
`check:init-service-contract`, `check:startup-registry-verdict` and
`check:wildcard-fallthrough`, from `plugin.ts`). All 101 ran unlocked at
7f9538f, one after another, each exit code captured before any pipe:
100 exited 0, and `check:dual-build-cjs-loads` answered `PREREQUISITE
NOT MET` (exit 3, three packages had no dist in this worktree). After
building those three it exited 0. The 21 families the changeset path
derives were re-run at 37e4afa, the changeset's own commit, and all
21 exited 0.
- `--ran` reconciliation, derived at 8b1644b against 978bb2b: `✓
dispatch-gates --ran: 101 derived famil(ies) accounted for — 101 run, 0
NOT-MEASURED (a DERIVED zero — all 101 recorded an exit code and none of
them is 3).`
- The derivation warns that this tree is behind `origin/main` (by order,
the trunk is not merged with main). Families CI runs on the PR are read
from the PR's check-runs, not re-run here.
</details>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01FEkQ5nGQtUA88SthJbYyRw

<!-- signed: repo:objectstack#5 · os-project-manager ·
session_01FEkQ5nGQtUA88SthJbYyRw -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…d to change and held for its whole approval (closedStates, ADR-0162) (objectstack-ai#38810)

<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9HqHpbnZfMBnSP27W5MzeEY)_

Part of objectstack-ai#37768
Part of objectstack-ai#37766
Part of objectstack-ai#37767

Clause-②: yes (narrowing)
Metadata-protocol: semantic
Skills-docs: follow-up objectstack-ai#38425

**This PR supersedes objectstack-ai#38497** (the approvals trunk
`claude/o5-data-approvals-trunk` → `main`). The trunk took its two
`main` refreshes as squashes, which left its history without `main` and
objectstack-ai#38497 in conflict with `main` again. This branch is the trunk with its
history joined to `main`: it carries every commit on the trunk, and
`main` up to `2fba83493b`. The Part-of lines and the two declarations
above are objectstack-ai#38497's; Clause-② carries the narrowing arm of piece 5
(objectstack-ai#38746, `feat(approvals)!`), which landed on the trunk after objectstack-ai#38497's
body was written. objectstack-ai#38497's description follows unchanged below, under
"The trunk (from objectstack-ai#38497)".

## 维护者速读

- 改了什么:objectstack-ai#38497 的全部内容(单据关闭态锁定 ADR-0162 的 A/B/C 各片、objectstack-ai#37766 各片、审批 objectstack-ai#37767
各块,含第 5 块「审批全程锁单」),改由这个 PR 落到 main;objectstack-ai#38497 由席位关闭。
- 为什么换 PR:主干两次刷新都被 squash 合入,主干和 main 的历史断开,objectstack-ai#38497 又与 main
冲突;这条分支内容等于主干加最新 main,历史里带着 main,所以对 main 是干净的。
- 谁受影响:同 objectstack-ai#38497 下文说明;声明了 `closedStates` 的对象受影响,没声明的照旧。
- 要你做什么:待 battery、L1 与非实现方契约复审之后,由席位交棒。

## How this branch is built

- Trunk head `a5f33621e3` (objectstack-ai#38797, squashed; its tree is `85aea4d1c2`).
- `77e94868d0` merges `8ff2442358`, the gated head objectstack-ai#38797 squashed: same
tree `85aea4d1c2`, no content change; it puts `main` up to `fc198b2847`
into the history.
- `2f344f7b1d` merges `origin/main` at `2fba83493b` (7 commits after
`fc198b2847`) through `scripts/pm/os-regen-merge.sh`: no conflict, and
none of the 7 commits touches a file the trunk's own changes touch.

## Trunk refreshes with `main`, and their records

- objectstack-ai#38791 (`main` at `59faf74c6f`): L1-b ACCEPT 7284982294, contract
review PASS 7285519382, seat record 7285551596; DELIBERATE CORRECTION
declaration 7284894883.
- objectstack-ai#38797 (`main` at `fc198b2847`): L1-b ACCEPT 7289462740, contract
review PASS 7289911344, seat record 7289942965; DELIBERATE CORRECTION
declaration 7289249692.

## Measured on this head

- `scripts/pm/dispatch-gates.mjs` against `main`: 147 derived, 147 run,
0 NOT-MEASURED, all exit 0.
- Regeneration from this tree (`gen:schema`, `gen:docs`,
`gen:liveness-counts`, then `check:generated` and
`check-system-context-census.mjs`): exit 0, and the tree was unchanged
after it.
- Tests and typecheck green: objectql, metadata-protocol,
platform-objects, plugin-approvals, core, service-automation, spec,
runtime; cli tests green; dogfood 500 files / 4295 tests passed.
- A trial merge of this head with `main` at `0fc9eab900` has no
conflict.

## The trunk (from objectstack-ai#38497)

> **Trunk moved (seat repo:objectstack#5, area o5-data).** This PR
replaces objectstack-ai#38421, the same closed-state trunk handed back by seat 2
(clock-out brief 7250342397 on objectstack-ai#34478). The trunk branch is now
`claude/o5-data-approvals-trunk`, cut from
`claude/project-thread-yxheps` at `bfe2df88b` and written only by area
`o5-data`. Since the hand-back it carries objectstack-ai#37766 slice C (PR objectstack-ai#38485,
merged into this trunk as `07f0923c5c` with `--no-ff`). Still to land on
this trunk before it leaves draft: objectstack-ai#37766 slices B and D, objectstack-ai#37767 pieces
3–5, objectstack-ai#37768 slice C (Release-order lines on those cards). The sections
below are objectstack-ai#38421's, for slices A and B of objectstack-ai#37768 and piece 2 of objectstack-ai#37767;
the slices added since are described in their own PRs.

> **Since landed on this trunk** (all in this PR's diff): objectstack-ai#37766 slices
B and D: objectstack-ai#38499, objectstack-ai#38546, objectstack-ai#38562, objectstack-ai#38563; objectstack-ai#37767 pieces 3–5: objectstack-ai#38540
(piece 3), objectstack-ai#38618 (piece 4), objectstack-ai#38746 (piece 5), with the ADR-0162
revision objectstack-ai#38601; objectstack-ai#37768 slice C: objectstack-ai#38516. Two refreshes with `main`:
objectstack-ai#38791, objectstack-ai#38797.

> (objectstack-ai#38497 as written) Clause-②: yes (widening: one new optional
authorable key, `ObjectSchema.closedStates`, and the engine's
enforcement of it)
> (objectstack-ai#38497 as written) Metadata-protocol: added
> (objectstack-ai#38497 as written) Skills-docs: follow-up objectstack-ai#38425

### 维护者速读

-
用户能看到什么变化:对象上写了「哪些状态算已关闭」后,单据一旦进入这些状态(比如发票已付款、已作废),它和它的明细行就不能再被普通用户改、删、挪动明细或加明细,系统返回
409「记录已锁定」;批量操作只要碰到一条已关闭的单据就整批不执行。系统自身的写(汇总重算、审批回写状态)照常落地。没写这个键的对象完全不变。
- 为什么做:单据关闭态锁定(ADR-0162)的第一、二部分:A
定下这个键和编写规则,B(本次新增)让平台真正按它锁单据,应用不用再手写锁定代码,也第一次能挡住「删一条明细」这种以前挡不住的改动。
-
出错会怎样:只影响写了这个新键的对象。最坏情况是该锁的没锁(回到今天的样子),或者某个平台内部写被误锁(已逐条列出并测试)。分支在拒绝文案(C
部分)和审批两张卡落地前不合并,所以不会单独发布。
- 要你做什么:无。有一条覆盖层的发现交座位判断是否要上决策卡(见 Acceptance notes「Overlay」)。

### What changes

#### Slice A — the key (ADR-0162 D1)

Slice A of objectstack-ai#37768 (ADR-0162 D1, the key), on the card's trunk branch.
Slices B (the engine's judgement, D2–D7, D10) and C (the refusal, D8)
land on this same branch; it does not merge before the card's
`Release-order` line is met, so the key is never published without its
enforcement (ADR-0078, ADR-0162 D10).

**Spec (`packages/spec`)**
- `ObjectSchema.closedStates`: optional map from a field of the object
to the list of that field's values that close a record, e.g. `{ status:
['paid', 'void'], approval_status: ['approved'] }`. The record is
guarded against a `__proto__` key like `fields`. No default, so no
parsed object grows a key. TSDoc and `.describe()` state the contract
D1–D5 give.
- `refuseDishonestClosedStates` (`src/data/closed-states.ts`, outside
the barrel, the `stage-field-kinds.ts` precedent), called from the
object's `superRefine`. One located `custom` issue each, at
`['closedStates', FIELD]` or `['closedStates', FIELD, i]`: a key naming
no field of the object; a field that is not a single-value `select`
(another type, `radio` included, or `multiple: true`); a select with no
inline `options` (a `picklist`-backed one); an empty list; a value that
is not one of the field's options; a repeated value. Because the object
document is judged whole, the same refusals cover removing or retyping a
named field and removing a listed option: the next version leaves a
declaration that names what the edit took away.
- Studio object form row (Advanced section, JSON row beside
`uiReadonlyWhen`).
- Liveness row `object.closedStates`: **`planned`**, evidence
`closed-states.ts#refuseDishonestClosedStates` (the refusals, live at
parse) — the `enable.aiReadable` precedent. It turns `live`, with its
runtime proof, in slice B: nothing on this branch reads the key at
runtime yet. See Acceptance notes.
- Regenerated: reference docs
(`content/docs/references/data/object.mdx`,
`packages/spec/docs/references/**`), the authorable-surface record
(`data/Object:closedStates`), liveness state counts (object: planned 1 →
2).

**Other packages**
- `metadata-core` FLS scrub: `closedStates` classified as a map keyed by
this object's fields (`recordOf(keep, true)`): an entry whose field is
denied to the caller is left out of the served definition, an emptied
map is deleted, and the values (option codes) are literals, never read
as references.
- `platform-objects`: the form row's label and help text authored in all
ten translated metadata-forms locales (ar, de, es-ES, fr, ja-JP, ko,
pt-BR, ru, zh-CN, zh-Hant), `en` regenerated by `check-i18n-bundles
--write`; two derived leaf-count pins moved (+2 leaves in `advanced`, +1
translated label).
- Three changesets: `@objectstack/spec` minor,
`@objectstack/metadata-core` patch, `@objectstack/platform-objects`
patch (the `uiReadonlyWhen` precedent).

#### Slice B — the engine's judgement (ADR-0162 D2–D7, D10)

**Engine (`packages/objectql`)**
- `closed-state-lock.ts` (new): the one judgement every write door
calls. A record is closed when its STORED row holds a listed value (D2);
its unit is the record plus its direct `master_detail` lines, and a
junction row is a line of both masters (D3). Every write a system
context does not make is bound, and a write with no context is bound
(D5). The refusal is `409 RECORD_LOCKED` with `reason` (`record_closed`
· `master_closed` · `cascade_reaches_closed` · `cannot_judge`),
`object`, `blockingObject`, `lockReason: 'closed_state'`; the message
names no id and no state value. D8's sentences are slice C.
- Wired doors: by-id update and delete (`engine-update.ts`,
`engine-delete-and-aggregate.ts`, judged against the prior row the write
already reads); predicate update and delete (refused whole before any
row is written: one existence probe on the record, and for lines one
semi-join probe where the store compiles the composed `ReadableIds`
leaf, else the write's one read of its matched rows under
`MAX_BULK_PER_ROW_HOOK_ROWS`); insert and insertMany (a line under a
closed master; partial-mode insertMany is refused whole); the cascade
set where it is planned (`engine-cascade-planning.ts`, D6); restore
(`recycle-bin/restore.ts`, D7).
- Placement (D10): after the middleware gates, before the before-hooks.
A master the write NAMES goes through the caller's own read door first
(`masterDetailHeadersCallerReads`), so an unreadable master answers as
before and the lock never confirms that a record the caller cannot read
exists; a STORED master is read by the engine.
- `closed-state-values.ts` (new): `closedValuesOf`, split out so the
registry does not import the write path.

**Registry fold (seat review S1, `registry-closed-state-fold.ts`, new)**
- An extension that redeclares a field the served `closedStates` names,
and removes it, retypes it, makes it multi-value or narrows its options
past a listed value (or leaves it with no inline options), has THAT
redeclaration refused: the field stands as the fold had it, the fold
logs it once naming the package, and the rest of the extension lands.
One test per case. The four guarantee sentences of slice A stand as
written.
- A tenant overlay (the fold's base) may ADD closed values; the served
declaration is the package's list with the overlay's added, and a field
the package's list names keeps the package's definition where the
overlay broke it.

**Other**
- Liveness `object.closedStates` → **`live`**, evidence the engine's
reads and the dogfood suite; state counts regenerated.
- Error-code ledger: `RECORD_LOCKED` registered under
`@objectstack/objectql` (third emitter beside plugin-approvals and
rest). This is a D8 ledger line pulled forward because B already throws
the code; C keeps the sentences.
- Changeset `@objectstack/objectql` minor; the spec changeset gains the
ledger line.

**After the seat's delta review (7249320091, PASS), head 8e95b36**
- S2: every master check is asked of the store: one existence probe per
chunk of ids with the closed predicate in its `where` and `fields:
['id']` (`anyClosedAmong`), never a read of state columns tested in
process. The cascade set is judged the same way: one probe per chunk for
its own state, and for its lines the predicate door's semi-join where
`lineProbeServes` says the store runs it; only a store that cannot keeps
the read of the lines' keys, then one probe of their masters (D4's
stated fallback). Pinned per shape by `a cascade that reaches a line of
a closed record is refused …` (probe store: no read of the master;
no-probe store: one probe carrying the predicate, `fields: ['id']`).
- N2: where the fold restores the package's field over an overlay that
broke it, the overlay's added closed values for that field are served
only where the package's field declares them.
- CI on a0d9493: the system-context census row for
`boundByClosedStates` (row 29g on
`content/docs/permissions/system-context.mdx`, register regenerated).
The local census had passed before the commit because it walks tracked
files only.
- Carried to slice C by the seat: tests for the assignment-rule and
approval-mirror system writes, a plugin-security-level D10 test, and the
API names in the developer `message`.

#### Engine-derived writes (Done-when list)

| Write | Context it runs in | What the lock does | Test |
|---|---|---|---|
| Referential clear of a deleted record's references (`set_null`) |
system (reference-cleanup elevates; the clear also carries the
referential-clear marker) | lands: exactly the cleared field | `a
referential clear lands on a closed record` |
| Recycle-bin relink on restore | caller, carrying
`REFERENTIAL_CLEAR_OPTION` | lands (a bare reference restore, the
clear's inverse) | `the recycle-bin relink puts a cleared reference back
on a closed record, for the caller` |
| Roll-up summary recompute | `{ ...caller, isSystem: true }` | lands |
`the summary recompute writes the closed invoice in a system context,
and lands` |
| Cascade legs of a planned delete | caller | judged ONCE, at the
planned set (D6); legs are not judged again | `a delete whose cascade
reaches a closed record removes no row`, with and without transactions |
| Change Owner (`changeRecordsOwner`) | **caller** | bound: each closed
record (and line) is a `RECORD_LOCKED` failure, the open ones move |
Change Owner block (4 tests) |
| Banned-user hand-over (`transferUserAssignedWork`) | **caller** |
bound: closed records stay with the user, counted as failures | `the
hand-over of a user's work leaves the closed records …` |
| Assignment rules | system | lands | not added here (system, unbound by
D5) |
| Approval status mirror | system, attributed | lands | measured below |

The two writes that run in the CALLER's context (Change Owner and the
hand-over) are bound, not exempted, and are reported to the seat as the
card asks.

#### Measured: the approval mirror and the request's finalisation

They do **not** share one unit of work. `ApprovalService` finalises the
request (`engine.update('sys_approval_request', …, { context: SYSTEM_CTX
})`, `approval-service.ts` ~6305) and then calls `mirrorStatusField`
(~6312), which issues its own `engine.update` with no transaction handle
and swallows a failure into a warning (`approval-service.ts`
~4989–5015). The same order holds at recall, reject, return and the
dead-run abandon (~7110, ~7726, ~7768, ~9810). A mirror that fails
leaves a finalised request and an unmirrored record. The lock does not
change this: the mirror is a system write and lands on a closed record.

#### Hook-supplied master (N14)

A master a `beforeInsert` / `beforeUpdate` hook supplies is **not**
judged: the lock runs before the before-hooks (D10), so it judges the
master the caller named. Pinned by `a master a beforeInsert hook
supplies is not judged by the lock`.

### Why

ADR-0162 (merged as `972114df`), Execution item 1, on the maintainer's
rulings recorded on objectstack-ai#32004 (7073676422) and objectstack-ai#36253 (7200732942,
7201405662, 7205949718). Apps that must freeze a decided document
hand-code it today and cannot guard the removal of a line at all.

### Tests

**Slice B**
- `packages/qa/dogfood/test/closed-state-lock.test.ts` (new, 69): on
SQLite in two store shapes, each pinned, a store that runs the line
probe and one that declares `readableIdsLeaf: false` (the MongoDB /
OData shape). Every row of D4's table, for a record and for a line,
single-row and many-row, on both shapes; the read shape of each (probe:
one statement on the line table; no probe: the matched rows plus one
read of their masters); the three cannot-judge cases (a master named by
something that is not one id, a state read that fails, a many-row line
write past the per-row ceiling with 10,001 seeded lines, with the
probe-store control that lands); the closing write lands whole and the
next is refused; no context refused; system writes, deletes and
restores; the cascade removes no row with and without transactions;
restore; engine-derived writes; a refused write runs no before-hook; an
object that declares nothing reads nothing extra; Change Owner and the
hand-over.
- `packages/objectql/src/registry-closed-state-fold.test.ts` (new, 13):
the four extension breaches each refused with the rest of the extension
applied, two controls; overlay may add, may add to an object with none,
may not shorten (key left out, fewer values), may not break a named
field, relabel control, and an overlay's added value for a field the
package's version of which is restored is not served (N2). Measured:
with the two guards disabled, 7 of the first 12 fail.

**Slice A**
- `packages/spec/src/data/closed-states.test.ts` (new, 22 cases): the
ADR example parses and keeps its value; absent stays absent; no tie to a
`state_machine` rule either way; `create()` keeps it; each refusal
above, one located issue each, with its message's subject; one issue per
offending entry with a sound entry untouched; removing the field,
retyping it, making it multi-value and removing a listed option each
refused, with the control that removing an unlisted option lands; the
save and publish door (`getMetadataTypeSchema('object')`) and the stack
door refuse at the same path; a line object needs no declaration and may
declare its own.
- `metadata-core` `object-schema-fls-references.test.ts`: a denied
field's entry dropped and the readable one kept; a map left empty
deleted; CONTROL: a value spelled like the denied field is served as
written.
- Moved pins, each with a history line:
`compose-stacks-merge-collection-refusal.test.ts` and
`compose-stacks-collection-pipe-arm.test.ts` — `closedStates` is an
object-level collection, so `composeStacks` `objectConflict: 'merge'`
refuses two stacks that declare it differently (new `it.each` row), and
it is the first collection key on the real shape behind a preprocess
stage, which the landed reading carries and the in-only reading does not
(the invariance case now pins exactly that);
`protocol.meta-types-degenerate-derivation.test.ts` object 53 → 54
top-level properties; the two `platform-objects` echo-decision counts.

<details><summary>Slice A local runs (head 5d8b45b)</summary>

- `pnpm --filter @objectstack/spec test`: 913/915 files on the first
run; the two red files were the composeStacks pins above, re-run green
after the move (92/92).
- `pnpm --filter @objectstack/metadata-core --filter
@objectstack/platform-objects test`: 29/29 files, 1121 tests; 130/130
files, 2218 tests.
- `pnpm --filter @objectstack/metadata-protocol exec vitest run
src/protocol.meta-types-degenerate-derivation.test.ts`: 18/18.
- `typecheck` of spec, metadata-core, platform-objects: exit 0.
- `pnpm --filter @objectstack/spec check:generated`: all artifacts up to
date (after `--fix` rebuilt the dist; it wrote nothing).
- `pnpm check:i18n`: OK, all bundles in sync.
- `node scripts/pm/dispatch-gates.mjs --ran`: 122 derived, 120 run,
every one exit 0; 2 NOT MEASURED (exit 3, prerequisite: other packages'
builds) — `check:skill-examples` (client SDK dist) and
`check:dual-build-cjs-loads` (a full build); CI runs both.
- `node scripts/pm/overlap-check.mjs`: clean against `origin/main`, no
open PR shares a file.
- No full dogfood battery: no `!` in the title and no `(narrowing)` arm.

</details>

<details><summary>Slice B local runs</summary>

On 8e95b36: objectql full suite 644/644 files, 14559/14559 tests;
dogfood `closed-state-lock.test.ts` 69/69 on a rebuilt dist; fold 13/13;
typecheck objectql and dogfood, `check:facade-delegation-only`,
`check:system-context-census` green.

Head 1f399d9.

- `pnpm --filter @objectstack/objectql exec vitest run`: 643/644 files,
14557/14558 tests on the first run; the red file was
`federated-injected-column-readers.test.ts`, which asks every engine use
of `isFederatedObject()` for a disposition: the line probe's
federated-master decline got its row (`exempt`, reads no row) and the
file re-ran green (5/5).
- `pnpm --filter @objectstack/dogfood exec vitest run
test/closed-state-lock.test.ts` against a rebuilt objectql dist: 67/67.
- `pnpm --filter @objectstack/objectql exec vitest run
src/registry-closed-state-fold.test.ts`: 12/12; with the two fold guards
disabled, 7 of 12 fail.
- `typecheck` of objectql (with `check:test-typecheck`) and dogfood:
exit 0.
- `node scripts/pm/dispatch-gates.mjs --ran`: 101 derived, 101 run,
every one recorded `exit 0`. First run: 94 green, 7 red, each re-run
after its fix: five spec dist-reading gates and `check:generated`
answered exit 3 / 1 on a spec dist older than the ledger edit (green
after `pnpm --filter @objectstack/spec build`);
`check:facade-delegation-only` was red because `engine.ts` grew 7 lines
past its ceiling (the new host members now share existing lines, 6856 ≤
6857).
- `pnpm check:system-context-census`: OK (the lock reads `isSystem`
through `boundByClosedStates`, inside the census).
- `node scripts/pm/overlap-check.mjs`: clean against `origin/main`, no
open PR shares a file.
- No full dogfood battery: no `!` in the title and no `(narrowing)` arm.

</details>

Slice A CI on 5d8b45b: 65 checks passed, 11 skipped, none failed.


### Acceptance notes

- **Overlay (card Done-when, for the seat).** Verified and pinned: an
overlay may ADD `closedStates`, and before this branch it already could
(an overlay body is a full object document, and the fold serves it as
the base), so a subscriber's admin can freeze records of a packaged
object in states the package did not close. Before the guard an overlay
could also SHORTEN the package's list (leave the key out or list fewer
values), which unlocked what the package locks; it no longer can.
Whether "may add" stays is a product question: if it changes what a
subscriber may do to a packaged document, it goes back to the seat as a
decision card, as the card says. The pin is `may ADD: an overlay that
declares closed values of its own is served with them`.
- **The fold "refuses" by keeping the field, not by failing
registration.** An extension is a separate package that may load in any
order; failing its whole registration over one field would take its
other objects and fields down with it. The redeclaration of the named
field is dropped, the fold logs it once with the package id, and the
rest applies.
- **D10 gate placement** is proven in the engine by order (the lock runs
inside the write after the middleware chain and before the before-hooks,
pinned by `a refused write runs no before-phase hook`); no
plugin-security-level test was added for "a caller denied the object
gets the same answer on a closed record".
- **Liveness (slice A: `planned`; slice B: `live`)** (confirmed by the
seat, claim revision 7248339226). The claim's file surface names "the
liveness ledger row with its runtime proof (ADR-0054)". On this slice
there is no runtime reader to prove: the engine's judgement is slice B.
A `live` row now would cite a consumer that does not exist. Slice A set
the row `planned`; slice B flips it to `live` with the engine reads and
the dogfood suite as evidence.
- **Narrow readings of D1, decided here (small, listed for the seat):**
`radio` is refused (D1 says `select`); a `picklist`-backed select is
refused because its options are not on the object and this is the one
door every save passes (the `stageField` precedent); an empty map
`closedStates: {}` is accepted and closes nothing (D1 refuses an empty
list, not an empty map). "Stored" needs no check of its own: a computed
value is a `formula` field, never a `select`.
- **Publish door.** The removal and retype refusals ride the object's
whole-document parse, which the save and publish door runs (pinned at
`getMetadataTypeSchema('object')`). A field removed through a tool that
rewrites the object document reaches the same parse.
- **Not in this slice (the card's other Done-when lines):** the overlay
question moved to slice B (claim revision 7248339226) and is answered
above. The `skills/**` follow-up is objectstack-ai#38425; the docs card (item 5) and
an eval that exercises a declaration are owed by the card, named here as
the card asks.
- The Metadata-protocol line was `added` on objectstack-ai#38497, the card's own value
for the key (the seat's claim revision 7248339226). This PR declares
`semantic`: it also carries objectstack-ai#38746, whose changeset
`.changeset/37767-hold.md` declares `Metadata-protocol: semantic` (a
record that declares `closedStates` is now held for its whole approval,
with no change to what an author writes), and AGENTS.md takes the
strongest of several kinds, `narrowed` over `semantic` over `added`.
- Branch is the trunk `claude/o5-data-approvals-trunk` (cut from seat
2's `claude/project-thread-yxheps`), not `claude/issue-37768-*`.

### Verification

Two-minute check: `pnpm --filter @objectstack/spec exec vitest run
src/data/closed-states.test.ts` — expect 22 passed; `pnpm --filter
@objectstack/objectql exec vitest run
src/registry-closed-state-fold.test.ts` — expect 13 passed; after `pnpm
--filter @objectstack/objectql build`, `pnpm --filter
@objectstack/dogfood exec vitest run test/closed-state-lock.test.ts` —
expect 69 passed.

### 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 (CI).
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request (the card's trunk branch).
- [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_01ADHkmPpwJymVUdp5AnRPBq

<!-- signed: repo:objectstack@os-steve · os-steve ·
session_01ADHkmSAjFEZHRpRq3WCj6z -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants