Skip to content

feat(approvals)!: on an object that declares closedStates, the document is held for the whole approval (ADR-0162 D5, #37767 piece 5) - #38746

Merged
os-zhuang merged 7 commits into
claude/o5-data-approvals-trunkfrom
claude/project-thread-nmutvp
Nov 30, 2026
Merged

os-zhuang merged 7 commits into
claude/o5-data-approvals-trunkfrom
claude/project-thread-nmutvp

Conversation

@objectstack-fleet

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

Copy link
Copy Markdown
Contributor

Requested by Steve · project thread

Part of #37767

Clause-②: yes (narrowing)
Metadata-protocol: semantic
Skills-docs: none — skills/ names no closedStates (git grep, 0 hits); its lockRecord rows describe the lock while a request is pending, which this does not change, and content/docs/automation/approvals.mdx teaches the hold

Piece 5 of the approvals topic, the hold (ADR-0162 D5, Execution item 8; design note 7210179412 §5 option a, §6 steps 5 and 6). Base: the trunk claude/o5-data-approvals-trunk at 99a6524361. Leaves #37767 open: the trunk → main PR #38497 and #38601 follow.

维护者速读

  • 改了什么:对声明了 closedStates 的对象,单据从提交审批起一直锁到整个审批结束。
  • 谁受影响:审批进行中(包括步与步之间)改这类单据或其明细行的写入都会收到 409 RECORD_LOCKED,不只是手工编辑,也包括在审批流程之外以用户身份运行的自动化(如 runAs:'user' 的记录变更流程);补救是让其以 runAs:'system' 运行,或把写入挪进审批自身的流程。
  • 不受影响:没声明 closedStates 的对象照旧;审批流程自身照常推进;撤回、退回修改照常。
  • 删除:审批进行中删除单据照常放行,审批随之结束(记为放弃)。
  • 已知口径:审批锁状态读接口在步与步之间答「未锁」,以写入时的 409 为准。
  • 要你做什么:无产品选择待裁;收窄 PR,待席位 L1 与契约复审。

What changes

  • @objectstack/plugin-approvals: on an object that declares closedStates, the approval lock holds the record and its direct master_detail lines for the whole approval, released when the approval is judged over; the approval's own runs pass. A record deleted during the approval ends it (marked abandoned, nothing written). The approvals-family lock read is unchanged.
  • @objectstack/spec, core, objectql, service-automation, runtime: a run's writes carry the root run of their tree (flowRootRunId, server-set, a widening), so the plugin can tell the approval's own runs apart (claim amendments 7273300807, 7273352749).
  • Docs: content/docs/automation/approvals.mdx, "The document is held for the whole approval" (§6 step 6); content/docs/automation/hook-bodies.mdx lists flowRootRunId among the ctx.provenance members (claim amendment 5).
  • D9's lockReason: 'approval' is not built on the trunk: n/a (seat 08:45Z).

Measured

Forced test changes

  • packages/core/src/security/assemble-execution-context.test.ts: its exact list of non-entry fields gains flowRootRunId.
  • packages/services/service-automation/src/runas-user-posture-rung.integration.test.ts: an exact toEqual of a root run's data context gains flowRootRunId, equal to its own flowRunId (claim amendment 4, 7276035950).
  • packages/cli/test/lowered-body-face-enumeration.test.ts: its pin of the provenance members on both faces gains flowRootRunId (claim amendment 4).

Out of scope

#38601, #38497, #38691, #38708.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ADHkmPpwJymVUdp5AnRPBq

…'s writes (ADR-0162 D5, item 8)

Claude-Session: https://claude.ai/code/session_01ADHkmPpwJymVUdp5AnRPBq
Co-authored-by: Claude <noreply@anthropic.com>
…hangesets and the spec's generated outputs (ADR-0162 D5, item 8)

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ADHkmPpwJymVUdp5AnRPBq
…leted record; the spec key is server-set (ADR-0162 D5, item 8)

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

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 6 package(s): @objectstack/core, @objectstack/objectql, @objectstack/plugin-approvals, @objectstack/runtime, @objectstack/service-automation, @objectstack/spec, touching 36 documentable anchor(s). ⚠️ 2 changed file(s) yielded no anchor (packages/spec/authorable-surface/kernel.json, packages/spec/docs/references/kernel/execution-context.md), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

12 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/ai/connect-mcp.mdx (via sys_approval_request (literal, a string literal in approvalInPassage; a string literal in clearApprovalMarks; a string literal in endApprovalOfDeletedRecord; a string literal in endApprovalsOfDeletedRecord; a string literal in passageRequestsFor))
  • content/docs/automation/approvals.mdx (via ApprovalService (symbol, a top-level class), flowRootRunId (symbol, a field of interface RunIdentityContext), flowRootRunId (literal, a string literal in NonEntryExecutionContextField), sys_approval_request (literal, a string literal in approvalInPassage; a string literal in clearApprovalMarks; a string literal in endApprovalOfDeletedRecord; a string literal in endApprovalsOfDeletedRecord; a string literal in passageRequestsFor), unjudged_since (literal, a string literal in approvalInPassage; a string literal in clearApprovalMarks; a string literal in endApprovalOfDeletedRecord))
  • content/docs/automation/flows.mdx (via ApprovalService (symbol, a top-level class), sys_approval_request (literal, a string literal in approvalInPassage; a string literal in clearApprovalMarks; a string literal in endApprovalOfDeletedRecord; a string literal in endApprovalsOfDeletedRecord; a string literal in passageRequestsFor))
  • content/docs/automation/hook-bodies.mdx (via HookContextSchema (symbol, a top-level const), ScriptContext (symbol, a top-level interface))
  • content/docs/automation/workflows.mdx (via sys_approval_request (literal, a string literal in approvalInPassage; a string literal in clearApprovalMarks; a string literal in endApprovalOfDeletedRecord; a string literal in endApprovalsOfDeletedRecord; a string literal in passageRequestsFor))
  • content/docs/concepts/architecture.mdx (via getSchema (literal, a string literal in declaresClosedStates; a string literal in passageRequestsFor))
  • content/docs/data-modeling/field-types.mdx (via sys_approval_request (literal, a string literal in approvalInPassage; a string literal in clearApprovalMarks; a string literal in endApprovalOfDeletedRecord; a string literal in endApprovalsOfDeletedRecord; a string literal in passageRequestsFor))
  • content/docs/frontend/plugins/plugin-detail.mdx (via sys_approval_request (literal, a string literal in approvalInPassage; a string literal in clearApprovalMarks; a string literal in endApprovalOfDeletedRecord; a string literal in endApprovalsOfDeletedRecord; a string literal in passageRequestsFor))
  • content/docs/permissions/system-context.mdx (via ExecutionContextSchema (symbol, a top-level const), bindApprovalLockHook (symbol, a top-level function), bindDetailRowLockHook (symbol, a top-level function), platformSystemApi (symbol, a method of class ScopedContextFacet), resolveRunDataContext (symbol, a top-level function))
  • content/docs/plugins/packages.mdx (via sys_approval_request (literal, a string literal in approvalInPassage; a string literal in clearApprovalMarks; a string literal in endApprovalOfDeletedRecord; a string literal in endApprovalsOfDeletedRecord; a string literal in passageRequestsFor))
  • content/docs/ui/pages.mdx (via sys_approval_request (literal, a string literal in approvalInPassage; a string literal in clearApprovalMarks; a string literal in endApprovalOfDeletedRecord; a string literal in endApprovalsOfDeletedRecord; a string literal in passageRequestsFor))
  • content/docs/ui/translations.mdx (via sys_approval_request (literal, a string literal in approvalInPassage; a string literal in clearApprovalMarks; a string literal in endApprovalOfDeletedRecord; a string literal in endApprovalsOfDeletedRecord; a string literal in passageRequestsFor))

⛔ 5 release-owned page(s) also name something this change touched. These are read-only:

  • content/docs/releases/v16.mdx (via sys_approval_request (literal, a string literal in approvalInPassage; a string literal in clearApprovalMarks; a string literal in endApprovalOfDeletedRecord; a string literal in endApprovalsOfDeletedRecord; a string literal in passageRequestsFor))
  • content/docs/releases/v17/17-0.mdx (via HookContextSchema (symbol, a top-level const))
  • content/docs/releases/v17/17-6.mdx (via ApprovalService (symbol, a top-level class), sys_approval_request (literal, a string literal in approvalInPassage; a string literal in clearApprovalMarks; a string literal in endApprovalOfDeletedRecord; a string literal in endApprovalsOfDeletedRecord; a string literal in passageRequestsFor))
  • content/docs/releases/v18/18-1.mdx (via ApprovalService (symbol, a top-level class))
  • content/docs/releases/v18/18-4.mdx (via sys_approval_request (literal, a string literal in approvalInPassage; a string literal in clearApprovalMarks; a string literal in endApprovalOfDeletedRecord; a string literal in endApprovalsOfDeletedRecord; a string literal in passageRequestsFor))

content/docs/releases/ is RELEASE-OWNED (AGENTS.md "Documentation Guardrails"): release
notes are written centrally at release time, and a code PR that edits them is the exact PR
that guardrail exists to stop. They are still audited — read-only. If one of them is actually
wrong, file an issue or open a dedicated docs-only PR; do not edit it here.

What this run could not see
  • 2 changed file(s) yielded no anchor (packages/spec/authorable-surface/kernel.json, packages/spec/docs/references/kernel/execution-context.md) — pages documenting those are invisible to this run
  • 1 anchor(s) matched too much of the corpus to be a work list: created_at (literal, 49 pages)
  • 2 name(s) were too generic to anchor anything (single lowercase words)
  • 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 — 191 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 45b2fac043c4977de0e0c4fdf9cef0a77d06f57d → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 9765b975e181e98acba7fd81e4c35997573603c4 — the merge of head 1d89edbc91b7ad0fe4a02e347b16808acf5d6679 into base 45b2fac043c4977de0e0c4fdf9cef0a77d06f57d, 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 9765b975e181e98acba7fd81e4c35997573603c4 && git checkout 9765b975e181e98acba7fd81e4c35997573603c4
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 45b2fac043c4977de0e0c4fdf9cef0a77d06f57d 1d89edbc91b7ad0fe4a02e347b16808acf5d6679 && git checkout -B drift-repro 45b2fac043c4977de0e0c4fdf9cef0a77d06f57d && git merge --no-ff 1d89edbc91b7ad0fe4a02e347b16808acf5d6679

node scripts/docs-audit/affected-docs.mjs --json 45b2fac043c4977de0e0c4fdf9cef0a77d06f57d

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

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 45b2fac043c4977de0e0c4fdf9cef0a77d06f57d → pass the list as
args.docs, on the commit named under Which tree this was computed on.

… member; typed find options (ADR-0162 D5)

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ADHkmPpwJymVUdp5AnRPBq
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmT9HTWLMN33WUVxVWB
L1-b, the seat's L1 thread · 2026-11-30T11:36Z · first review

席位核对

ACCEPT @ 56e735f (card #37767, piece 5; base is the claude/o5-data-approvals-trunk trunk, not main)

  • The hold rule. lifecycle-hooks.ts holds the document during an approval through a passage. The pieces are passageRequestsFor, writesAsApprovalRun, approvalInPassage, passageHoldsAgainst and withPassage. Both the record lock hook and the detail-row lock hook read the same marked requests (unjudged_since). A write passes when its root run is the approval run's own root. stampRootRun (service-automation root-run.ts) makes that root reach the run's children. Any other writer is refused.

  • Deleting a held record ends its approval. This is done by endApprovalOfDeletedRecord and endApprovalsOfDeletedRecord in approval-service.ts.

  • flowRootRunId plumbing is consistent across every layer I read:

    • the spec ExecutionContext;
    • HookContext provenance and buildProvenance;
    • platformSystemApi, which strips it, so a script cannot forge it;
    • the body runner and the script runner;
    • resolveRunDataContext (via readRootRun);
    • the core non-entry fields.
  • Declarations match the face. There are three changesets:

    • spec: patch (widening, none);
    • core, objectql, service-automation and runtime: patch (widening);
    • plugin-approvals: minor (narrowing, semantic, BREAKING, ADR-0087 not-required).

    The ! in the title matches the narrowing. @objectstack/cli is touched by a test file only, so it needs no changeset entry.

  • My runs at this head:

    • the integration file approval-hold-37767 passed 15/15;
    • Ablation A: I removed if (root && writer.root === root) return true; in the passage check. One test went red, the middle-run case, and the file was restored. That rule is pinned.
    • Ablation B: I removed if (rows.some(snapshotAbandoned)) return false; in approvalInPassage. All tests stayed green, and the file was restored. Nit: the abandoned-snapshot check is an unpinned defence layer. This is NOT MEASURED by any test. A follow-up pin would help, but it does not block.
  • Note for L2, at rule level and not a must-fix. Suppose an approval run's own write triggers a record-change flow that has runAs: 'user'. stampRootRun gives that flow a new root, so it is outside the approval tree, and its write to the held record is refused 409 during the passage. The docs tell authors to use runAs: 'system' for record-change flows that react to approval outcomes, and with system the write passes. L2 should judge whether the plugin-approvals changeset should name this author-visible edge too.

Checks at this head (read before writing): 25 success, 8 skipped, 0 failure, 33 in progress.
Dogfood: owed, because the PR is BREAKING. The lane runs only on PRs into main, and this PR's base is the trunk. The seat records that the battery is owed on trunk→main #38497, and that the local full run at dc12b07 stands for now. Landing #38497 waits for a Dogfood battery (opt-in) success on its exact head.
L2: owed at CONTRACT_REVIEW_TIER. The seat is running it.

…hen flowRootRunId is absent (ADR-0162 D5)

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ADHkmPpwJymVUdp5AnRPBq
@objectstack-fleet

objectstack-fleet Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSAjFEZHRpRq3WCj6z

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 1d89edbc91b7ad0fe4a02e347b16808acf5d6679
Local-runs: none
Scope: packages/spec/src/data/hook.zod.ts, packages/spec/src/kernel/execution-context.zod.ts + packages/plugins/plugin-approvals/src/lifecycle-hooks.ts, packages/plugins/plugin-approvals/src/approval-service.ts, packages/core/src/security/assemble-execution-context.ts, packages/objectql/src/engine-execution-plumbing.ts, packages/objectql/src/engine-scoped-context.ts, packages/services/service-automation/src/runtime-identity.ts, packages/runtime/src/sandbox/body-runner.ts, packages/runtime/src/sandbox/script-runner.ts, content/docs/automation/approvals.mdx, content/docs/automation/hook-bodies.mdx
Security-touching: yes
Rule-change-verified: none

PR #38746 into claude/o5-data-approvals-trunk (merge base 99a6524361; the trunk has since moved to 45b2fac043, an ADR-0162 text change of 4 lines that touches no file of this diff). Card #37767: body and all 50 comments read, with design note 7210179412 (§5 option a, §6 steps 5 and 6), claim amendments 7273300807, 7273352749, 7276035950, 7276819216, and report 7275825509. ADR-0162 D5 and Execution item 8 read at this head. PR comment 7277290516 (L1-b) read. The rest of the diff (the new integration test, the three forced test edits, generated references, the census file, the changesets' prose) is the lane seat's ACCEPT at TIER_DEFAULT.

Delta, 56e735f99a500a7b6ba0f670a55927178b79589a to this head: three prose files and nothing else (git diff --stat: .changeset/37767-hold.md, content/docs/automation/approvals.mdx, content/docs/automation/hook-bodies.mdx; 7 insertions, 3 deletions). No code, schema, test or generated file moved, so every judgment below was made at 56e735f99a and stands on this head. The new sentences agree with the code: a record-change flow that a decision sets off is stamped as the root of its own tree (root-run.ts#stampRootRun) and its runAs: 'user' write is refused by passageHoldsAgainst; under runAs: 'system' it passes as a system session; the member is absent where readRootRun answers nothing. The PR body's 谁受影响 line now says the same.

Check-runs. On 56e735f99a, complete: 69 runs, 61 success, 8 skipped, none failed; the code verdicts are carried. On this head, at the time of writing: 38 runs, 5 success, 9 skipped, 24 still in progress (Check Changeset, the docs build and the docs guards among them), none failed. The seat read this head complete before adopting: 73 runs, 63 success, 10 skipped, none failed.

① Derived judgments

  • flowRootRunId is a widening, and it is server-set. Right. One optional string on ExecutionContextSchema and on HookContextSchema.provenance. assembleExecutionContext names it among the fields an entry point may not set, and the closed-field test gains it. The only writer is resolveRunDataContext, from the root run the engine stamps (root-run.ts#stampRootRun): a run with no parent is stamped as its own root whatever the incoming context carried, and the two doors that start a flow by name build the run context from a closed key set (runtime/src/domains/automation.ts#buildAutomationContext), so a request body cannot name a parent or a root. buildProvenance copies it only beside flowRunId; platformSystemApi strips both; the sandbox hands a body a projected copy, and the plugin reads the engine's own ctx.provenance, never a body's.
  • packages/spec/authorable-surface/kernel.json gains the key. Right as a generated ratchet row, not as a grant: the shard lists every key of kernel/ExecutionContext, flowRunId and isSystem among them. Metadata-protocol: none on the two widening changesets is right: nothing an author writes changes.
  • A root run carries its own id; every run of a tree carries the root. Right, read in stampRootRun (a child keeps the inherited root; a child whose parent could not be placed is stamped null, and then the key is absent). Pinned by the runas-user-posture-rung edit and by the hold test's middle-run case.
  • The hold is a narrowing on @objectstack/plugin-approvals. Right. On an object that declares closedStates, a caller's update of the record, and an insert, update, delete or move of a direct master_detail line, is refused 409 RECORD_LOCKED through each passage. Read in gatingRequests, passageHoldsAgainst, approvalInPassage and both hooks. It does not ask lockRecord, as D5 rules.
  • Who passes. Right against D5, each read in the code: a system session; a record write whose every key is the decided step's mirror field (D5 names this pass for any caller, as the pending lock has it); a write whose flowRootRunId equals the request's root_run_id, or whose flowRunId is the request's flow_run_id, root_run_id or record_run_id; the revise window (the hold stands only while a marked request is the approval's latest on the record); the record's own delete. A run of another tree is refused, also a second approval of the same record: its root is not the marked request's, and the first approval's own rows are read to decide whether its passage stands. A flow that a write of the approval sets off starts a tree of its own and is refused, which is D5's "for a write that carries a run of the approval, and for no other".
  • A run outside the approval's tree, running as the user, is refused (L1-b's note, PR comment 7277290516). Right, and meant. A record-change flow that a write of the approval sets off is stamped as the root of its own tree, so under runAs: 'user' its write to the held record answers 409 RECORD_LOCKED, also where the user it runs as may edit the record; under runAs: 'system' it passes as a system context. D5: "The pass is for a write that carries a run of the approval, and for no other", and "An indirect write that carries none is refused like any caller's, also where a node of the approval set it off"; D5 counts "a flow that runs as the user" among callers; Consequences: "an indirect write in a passage that carries no run of the approval is refused"; the ruled words are 「从提交到审批结束别人都改不了」. Design note 7210179412 §5 and §6 step 5 put the hold on the mark and name no pass for another tree. The pending lock already refuses such a run while a request is pending (it passes the opening run alone), so the class is not new: the passage adds time to it. It is now declared in the guide's hold section, in the changeset's BREAKING paragraph and in the PR body, each with the remedy.
  • The whole approval. Right. Both decision writers stamp the mark in the update that records the decision (approval-service.ts, the decide path and the revision-limit auto-reject); the mark stands until the approval is judged or its next request opens. After the last decision it stands until the door or the reconciler judges the approval over.
  • Delete during the approval. Right against item 8. cancelForDeletedRecord now calls endApprovalsOfDeletedRecord after its read of pending requests and before its early return, so a delete in a passage ends the approval with or without a pending request. endApprovalOfDeletedRecord stamps __abandoned on the newest request unless one already carries it, clears the marks, writes nothing to the record. The reconciler's deleted-record branch calls the same function. The cascade leg of the record's own delete yields by the detail hook's existing rule; a cascade from another master is refused for a caller and lands for the approval's run.
  • getRecordLock unchanged. Right, and consistent with D5 and D9: "The approvals-family read stays exactly as published", and item 8, "The approvals-family read is not touched". Declared in the changeset and the guide, pinned by a test; no finding.
  • Objects without closedStates unchanged. Right. passageRequestsFor returns before any read; withPassage hands back the pending list itself; the pending branch of both hooks is the earlier code under an else. One cost is new on every object: one keyed read of marks in the after-delete linkage.
  • The three forced test edits add the new key and nothing else: one line in assemble-execution-context.test.ts, one in runas-user-posture-rung.integration.test.ts, two member lists in lowered-body-face-enumeration.test.ts.
  • A degradation, stated at rule level. Where the plugin cannot read its marks, or the registry cannot answer for the object, the hold does not hold, as the pending lock does not when its bookkeeping cannot be read. Where the marks are read and the approval's rows cannot be, it holds. Both are written in the functions' own docblocks and follow the pending lock's declared rule (ADR-0162 D4, "The pending line lock is narrower"). Not a finding.

② Semver level

  • .changeset/37767-hold.md: @objectstack/plugin-approvals minor, Clause-②: yes (narrowing), Metadata-protocol: semantic, BREAKING banner with FROM, TO and the one-line fix, ADR-0087 marker not-required (no-migration-prescription). Matches the diff: the meaning of declaring closedStates changes for an approval, no key or value is refused. semantic takes at least minor: right.
  • .changeset/37767-hold-root-run-spec.md: @objectstack/spec patch, Clause-②: yes (widening), Metadata-protocol: none. Right: a server-set key, none takes patch.
  • .changeset/37767-hold-root-run.md: core, objectql, service-automation, runtime patch, widening, none. Right: each of the four is moved by the diff, and none is left out (@objectstack/cli changes a test only).
  • The PR title carries ! and the body carries Clause-②: yes (narrowing) and Metadata-protocol: semantic, the stronger of the three changesets. Check Changeset was green on 56e735f99a and is still running on this head, whose changeset edit is one paragraph of prose.

Clause-②: yes (narrowing)

③ Boundary flags

  • Dev report 7275825509 carries three deviations and no open_questions. (a) The forced edit of runas-user-posture-rung.integration.test.ts: answered by claim amendment 4 (7276035950), and it only adds the key. (b) The spec changeset at Metadata-protocol: none, patch, with the PR body at semantic: right, see ②. (c) Generated outputs touched: each is the generator's row for the new key or the census count (50 to 51 write sites, the abandoned stamp).
  • Amendments 4 and 5 cover the two files added after the report (lowered-body-face-enumeration.test.ts, hook-bodies.mdx).
  • D9's lockReason: 'approval' in a passage: the one lock read is not on the trunk (no lockReason in any src at this head), so the PR cannot build it. See N4.
  • SQL push-down: see N3.

④ Design judgment

packages/spec/src/kernel/execution-context.zod.ts and packages/spec/src/data/hook.zod.ts, against ADR-0162 D5 ("The approval's own runs pass, and the hold knows them by their root run"), item 8 ("how the lock reads a writer's root run") and their first consumer, lifecycle-hooks.ts#writerRunsOf. The key holds: the jsdoc's four claims (the root of the tree at any depth; equal to flowRunId on a run with no parent; set by the engine and never by a client; absent where flowRunId is and on a run the engine could not place) each agree with stampRootRun, resolveRunDataContext, assembleExecutionContext and buildProvenance. The consumer reads it only beside a run id, so a root with no run names nothing. The name is the seat's ruling and is not re-judged.

Implementing files, sentence by sentence. runtime-identity.ts: both arms copy the root beside the run id, and only there. engine-execution-plumbing.ts, engine-scoped-context.ts, body-runner.ts, script-runner.ts, assemble-execution-context.ts: each does what its changeset sentence says. lifecycle-hooks.ts: the block comment's five passes are the five the code makes; "A passage does not ask the node's lockRecord" holds; the read side is untouched. approval-service.ts: the two docblocks agree with the code. approvals.mdx, "The document is held for the whole approval": each bullet agrees with the code, the lockRecord: false sentence and the locked: false answer included.

Tried and not broken: a run started by another flow on the record; a subflow or map run at depth (passes by root); a run whose root is another approval of the same record; a body or request that names a root; a root with no run; a system context; a mirror-only write (passes, as D5 says); the send-back window with a mark left behind; a decision and its mark in two writes (they are one); a request row that opens in the same instant as the marked one.

No must-fix, no should-fix.

Nits:

  • N1 (nit) — hook.zod.ts describe and execution-context.zod.ts jsdoc say the plugin holds "between two steps". The hold also runs from the last decision until the approval is over (D5; approvalInPassage). The wording is narrower than the rule and misleads nobody about the key. A fix moves the head and the generated references: accepted deviation, or the next touch of the file.
  • N2: closed
  • N3 (nit) — SQL first. approvalInPassage makes one keyed read per marked candidate and picks the approval's latest request in the app, from up to 500 unordered rows; the detail hook's unresolved path judges every marked request of the master object, up to PENDING_LOCK_LIMIT + 1, and does not stop at the first that holds. No reason is given in the code. One read over the candidates' root runs, ordered by created_at, would do. Bounded, and no effect on the verdict at any size an approval reaches: a follow-up card.
  • N4 (nit) — Item 8 says "The one lock read of item 2 answers approval in a passage". That read is not on the trunk, and the PR body answers n/a without naming who carries the sentence. It belongs on the build card of the one read, before the trunk goes to main: a line on that card.
  • N5 (nit) — lifecycle-hooks.ts#pendingRequestsForObject (outside the diff) calls its fail-open "deliberately the ONE fail-open left". With passageRequestsFor and declaresClosedStates there are three reads that answer "not held" when they cannot read. The new docblocks say so; the old sentence is now inexact. Next touch.
  • N6: closed
  • N7 (nit) — No test pins the refusal of a run of another tree that runs as the user (the suite pins a caller, a hook as another caller, and a run without its root). The pin can ride the follow-up that pins the abandoned-snapshot read L1-b found unpinned.

Implemented-by: claude/project-thread-nmutvp
Reviewed-by: session_01ADHkmSAjFEZHRpRq3WCj6z

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmT9HTWLMN33WUVxVWB
L1-b, the seat's L1 thread · 2026-11-30T12:35Z · delta review

席位核对

ACCEPT @ 1d89edb (card #37767, piece 5). This is a delta from 56e735f and my ACCEPT 7277290516: one commit, 1d89edbc, +7/−3, text only, plus the body.

  • The note I left for L2 is now in the face. A record-change flow with runAs: 'user' that a decision sets off starts its own run tree, so its write to the held document is refused 409. Three places now say so:

    • the BREAKING paragraph of .changeset/37767-hold.md, with the fix runAs: 'system' beside the existing one-line fix;
    • approvals.mdx;
    • the body's 谁受影响 line.

    Each sentence matches what I read at 56e735f: stampRootRun gives a run with no parent its own root, and the passage check passes only the approval's root.

  • hook-bodies.mdx now says "Absent on a run the engine could not place in a tree" for ctx.provenance.flowRootRunId. That is true to root-run.ts: a $rootRun stamped null means the engine could not read the tree whole, and the provenance then carries no root id.

  • No executable line moves, because git diff 56e735f9..1d89edbc touches only the three text files. So my earlier runs carry over:

    • approval-hold-37767 passed 15/15;
    • removing the root-run check turns 1 case red;
    • the abandoned-snapshot check is still unpinned (the nit, NOT MEASURED).

Checks at this head (read before writing): 63 success, 10 skipped, 0 failure. mergeable_state is clean.
L2: PASS at this head (7278629081). The dogfood battery is still owed on trunk→main #38497, as recorded before.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSAjFEZHRpRq3WCj6z

维护者速读

  • 用户能看到什么变化: 对象声明了 closedStates 时,单据从提交审批到整个审批结束都锁定,步与步之间也锁。此期间改单据或其明细行,都会收到 409 RECORD_LOCKED。
    • 这包括手工编辑,也包括在审批流程之外、以用户身份运行的自动化(runAs:'user' 的记录变更流程)。
    • 补救办法:让这类流程以 runAs:'system' 运行,或者把写入挪进审批自身的流程。
    • 审批进行中删除单据照常放行,审批随之结束,记为放弃。
  • 为什么做: 审批专题第 5 块(ADR-0162 D5,执行项 8)。Warren 08:23Z 交给 3 号座位。
  • 出错会怎样:
  • 要你做什么: 这是基于主干分支的收窄 PR(标题带 !),请批准或直接合并。

Seat opinion: land as is.

席位核对

ACCEPT at head 1d89edbc91b7ad0fe4a02e347b16808acf5d6679.

  1. Shape. plugin-approvals: the hold, in lifecycle-hooks.ts and approval-service.ts. The root-run key flowRootRunId is in spec, core, objectql, service-automation and runtime. Docs: approvals.mdx and hook-bodies.mdx. Three changesets.
  2. Premise. The trunk carries pieces 1 to 4. The key name is the seat's ruling (claim amendments 7273300807, 7273352749).
  3. Gates.
  4. Accepted deviations.
    • L2 nits N1, N3, N4, N5 and N7.
    • Three forced test edits that only add the key, named in claim amendments 4 and 5.
  5. Out of scope and where it went. docs(adr): ADR-0162 revised on three rulings of 2026-11-29: the reconciler places a run with no row, and a decision whose run never went on, by the step last decided #38601 is merged. feat(objectql): a record in a closed state, and its lines, are closed to change (closedStates, ADR-0162) — trunk #38497 is trunk → main, with the dogfood battery owed there. 37767 后续:审批读取的 fan-out 判断与引擎注释收尾(N14–N17、N23、stopOf) #38691 and 37767 后续:引擎标出正在推进的运行,让审批清理不把恢复中的运行当成已停 #38708 are untouched.
  6. Landing.
    • L1 ACCEPT: 7277290516, then the delta 7278652327 on this head.
    • L2 PASS: 7278629081 on this head.
    • It lands into the trunk after os-zhuang approves or merges.

ACCEPT → comment 7278652327 · Contract review → comment 7278629081

@objectstack-fleet objectstack-fleet Bot added the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 30, 2026
@os-zhuang
os-zhuang marked this pull request as ready for review November 30, 2026 12:38
@os-zhuang
os-zhuang merged commit 6e17a6a into claude/o5-data-approvals-trunk Nov 30, 2026
77 checks passed
@os-zhuang
os-zhuang deleted the claude/project-thread-nmutvp branch November 30, 2026 12:38
@objectstack-fleet objectstack-fleet Bot removed the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 30, 2026
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 protocol:data size/l 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.

3 participants