Skip to content

fix(runtime,cli,lint,spec)!: a sandboxed body's ctx.api.object(X).updateById(id, patch) writes the row - #38643

Merged
os-zhuang merged 10 commits into
mainfrom
claude/issue-38630-sandbox-update-by-id
Nov 30, 2026
Merged

os-zhuang merged 10 commits into
mainfrom
claude/issue-38630-sandbox-update-by-id

Conversation

@objectstack-fleet

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

Copy link
Copy Markdown
Contributor

Requested by Steve · project thread
Fixes #38630
Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: follow-up #38655

维护者速读

  • 用户能看到什么变化:应用作者在脚本动作和触发器里按文档写的「按编号更新一条记录」现在真的能保存改动,之前这样写第一次运行就报错、数据不变;传错编号(比如传了一个查询条件)会得到一句清楚的拒绝,什么也不写。
  • 为什么做:文档和对外类型说明都承诺有这个写法,只有脚本运行的沙箱缺了它;属于脚本动作写入能力补齐的工作。
  • 出错会怎样:只影响调用这个写法的脚本,原来的另一种更新写法不变;保存检查同时变严:没有声明写权限就用这个写法的脚本动作,以及以系统身份用它改人员授权记录的脚本,保存时会被拒绝(这两种脚本以前也从来运行不成功);有问题可直接撤回。
  • 要你做什么:这是收紧保存检查的改动,需要一次契约级审核后才能落地。

What changes

  • Runtime (the fix). The QuickJS sandbox's ctx.api.object(X) now installs updateById among its WRITE leaves (installCtx), behind the same api.write capability gate. It forwards by name to the host's scoped repository, as every leaf does; no per-method argument mapping was needed.
  • Runtime (the id guard). updateById's id argument is judged at the crossing, before the host is called (ID_ARGUMENT_INDEX, refuseNonScalarIdArgument). Anything but a non-empty string or a non-zero number is refused as VALIDATION_ERROR / 400 with a sentence naming the call, the shape it was given, and the bulk form (update(data, { where, multi: true })). 0 and '' are refused because HookObjectApi.updateById already declares them a refusal (they identify no row).
  • CLI. objectstack build's api.write inference names updateById (the api.write regex and OBJECT_WRITE_LEAVES), so a lowered handler whose only write is updateById is granted the call. The word boundary matters: update\b does not match inside updateById.
  • Lint. SANDBOX_API_WRITE_METHODS gains updateById; its existing pin to the runner's WRITE list holds with both sides moved. action-body-write-capability-undeclared therefore finds an ungranted updateById call.
  • Spec (save-time identity refusal). BODY_WRITE_METHODS in packages/spec/src/identity/identity-assignment-body-writes.ts, the list that names itself the runner's api.write set, gains updateById. So HookSchema and ActionSchema refuse an elevated body (a runAs: 'system' hook, a script action) that writes sys_user_position, sys_user_permission_set, sys_invitation or sys_member through updateById, as they refuse the other write calls. Before this change the call threw TypeError: not a function in the sandbox; now that it is installed, the run-time refusal (plugin-security's data middleware) refuses the write as well.
  • BREAKING, at two authoring doors (!, Clause-②: no (narrowing), Metadata-protocol: narrowed). At save and in os validate: an action body calling updateById without api.write is refused as action-body-write-capability-undeclared (FROM saved and threw at every run → TO declare api.write), and the elevated identity-assignment write above is refused at body.source. Neither body ever worked. ADR-0087: registered — the new v19 entry hook-action-body-system-identity-assignment-update-by-id-refused for the identity-assignment door, beside the existing publish-refuses-seeds-and-actions-that-save-and-do-not-work that covers the ungranted api.write write.
  • Text that this change made false, fixed in the same files. Two author-facing sentences listed the sandbox's write leaves and would have gone on saying updateById is not one: the os explain action-body-write-capability-undeclared paragraph (rule-explanations.ts, it said "the six ctx.api write leaves") and the build's .create() refusal (extract-hook-body.ts). Both now list updateById; "six" is dropped.
  • Write-leaf lists brought to the installed set: the comments in validate-hook-body-writes.ts (API_WRITE_METHODS note), validate-action-body-writes.ts (two comments that said a body has no updateById; the hint itself is unchanged) and authoring-rules.ts, and the two docs lists (content/docs/automation/hook-bodies.mdx, the .create() paragraph; content/docs/deployment/validating-metadata.mdx, the rule's row).
  • The build's capability-inference table names every write leaf it infers from. In content/docs/automation/hook-bodies.mdx, the api.write row of the Capability inference table now reads insert / update / updateById / updateMany / upsert / delete / deleteMany / patch / remove / create, the alternation extract-hook-body.ts matches. updateById is new here. updateMany and deleteMany were already inferred, and the row had omitted them before this PR; they are fixed in the same row.
  • A v19 semantic entry records the identity-assignment narrowing. packages/spec/src/migrations/entries/semantic/19.hook-action-body-system-identity-assignment-update-by-id-refused.ts records that a save now refuses an elevated body (a runAs: 'system' hook or a script action) that writes sys_user_position, sys_user_permission_set, sys_invitation or sys_member through updateById, a call that threw TypeError: not a function before this release. The v18 entry hook-action-body-system-identity-assignment-write-refused is unchanged: in v18 updateById was never refused, it threw. The protocol upgrade guide is projected from the registries by gen:upgrade-guide into the gitignored content/docs/protocol-upgrade/; nothing generated is committed.
  • Re-read, unchanged. rule-explanations.ts ~1365 / ~1376 / ~1838 and validate-hook-body-writes.ts ~246 / ~256 name updateById as a write channel; with the leaf installed each is true, so none is edited. The hook-bodies.mdx snippet is now true, and the action-record-write-discarded hint (update({ id: ctx.recordId, … })) stays.
Measured before the change, and what the host does with a non-scalar id

Probe on real ObjectQL + better-sqlite3 SqlDriver + QuickJSScriptRunner, at origin/main f3028c5 (throwaway file, not committed):

PROBE ACTION updateById :: {"err":{"name":"SandboxError","message":"action 'close' threw: TypeError: not a function"}} :: A=open,B=open
PROBE ACTION typeof :: {"ok":"undefined"}
PROBE ACTION update({id}) :: {"ok":"ok"} :: A=won2,B=open
PROBE HOOK updateById :: {"name":"SandboxError","message":"hook 'win_deal' threw: TypeError: not a function"} :: A=open,B=open

The host repository called in-process (ScopedContext.object('ubi_deal').updateById(id, …)), two rows seeded: every non-scalar or falsy id was refused by the engine and no row moved. The messages are about filters or options.multi, and several carry no code:

id host answer
{ $ne: null }, { $in: [id] }, null, '', 0, NaN, true Error: Update requires an ID or options.multi=true (no code)
{} INVALID_FILTER / 400 (empty object at where.id)
[id] INVALID_FILTER / 400 (array comparand at where.id)
undefined INVALID_FILTER / 400 (undefined comparand at where.id)

So no shape reaches a wider write than one row today; the guard turns each into one coded refusal before the engine is called. After the change, same probe: updateById writes A=won, a null id answers VALIDATION_ERROR / 400 with ctx.api.object('ubi_deal').updateById(id, data) needs the id of one record (a non-empty string or a non-zero number) and was given null, so nothing was written.

Tests

  • packages/runtime/src/sandbox/body-update-by-id.integration.test.ts (new, real runner): an action body and a hook body calling updateById(id, patch) write that row and only that row (before/after reads of both rows); a control on update({ id, … }) on both faces; the api.write gate (INSUFFICIENT_PRIVILEGES / 403, nothing written); one case per refused id shape (operator object, array, null, undefined, '', 0), each asserting code + status, no update reaching the engine (an engine middleware counts them) and no row moved; and a hook body that catches the coded refusal.
  • packages/cli/test/extract-hook-body.test.ts: updateById alone infers exactly ['api.write'], directly and on a bound handle; the .create() refusal's leaf list.
  • packages/spec/src/identity/identity-assignment-body-writes.test.ts: updateById joins the per-method battery (every quote form, all four objects); a runAs: 'system' hook and a script action writing sys_user_position through updateById are refused at body.source with their sentence; CONTROL: the same call on crm_account parses on both faces.
  • packages/lint/src/validate-action-body-capabilities.test.ts: an ungranted updateById is refused and named; granted, it passes. The runner-list pin is unchanged and green with both lists moved.
Readings
  • New runtime file: Test Files 1 passed (1), Tests 11 passed (11).
  • Ablation 1, the leaf removed (scripts/ablation-replace.mjs, anchor x1 → x0, blob b52e071075c9 → a62699b7b677): Tests 10 failed | 1 passed (11), the one green being the update({ id }) control; restored, blob == HEAD, git diff HEAD empty.
  • Ablation 2, the guard call removed (blob b52e071075c9 → a36d5c25cb9d): Tests 7 failed | 4 passed (11), the seven guard cases red (expected undefined to be 'VALIDATION_ERROR', expected 'INVALID_FILTER' to be 'VALIDATION_ERROR'), the write pins, control and gate green; restored, git diff HEAD empty.
  • @objectstack/cli test/extract-hook-body.test.ts: Tests 67 passed (67).
  • @objectstack/lint whole suite: Test Files 246 passed (246), Tests 9960 passed (9960).
  • pnpm --filter @objectstack/runtime --filter @objectstack/cli --filter @objectstack/lint typecheck: VERDICT command-exit 0.
  • @objectstack/spec whole suite at f7b947f: Test Files 1007 passed (1007), Tests 30504 passed | 1 todo (30505).
  • Ablation 3, updateById removed from the spec's BODY_WRITE_METHODS (blob 408d74efe3cc → b126506e753a): Tests 6 failed | 25 passed (31) in identity-assignment-body-writes.test.ts, the four per-object method batteries and the two updateById refusals red, the crm_account control green; restored, blob == HEAD, git diff HEAD empty.
  • @objectstack/lint whole suite at f7b947f: Test Files 246 passed (246), Tests 9960 passed (9960).
  • New v19 entry at 4c186ea: check-adr-0087-registration --base origin/main exits 0 (registered hook-action-body-system-identity-assignment-update-by-id-refused, publish-refuses-seeds-and-actions-that-save-and-do-not-work; 1 migration entry added, each at or above PROTOCOL_MAJOR 19); check:spec-changes and check:upgrade-guide generate in memory (protocol 19.0.0); gen:upgrade-guide writes the docs pages and 19.md carries the entry; check:generated after a spec build: All 14 generated artifacts are up to date; the spec migrations, registry and upgrade-guide tests: Test Files 8 passed (8), Tests 246 passed (246); cli test/migrate-meta-engine-guidance.test.ts: Tests 3 passed (3); check-changeset-no-major --event with this PR's body: exit 0; overlap-check --branch=HEAD: VERDICT clean.
  • @objectstack/spec pnpm test (local project) at 8e38653: Test Files 913 passed (913), Tests 28896 passed | 1 todo (28897); the upgrade-guide span and docs tests with the migrations tests: Test Files 7 passed (7), Tests 239 passed (239). dispatch-gates --ran at 8e38653: 124 derived, 124 run, 0 UNRUN; every family exit 0 once the cli and formula closures were built.
  • Inference-row edit at 60c75f9: the 45 families dispatch-gates --commands derives for content/docs/automation/hook-bodies.mdx all exit 0, among them check:doc-anchors (1179 fragment links resolve), check:docs-spec-enumerations, check:doc-security-posture and check:doc-formula-expressions; overlap-check --branch=HEAD: VERDICT clean.
  • Changeset correction at 0382b34: the BREAKING table's second FROM cell and the sentence after the table now say both bodies threw TypeError: not a function before this change.
  • Dogfood battery (pnpm --filter @objectstack/dogfood test, no shard, at f7b947f): VERDICT command-exit 0, Test Files 495 passed | 3 skipped (498), Tests 4187 passed | 68 skipped (4255).
  • dispatch-gates --ran: 121 derived, 121 run, 0 UNRUN. Four exited 3 for a prerequisite, not a finding: check-plugin-teardown-shape --self-test (shallow clone), check:skill-examples (client-react dist not built), check:dual-build-cjs-loads; check:type-check-debt re-run under the lock afterwards: OK — 0 ledger entr(ies) re-measured … none above its recorded number. CI's Type Check · debt ledger is green.

Acceptance notes

  • First-party bodies calling updateById: none, so nothing in this repository is newly refused.

Verification

Read first, by risk:

  1. packages/runtime/src/sandbox/quickjs-runner.ts: refuseNonScalarIdArgument and its call at the top of installApiMethod's leaf.
  2. packages/runtime/src/sandbox/body-update-by-id.integration.test.ts: the refused-shape table.
  3. packages/cli/src/utils/extract-hook-body.ts: the api.write alternation.

Two-minute check: pnpm --filter @objectstack/runtime exec vitest run --project local src/sandbox/body-update-by-id.integration.test.ts prints Tests 11 passed (11).
For the save-time narrowing: pnpm --filter @objectstack/spec exec vitest run src/identity/identity-assignment-body-writes.test.ts prints Tests 31 passed (31).


Generated by Claude Code

…d(id, patch) writes the row

The QuickJS runner installs updateById behind api.write, refusing an id that
is not a non-empty string or non-zero number at the crossing. The build
infers api.write for it and lint's sandbox write list names it.

Claude-Session: https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B
Co-authored-by: Claude <noreply@anthropic.com>
@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

This PR changes 4 package(s): @objectstack/cli, @objectstack/lint, @objectstack/runtime, @objectstack/spec, touching 21 documentable anchor(s). ⚠️ 2 changed file(s) yielded no anchor (packages/lint/src/validate-hook-body-writes.ts, packages/spec/src/data/hook.zod.ts), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

25 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json f5da514b07bcbb402e3b17790465615ca726b3b3.

⛔ 10 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 2 changed file(s) yielded no anchor (packages/lint/src/validate-hook-body-writes.ts, packages/spec/src/data/hook.zod.ts) — pages documenting those are invisible to this run
  • 1 anchor(s) matched too much of the corpus to be a work list: VALIDATION_ERROR (literal, 40 pages)
  • 4 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 69 of 252 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 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; 124 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 — 195 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 f5da514b07bcbb402e3b17790465615ca726b3b3 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 64be7840f7f3988095a3be235ceba6ee06d27463 — the merge of head 0dad68c61b62b6261639e96f918e6f24f89871f6 into base f5da514b07bcbb402e3b17790465615ca726b3b3, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main 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 64be7840f7f3988095a3be235ceba6ee06d27463 && git checkout 64be7840f7f3988095a3be235ceba6ee06d27463
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin f5da514b07bcbb402e3b17790465615ca726b3b3 0dad68c61b62b6261639e96f918e6f24f89871f6 && git checkout -B drift-repro f5da514b07bcbb402e3b17790465615ca726b3b3 && git merge --no-ff 0dad68c61b62b6261639e96f918e6f24f89871f6

node scripts/docs-audit/affected-docs.mjs --json f5da514b07bcbb402e3b17790465615ca726b3b3

⚠️ 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 f5da514b07bcbb402e3b17790465615ca726b3b3 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSwS4mQyXWrddL4r6B

Final green head · 2026-11-29T19:27Z · zone o3-B · a5d89b4198b7b817b8dbdac09295b0fc3944ccb8 · check-runs 59 success · 11 expected skip · 0 failed · 0 pending; mergeable_state clean; l1-face CLEAN; NOT governed, 307 changed lines. Sent to L1-a for the first review. Closes #38630 on merge (Fixes).
Seat question before landing (dev report 7261277355, deviation 3): SANDBOX_API_WRITE_METHODS gaining updateById makes action-body-write-capability-undeclared refuse, at save and in os validate, an action body that calls updateById without api.write. Before this PR that body saved and then threw at every run. Whether that is a narrowing arm (Metadata-protocol: narrowed, a contract-review-tier review owed) is with the seat repo:objectstack#3; the PR stays draft until it answers.

…ssignment object is refused at save; the write-leaf lists name updateById

The changeset declares the narrowing: an action body calling updateById
without api.write, and an elevated body writing an identity-assignment
object through it, are refused at save and in os validate.

Claude-Session: https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B
Co-authored-by: Claude <noreply@anthropic.com>
…nd cli stay patch

Claude-Session: https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet objectstack-fleet Bot changed the title fix(runtime,cli,lint): a sandboxed body's ctx.api.object(X).updateById(id, patch) writes the row fix(runtime,cli,lint,spec)!: a sandboxed body's ctx.api.object(X).updateById(id, patch) writes the row Nov 29, 2026
…ong the judged write calls

The save-time refusal it registers now judges updateById too, so its
surface and reason list the call beside insert, update, delete,
updateMany, deleteMany and upsert. The upgrade guide is a projection
of this entry and is generated, not committed.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B
… the build infers api.write from

updateById is inferred since this change; updateMany and deleteMany
were inferred already and the row omitted them.

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

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSwS4mQyXWrddL4r6B

Final green head · 2026-11-29T22:24Z · zone o3-B · 60c75f96865c3d84cc0d2a19d55437c9adbaa50f · check-runs: 64 success, 12 expected skips, 0 failed, 0 pending · mergeable_state clean · not governed, +349 / -32.
This supersedes the earlier final-green 7261303617 at a5d89b4. Since then the seat ruled this a narrowing (claim amendment 7261329737), and the step-18 entry was folded in (claim amendment 2, 7262440822). The PR title carries ! and the body is narrowed; the zone wrote both through issue_patch, and the read-back was identical.
l1-face flags only dogfood. The full battery was run at f7b947f (495 files passed, 3 skipped; 4187 tests passed). The two commits after it change only a ledger-entry string (step 18) and one docs table row, and CI's Dogfood Regression Gate is green at this head. The reviewer judges whether that reading covers this head.
Owed sentence-by-sentence reads: the changeset, content/docs/automation/hook-bodies.mdx and content/docs/deployment/validating-metadata.mdx. One CONTRACT_REVIEW_TIER review is owed and the seat routes it. The PR stays draft until it passes, and the landing goes through the seat. Closes #38630 on merge (Fixes).

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmQm8PTU4AkVU5kdwEv
L1-a, the seat's L1 thread · 2026-11-29T22:37Z · first review

席位核对

REWORK @ 60c75f96865c3d84cc0d2a19d55437c9adbaa50f (card #38630, Fixes, zone o3-B). There is one must-fix, in the changeset. Everything else checks out at this head, as read below.

Must-fix 1. The BREAKING section's second row states the old behaviour wrongly.

  • Line 20's FROM cell says "saved, then refused at run time". Line 22 says "the run-time security middleware already refused the second".
  • Before this PR the sandbox's WRITE list had no updateById. At base c8019932, quickjs-runner.ts:754 reads ['insert', 'update', 'delete', 'updateMany', 'deleteMany', 'upsert'].
  • So an elevated body calling ctx.api.object('sys_user_position').updateById(…) threw TypeError: not a function on every run, exactly as the first row did. It never reached the security middleware. The middleware's refusal of that call starts with this PR, once the sandbox installs updateById.
  • This text becomes the published CHANGELOG, and a customer reads the FROM column as what happened before the upgrade. Please make the second FROM cell say the body threw TypeError: not a function at run time. Please make line 22 say both bodies threw that before this change, and that with the call now installed, the first is refused for api.write and the second by the run-time security middleware.
  • A changeset-only delta is enough. I will re-read just that file.

Read at head (these stand, and the delta review will not reopen them):

  • Declarations. The title has !. The body and the changeset have Clause-②: no (narrowing) and Metadata-protocol: narrowed. The changeset has a BREAKING banner with a FROM→TO table, which is the subject of the must-fix. Bumps: lint and spec minor (the two doors that narrow), runtime and cli patch.
    • The ADR-0087 disposition is not-required (already-registered …) and names both entries. 19.publish-refuses-seeds-and-actions-that-save-and-do-not-work registers the action-body ctx.api write without api.write. 18.hook-action-body-system-identity-assignment-write-refused registers the elevated identity-assignment write. No id is added and no key is re-shaped, so already-registered is right.
    • Skills-docs: none is true. Its reason is that skills/objectstack-data/references/data-hooks.md lists a curated subset (insert / update / delete), and nothing under skills/** lists the full leaf set.
  • Spec. identity-assignment-body-writes.ts:48 BODY_WRITE_METHODS gains updateById. WRITE_CALL closes on \s*\(, so update never matches inside updateById and the new name must be listed on its own, as it is.
    • My ablation was to drop updateById from that list. It gives 6 failed | 25 passed (31): the four per-method batteries and the hook and action updateById pins. The control stays green. Restored, tree clean.
  • The write-leaf lists agree. Runtime WRITE (quickjs-runner.ts:757), lint SANDBOX_API_WRITE_METHODS (validate-action-body-capabilities.ts:68-71), spec BODY_WRITE_METHODS, cli OBJECT_WRITE_LEAVES and the cli api.write inference pattern all carry updateById.
  • My own runs, in a clean worktree at this head, after building the runtime, cli and lint closures:
    • spec identity-assignment-body-writes plus src/migrations: 6 passed, 240 passed (240).
    • lint validate-action-body-capabilities, -writes, validate-hook-body-writes and rule-explanations: 4 passed, 157 passed (157).
    • cli extract-hook-body: 67 passed (67).
    • runtime src/sandbox, including body-update-by-id.integration: 51 passed, 569 passed | 2 skipped (571).
    • From the paused round at a5d89b4, the runtime id-guard ablation (n !== 0) still stands. That code did not change after it.
  • Docs, read sentence by sentence.
    • validating-metadata.mdx:525: the write list gains updateById and now matches SANDBOX_API_WRITE_METHODS. This was the row I flagged at a5d89b4.
    • hook-bodies.mdx:326: the sandbox's write leaves gain updateById and match runtime WRITE.
    • hook-bodies.mdx:455: the inference row now lists insert / update / updateById / updateMany / upsert / delete / deleteMany / patch / remove / create, the same set as OBJECT_WRITE_LEAVES in extract-hook-body.ts:562.
    • The changeset's other paragraphs are true against the code: the updateById leaf behind api.write, the id guard and its six refused forms with VALIDATION_ERROR / 400, update({ id, … }) unchanged, the api.write inference, and the two refusal texts.
  • Dogfood (the item l1-face flags). My judgement is that the battery at f7b947f covers this head.
    • The CI "Dogfood Regression Gate" success at this head is the summary job; its three shards are skipped on a PR. So it is not a battery reading at this head.
    • From f7b947f to 60c75f9 only two files changed: entry 18's surface / reason strings and the hook-bodies.mdx row.
    • No file under packages/qa/dogfood names entry 18 or identity-assignment (grep, 0 hits). Neither change is code a boot runs.
    • The must-fix delta adds only changeset text, so this judgement carries over to it. The seat makes the landing call.
  • Mechanical face. l1-face flags only dogfood, judged above. Checks at this head: 64 success, 12 expected skip, 0 failed. mergeable_state is clean. Fixes is right: the card's call now writes the row, and the two doors refuse it wherever they refused the same write.

For the L2 at CONTRACT_REVIEW_TIER (the seat routes it): entry 18 is a v18 semantic entry, and claim amendment 2 (7262440822) edits its surface and reason to name updateById. That is the seat's ruling. Note that the v18 upgrade guide's projection will then list a call that is refused only from this release.

…teById threw TypeError too

The sandbox did not install updateById, so that body never reached the
run-time security middleware. The BREAKING table and the sentence after
it now say so.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B
…tity-assignment save refusal

Through v18 a sandboxed body had no updateById leaf and the call threw
TypeError, so the v18 entry rightly does not name it; it is restored
byte-identical to main. The new v19 entry records that a save now
refuses an elevated body writing sys_user_position,
sys_user_permission_set, sys_invitation or sys_member through
updateById. The changeset registers it beside the publish-refuses
entry that covers the api.write half.

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

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmQm8PTU4AkVU5kdwEv
L1-a, the seat's L1 thread · 2026-11-29T23:25Z · delta review

席位核对

ACCEPT @ 4c186ea46d04fe608fb8cafa1937f8ff8d63c3fa (card #38630, Fixes, zone o3-B). This is the delta from REWORK 7263826297 at 60c75f96. The narrowing owes L2 at CONTRACT_REVIEW_TIER; the seat routes it and lands at Tier H. The PR stays draft.

The delta is three files. I read each sentence by sentence:

  • Must-fix 1 is fixed. In .changeset/38630-sandbox-update-by-id.md, the second BREAKING row's FROM cell now says "saved, then threw TypeError: not a function at every run". The next paragraph now says three things, each true against the code:
    • both bodies threw that before this change, because the sandbox did not install updateById (base quickjs-runner.ts:754);
    • now the first is refused for its missing api.write and the second by the run-time security middleware. plugin-security flow-system-identity-write-refusal.ts governs update with PERMISSION_DENIED (403), and the sandbox's updateById reaches it through the engine's update, as measured at a5d89b4;
    • both are also refused at save.
  • Entry 18 is unchanged. Its file is byte-identical to the PR base c8019932 (git diff --stat is empty). This follows the seat's correction (claim amendment 3, 7263848975), and it removes the history-rewrite note I left for L2 at 60c75f9.
  • The new entry 19.hook-action-body-system-identity-assignment-update-by-id-refused.ts.
    • Its surface is exactly the updateById case: the two body kinds and the four objects.
    • Its replacement repeats entry 18's prescription word for word: a runAs: 'user' hook or flow, or the four organization endpoints.
    • Its reason is true. Through protocol 18 the sandbox had no leaf and entry 18 judged the six other calls. This release installs updateById, and both schemas refuse it at body.source at the same four doors. The run-time PERMISSION_DENIED (403) is the code above.
    • Its acceptanceCriteria mirrors entry 18's for this one call.
  • The ADR-0087 disposition is now registered. The marker names hook-action-body-system-identity-assignment-update-by-id-refused and publish-refuses-seeds-and-actions-that-save-and-do-not-work.
    • At head, check-adr-0087-registration.mjs exits 0 and reports "new here: …update-by-id-refused".
    • My ablation: I dropped the new entry in a local-only commit (the gate reads the registries at HEAD). The gate then exits 1: "1 of those id(s) do not exist in the ADR-0087 registries at HEAD". Reset to 4c186ea4, tree clean.
  • My own runs, in a clean worktree at this head, after pnpm gen:migration-registry (the registry is generated): spec src/migrations plus src/identity, 18 passed, 440 passed (440).
  • Dogfood. I still judge that the battery at f7b947f covers this head. Since f7b947f, the diff is:
    • entry 18, which nets to unchanged;
    • one new migration-entry data file;
    • changeset prose;
    • one hook-bodies.mdx row.
      No file under packages/qa names the new id or entry 18 (grep, 0 hits), and none of it is code a boot runs. The seat makes the landing call.
  • Mechanical face. l1-face flags only dogfood, judged above. Changeset and declarations are ok. Checks at this head: 64 success, 12 expected skip, 0 failed. mergeable_state is clean.

Everything else stands as read at 60c75f9 in 7263826297.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSAjFEZHRpRq3WCj6z

Contract-review-handoff: repo:objectstack#1 — CONTRACT_REVIEW_TIER unavailable (project rule: the maintainer bars the ceiling tier in this seat, 「契约复审交 review 席位,不用 fable」; no l2-review or review seat is seated, mailbox list read 2026-11-29T23:26Z) · head 4c186ea

Faces: narrowing (Clause-②: no (narrowing), Metadata-protocol: narrowed, title !: an action body calling updateById without declaring api.write is refused at save and os validate; an elevated body writing an identity-assignment object through updateById is refused at save) and published schema (packages/spec BODY_WRITE_METHODS gains updateById; one new v19 semantic entry; step-18 entry unchanged). L1 ACCEPT 7264456877 (delta). The PR takes needs:contract-review in this stroke.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSAjFEZHRpRq3WCj6z

Contract-review-claim: session_01ADHkmSAjFEZHRpRq3WCj6z · head 4c186ea · 2026-11-30T00:10Z

The seat takes the tier itself from here (the maintainer, 2026-11-30 「你现在有fable」); the earlier handoff to repo:objectstack#1 is withdrawn on its mailbox #38524.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSAjFEZHRpRq3WCj6z

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 4c186ea46d04fe608fb8cafa1937f8ff8d63c3fa
Local-runs: none
Scope: packages/spec/src/identity/identity-assignment-body-writes.ts, packages/spec/src/migrations/entries/semantic/19.hook-action-body-system-identity-assignment-update-by-id-refused.ts + packages/runtime/src/sandbox/quickjs-runner.ts, packages/cli/src/utils/extract-hook-body.ts, packages/lint/src/validate-action-body-capabilities.ts, packages/lint/src/rule-explanations.ts, packages/lint/src/authoring-rules.ts, packages/lint/src/validate-action-body-writes.ts, packages/lint/src/validate-hook-body-writes.ts, packages/spec/src/identity/identity-assignment-body-writes.test.ts, packages/runtime/src/sandbox/body-update-by-id.integration.test.ts, packages/cli/test/extract-hook-body.test.ts, packages/lint/src/validate-action-body-capabilities.test.ts
Security-touching: yes
Rule-change-verified: none

Inputs read: card #38630 (body and all 12 comments), PR #38643 (body, 16-file list, all 6 comments), the net diff f3028c5eb0..4c186ea46d, and the check-runs on the head (every completed run success or an expected skipped; no failure, none pending). Code outside the diff was read at the head, not reviewed. Security-touching: yes because the hunks teach capability-grant and identity-assignment refusal behaviour; no hits path is under skills/**, so no label is asked for. No path is under .claude/**.

① Derived judgments

  • HookSchema / ActionSchema accept set, narrowed — right. BODY_WRITE_METHODS gains updateById; WRITE_CALL closes on \s*\(, so update cannot match inside updateById and the name has to be listed on its own. Both the chained form and the bound-handle form reach it (one WRITE_CALL). A runAs: 'system' hook or a script action whose language: 'js' body calls updateById on one of the four objects is now refused at body.source. Declared: Clause-②: no (narrowing), Metadata-protocol: narrowed.
  • Lint accept set, narrowed — right. SANDBOX_API_WRITE_METHODS gains updateById, so action-body-write-capability-undeclared refuses an ungranted updateById in an action body at save, publish and os validate. Declared in the same lines; covered by the registered v19 entry publish-refuses-seeds-and-actions-that-save-and-do-not-work, whose surface is "a ctx.api write without api.write", method-agnostic.
  • Sandbox surface, widened to the declared contract — right. WRITE gains updateById, behind the same api.write gate, forwarded by name to ObjectRepository.updateById (engine.update(object, { ...data, id }, { where: { id } }), two parameters, so no third argument can carry a filter or multi). This honours HookObjectApi.updateById and IScopedObjectRepository.updateById; no new authority over update({ id }).
  • New refusal at the crossing — right. A non-scalar, empty, zero or non-finite id answers VALIDATION_ERROR / 400 before the host is called. It replaces TypeError: not a function, so nothing that worked is taken away, and it matches the contract sentence "A falsy id is ... a REFUSAL".
  • Build inference, widened — right. The api.write alternation and OBJECT_WRITE_LEAVES name updateById ahead of update; a lowered handler whose only write is updateById is granted the call it now has.
  • Public surface. One new migration id (hook-action-body-system-identity-assignment-update-by-id-refused); the exported value of lint's SANDBOX_API_WRITE_METHODS gains a member; no spec export, key or type moves. The v18 entry is not in the diff.

② Semver level

Clause-②: no (narrowing) — matches the diff. Metadata-protocol: narrowed takes at least minor on a package the diff moves: @objectstack/spec minor and @objectstack/lint minor are the two doors that narrow; @objectstack/runtime and @objectstack/cli patch are a fix and its inference. The changeset carries the BREAKING banner, a FROM to TO table whose FROM cells now both say the body threw TypeError: not a function, and one ADR-0087 marker, registered, naming the new entry and the existing v19 one. Check Changeset is success on the head. @objectstack/spec is at 19.0.0-next.2, so a v19 entry is the right step. Skills-docs: follow-up #38655 is taken as declared; that card is outside this brief's inputs and was not read.

③ Boundary flags

  • Decision-analysis premise 5 (a non-scalar id reaching where: { id }): answered. Measured refused by the engine before the change, and now refused at the crossing with one coded error; six shapes pinned with an engine-middleware counter at zero.
  • Dev round 1 open_questions (does BODY_WRITE_METHODS follow here or in its own card): answered by claim amendment 7261329737, folded in; present in the diff with its pins and a control.
  • Dev round 2 open_questions (the v18 entry's method lists): answered by claim amendment 3 (7263848975), which withdrew amendment 2's edit; the v18 entry is absent from the file list and a new v19 entry records the step. Right: v18 never refused updateById.
  • Round 1 deviations (test file under src/sandbox/, the two author-facing sentences outside the named lines, the lint narrowing): each is covered by an amendment or is the declared narrowing itself.
  • Rounds 3 to 5 carry no open question.
  • SQL push-down: no new id materialisation and no in-app join. updateById is one engine.update with where: { id }; the guard reads one argument in the VM.
  • Dogfood: the battery reading is at f7b947f; the commits since are ledger-entry text, one docs row and changeset prose. L1-a judged that it covers this head; I have no reason against it, and the landing call is the seat's.

④ Design judgment

packages/spec/src/identity/identity-assignment-body-writes.ts — holds. The list names itself "the api.write set" of the runner, and at this head the runner's WRITE, lint's SANDBOX_API_WRITE_METHODS, the cli's OBJECT_WRITE_LEAVES and this list agree on the same seven names. Without this line the save-time half would have gone blind to a write the PR itself makes reachable; the run-time half (flow-system-identity-write-refusal.ts, GOVERNED_OPERATIONS holds update) judges the engine operation, so it already covers the call. First consumers hook.zod.ts:201 and action.zod.ts:2816 read the function unchanged. Tried to break: update shadowing updateById in the alternation (no, the pattern backtracks on \s*\(), optional chaining and bound handles (shared WRITE_CALL), a non-identity object (control parses).

19.hook-action-body-system-identity-assignment-update-by-id-refused.ts — holds, read sentence by sentence. surface is exactly the two body kinds, the one call and the four objects. replacement restates the v18 prescription. reason: through v18 WRITE had no updateById (base quickjs-runner.ts:754) and the v18 entry lists six calls; the schemas refuse on the handle or a bound name, one issue per object at body.source; the run-time code and status are the middleware's. No relevantWhen, as its v18 sibling has none. Lint & Repo Gates and Test Core are green with the entry in the registry.

quickjs-runner.ts — agrees with the contract. The guard sits after the capability gate and the ctx.api check and before any argument is dumped or the host called; it throws through hostErrorToVm, the same path the capability denial uses, so the body sees code and status and can catch it. Accepted: a non-empty string, a finite non-zero number. Refused with a named shape: empty string, 0, NaN and infinities, null, objects and arrays, undefined, and every other type by its typeof. One leaf list in the file; a transaction-scoped context reuses the same leaf.

extract-hook-body.ts, validate-action-body-capabilities.ts, rule-explanations.ts, authoring-rules.ts, validate-action-body-writes.ts, validate-hook-body-writes.ts — each changed sentence is true against the installed set; the action-record-write-discarded hint keeps update({ id, ... }), which is still a write the sandbox installs. The tests pin both faces, the gate, the control and each refused shape.

S1 (should-fix) — packages/spec/src/data/hook.zod.ts:182-183, the contract block over refuseElevatedIdentityAssignmentBodyWrite, still reads "whose source names a write (insert, update, delete, updateMany, deleteMany, upsert)". That block is the published schema's own statement of what this refinement refuses, and this PR makes it incomplete: the parse now refuses updateById too. It is the same defect the PR fixed in the lint comments and the two docs lists, and the one the PR body says is closed ("Write-leaf lists brought to the installed set"). Fix: add updateById to that list in the same PR. (action.zod.ts names no methods and needs nothing.)

N1 (nit) — packages/lint/src/validate-readonly-hook-writes.ts line 59 (comment: the VM "installs exactly insert/update/delete/updateMany/deleteMany/upsert") and line 296 (the reason string of the exported READONLY_HOOK_METHOD_EXCLUSIONS, which lists the same six as installCtx's leaves) are now incomplete. No rule output changes. Since S1 moves the head anyway, both lines can go in the same commit; otherwise a follow-up card.

N2 (nit) — the id guard throws synchronously at the call site, like the capability denial, so a body that writes updateById(bad).catch(...) without await in a try does not see it in the .catch. Consistent with the existing gate; accepted as is.

Implemented-by: claude/issue-38630-sandbox-update-by-id
Reviewed-by: session_01ADHkmSAjFEZHRpRq3WCj6z

VERDICT: PASS

…nly-rule sandbox list name updateById

Comment and string text only: hook.zod.ts's contract block over the
elevated identity-assignment refusal, and the installed-leaf list in
validate-readonly-hook-writes.ts's comment and its create() exclusion
reason, now include updateById.

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

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmQm8PTU4AkVU5kdwEv
L1-a, the seat's L1 thread · 2026-11-30T00:25Z · delta review

席位核对

ACCEPT @ 0dad68c61b62b6261639e96f918e6f24f89871f6 (card #38630, Fixes, zone o3-B). ACCEPT 7264456877 carries over to this head. This round carries the seat's L2 PASS 7265079064 items S1 and N1, under claim amendment 4 (7265093039).

  • The delta is one commit. Its parent is 4c186ea4, the head ACCEPT 7264456877 judged. It touches two files and changes only comments and one string:
    • packages/spec/src/data/hook.zod.ts:182: the refusal docblock's write list gains updateById. It now matches BODY_WRITE_METHODS (identity-assignment-body-writes.ts:48), which this PR already widened.
    • packages/lint/src/validate-readonly-hook-writes.ts:59: the // note's sandbox leaf list gains updateById and now matches runtime WRITE (quickjs-runner.ts:757).
    • The same file's READONLY_HOOK_METHOD_EXCLUSIONS create reason (:295) gets the same list. This string ships, and @objectstack/lint already has its changeset entry. Its one test reader asserts toMatch(/can no longer reach this rule/) (validate-readonly-hook-writes.test.ts:478), which the edit does not touch.
  • Both edits are true. Each list is now the seven leaves the sandbox installs.
  • A nit the dev named. The test comment at validate-readonly-hook-writes.test.ts:412 still lists the six old leaves. It is a comment in a test file, which ships nothing, so it does not block.
  • Dogfood. The battery at f7b947f still covers this head, in my judgement. The added delta is two comments and one reason string, and no file under packages/qa reads READONLY_HOOK_METHOD_EXCLUSIONS. The seat makes the landing call.
  • Checks. At 00:24Z this head read 9 success, 9 expected skip, 0 failed and 19 pending. They must be read green before landing.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSAjFEZHRpRq3WCj6z

Contract-review-claim: session_01ADHkmSAjFEZHRpRq3WCj6z · head 0dad68c · 2026-11-30T00:52Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSAjFEZHRpRq3WCj6z

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 0dad68c61b62b6261639e96f918e6f24f89871f6
Local-runs: none
Scope: packages/spec/src/identity/identity-assignment-body-writes.ts, packages/spec/src/migrations/entries/semantic/19.hook-action-body-system-identity-assignment-update-by-id-refused.ts, packages/spec/src/data/hook.zod.ts + packages/lint/src/validate-readonly-hook-writes.ts, packages/runtime/src/sandbox/quickjs-runner.ts
Security-touching: yes
Rule-change-verified: none

Delta round over 4c186ea4 (record 7265079064). The delta is one commit, 0dad68c61b, whose only parent is the head reviewed before; it touches two files, 5 lines in and 5 out, all comment or string text. Inputs read: the compare 4c186ea46d..0dad68c61b, both files at the new head, the runner's WRITE list at the new head, the PR's declaration lines, and the check-runs on the new head (62 success, 10 expected skipped, none failed, none pending). Everything the first record judged outside these two files is byte-identical and stands as read there.

Prior findings:

  • S1: closed
  • N1: closed
  • N2: accepted as is, unchanged (the id guard throws synchronously, like the capability denial)

① Derived judgments

  • No accept-set change in the delta — right. hook.zod.ts moves two lines inside the contract block over refuseElevatedIdentityAssignmentBodyWrite; the refinement, its guard and identityAssignmentWritesNamedIn are untouched. validate-readonly-hook-writes.ts moves two comment lines and one line of the reason string of READONLY_HOOK_METHOD_EXCLUSIONS; no method list, rule id or finding moves.
  • Public surface. The exported reason string of the create exclusion gains one word. No export is added or removed; no schema, key, type or migration id moves.
  • The narrowing is the one already judged. BODY_WRITE_METHODS, SANDBOX_API_WRITE_METHODS, the runner's WRITE and the cli's leaf alternation are unchanged from 4c186ea4.

② Semver level

Clause-②: no (narrowing) — unchanged, and still matches the diff. The PR body still carries Clause-②: no (narrowing), Metadata-protocol: narrowed and the ! title; the changeset is untouched by the delta. Both packages the delta touches already move in it (@objectstack/spec minor, @objectstack/lint minor), and comment and message text asks for no higher level. Check Changeset is success on the new head.

③ Boundary flags

  • The delta raises no dev flag and no open_questions entry; the answers recorded on 4c186ea4 stand.
  • SQL push-down: nothing in the delta reads or writes data.
  • Dogfood: the delta is comment and string text that no boot runs; the earlier judgment on the battery reading carries over, and the landing call is the seat's.

④ Design judgment

packages/spec/src/data/hook.zod.ts — holds. The block now reads "names a write (insert, update, updateById, delete, updateMany, deleteMany, upsert)": seven names, the same seven in the same order as BODY_WRITE_METHODS in identity-assignment-body-writes.ts and as WRITE at quickjs-runner.ts:757. No name is added beyond the installed set and none is missing, so the published schema's statement of the refinement and the refinement agree again.

packages/lint/src/validate-readonly-hook-writes.ts — holds. Line 59 says the VM "installs exactly" the seven, and the reason string lists the same seven as installCtx's leaves; both match WRITE name for name. The sentence each sits in is still true: the VM installs no create leaf, and IScopedObjectRepository declares insert. Test Core is green on the new head, so no pin on that string was broken.

A sweep at the new head for a sandbox write-leaf list that names deleteMany with insert or upsert and not updateById finds none left in packages, content/docs (releases apart) or skills; the remaining hits are driver operation unions and batch endpoints, which are not the sandbox set.

No must-fix, no should-fix.

Implemented-by: claude/issue-38630-sandbox-update-by-id
Reviewed-by: session_01ADHkmSAjFEZHRpRq3WCj6z

VERDICT: PASS

@objectstack-fleet objectstack-fleet Bot removed the needs:contract-review Marker only — PR awaits its at-tier Contract review PASS; no check reads it, the record decides label Nov 30, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSAjFEZHRpRq3WCj6z

维护者速读

  • 用户能看到什么变化:脚本动作和触发器里按文档写的「按编号更新一条记录」现在真的能保存改动(以前第一次运行就报错、数据不变);传错编号会得到一句清楚的拒绝,什么也不写。
  • 为什么做:文档和对外类型都承诺了这个写法,只有脚本沙箱缺了它。
  • 出错会怎样:只影响用这个写法的脚本;保存检查同时变严,没声明写权限就用它的脚本动作、以系统身份用它改人员授权记录的脚本会在保存时被拒(这两种以前从来跑不成功);可直接撤回。
  • 要你做什么:这是收紧保存检查的改动,需要你审批。契约复审 PASS 在评论 7265670341,Head-sha 0dad68c61b62b6261639e96f918e6f24f89871f6;批准后由席位落地。

Seat opinion: land as is. The narrowing refuses only bodies that never ran (they threw TypeError: not a function), it carries the ! title, a BREAKING changeset row and a new v19 ADR-0087 semantic entry, and both review legs are on the current head with nothing open.

席位核对

ACCEPT at head 0dad68c61b62b6261639e96f918e6f24f89871f6 · Tier H (declared narrowing, maintainer-landed leg) · Fixes #38630

  1. Shape: one card, runtime fix + id guard + CLI inference + lint list + spec BODY_WRITE_METHODS; one Clause-② arm (narrowing) per PR, as ruled for this card.
  2. Premise measured: the PR body's probe at origin/main f3028c5 shows updateById threw TypeError: not a function on both faces; after the change it writes one row and refuses non-scalar ids as VALIDATION_ERROR / 400.
  3. Gates: check-runs on this head 62 success, 10 expected skips, 0 failed, 0 pending.
  4. Accepted deviations: N2 (the id guard throws synchronously, like the capability denial) is accepted as is.
  5. Out of scope and where it went: skills docs for updateById → skills: teach three new save-time refusals — an ungroupable list-view grouping field, updateById in a body without api.write, and a hook or action body calling an ungranted capability #38655 (Skills-docs: follow-up #38655).
  6. Landing: L1 ACCEPT 7264456877, delta ACCEPT 7265266081; L2 contract review PASS 7265079064 (head 4c186ea4), delta PASS 7265670341 on this head with S1 and N1 closed. Lands after os-zhuang approves.

ACCEPT → PR #38643 comment 7265266081 · Contract review → comment 7265670341

@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 00:58
@os-zhuang
os-zhuang added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit 4b57756 Nov 30, 2026
80 of 81 checks passed
@os-zhuang
os-zhuang deleted the claude/issue-38630-sandbox-update-by-id branch November 30, 2026 01:25
@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
…ng declares (objectstack-ai#38648)

<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9JeHmqv6CKCkW8ewrPBLekk)_
Fixes objectstack-ai#38623
Clause-②: no
Metadata-protocol: none

## 维护者速读

- 在 Studio、元数据接口或 AI
助手里保存或发布一条翻译时,如果它指向一个已经不存在的对象、字段、校验规则、里程碑或权限集,保存结果里会多出一条提示;以前保存显示一切正常,什么都不说。
- 属于“错误的元数据要被明确指出”这项构建能力:本地校验早就会报这类问题,线上保存却静默通过,这次替在 Studio 和 AI
助手里写翻译的作者补上这个缺口。
-
出错的最坏情况是对一条其实有效的翻译多报一条提示,保存本身照常成功、不会被拒;应用的导航菜单和应用名这类翻译这次仍不检查,可以直接撤回这次改动。
- 无。

## What changes

A `translation` item saved (active) or published over the metadata API
now runs `validateTranslationReferences` at the runtime publish gate. An
orphan key comes back as a `translation-target-unknown` **advisory** on
the save and publish answer (`advisories`, severity `warning`). Before
this, no rule ran on a `translation` write
(`runtimeAuthoringRulesFor('translation')` was `[]`): the item was
accepted as valid while `os validate` refused the same key.

**Never a refusal.** Every finding on a translation write is a
`warning`, so it lands in `advisories` and never in the 422 `errors`. A
published item that names a key an upgrade removed still loads and
saves. `os validate` keeps reporting the same key at `error`.

**Families the door judges** (the ones the per-write snapshot carries,
`RuntimeStackContext`: objects, permissions, books, datasets):

- `objects.NAME`, only when the gate did not narrow `objects` to the
write's package closure. The i18n layer is process-wide, so a
translation may legitimately name an object outside its package's
closure.
- `objects.NAME.fields.FIELD`, and the field's `options` keys, only for
a field that declares options inline. A picklist-bound field's served
options are not in the snapshot.
- `objects.NAME._validations.RULE`
- `objects.NAME._milestones.FIELD.VALUE`
- `permissions.NAME`

**Not judged at the door:** apps and their navigation
(platform-contributed nav items included), `_views`, `_sections`,
`_tabs`, `_relatedLists`, `_actions`, `globalActions`, `dashboards`,
`forms`, `pages`, `picklists`, `positions`, `reports`, `mappings`,
`books` (the implicit per-package book is named by a package id the
snapshot never sees), `flows`, `hooks`. Each resolves into a collection
no per-write snapshot carries, so the door never guesses a key there
unknown; `os validate` still judges all of them. Judging apps and
navigation at the door would mean carrying served apps in the snapshot.
That is a separate decision and not this card.

The changes:

- `authoring-rules.ts`: the `validateReferenceIntegrity` entry's
`runtimeTypes` gains `translation`, so a translation write dispatches
the suite.
- `reference-integrity-suite.ts`: the `validateTranslationReferences`
member gains `runtimeTypes: ['flow', 'translation']` and still hands its
run context straight through.
- `validate-translation-references.ts`: the rule reads `runtimeWriteType
=== 'translation'` off that context as its save-door reading. That is
the signal the suite's other members already read for `wholeCollection`.
In that reading the rule treats the entry as one item (keyed by its own
`locale`), reduces the item to the judged families, and maps every
finding to `warning`.
- `runtime-gate.ts`: `TYPE_TO_STACK_KEY` gains `translation:
'translations'`. No context row is added, and no metadata-protocol
source changes.
- `scripts/engine-double-contract.pinned.json`: the three engine doubles
the new protocol pin uses (`delete`, `findOne`, `update`) are recorded,
written by `check-engine-double-contract --write`.
- `content/docs/deployment/validating-metadata.mdx`: the "Reference
integrity" row's runtime-publish cell gains `translation`
(`✓ᶠᵛᵒᵈᵗʳᵖᵃᶜᵗ`), and its text says what a translation write runs. The
superscript legend gains `✓ᵗ` `translation`, and the longest-first note
now covers it. Nothing else on the page changes.

The CLI reading is byte-identical: without `runtimeWriteType` the rule
takes its old path, the whole rule at its own severities.

**Control pins moved** (each held `translation` as the ungated control;
it now crosses, so the control moves to a type that stays ungated;
`tool`'s own control is untouched):

- `packages/lint/src/authoring-rule-wiring.test.ts` ("a type nobody
gated returns nothing"): `translation` → `doc`
- `packages/lint/src/runtime-gate.test.ts` ("runs nothing for a metadata
type no rule gates"): `translation` → `doc`
- `packages/lint/src/runtime-gate.test.ts` ("returns null for an
unmapped type"): `translation` → `doc`
- `packages/lint/src/runtime-gate.inert-type-writes.test.ts` ("crossing
these five widened no OTHER type s roster"): `translation` →
`capability`
- `packages/lint/src/runtime-gate.datasource-writes.test.ts` ("the types
still awaiting their own readings are untouched"): `translation` →
`capability`, and the comment says `translation` crossed on its own
reading

The seat's reading (7260663888 on objectstack-ai#38623) takes this card as the
`translation` reading that the ADR-0049 group B line defers the wiring
to.

**Read these first** (ranked by risk):

1. `packages/lint/src/validate-translation-references.ts`:
`doorJudgedSubset` and the `localeEntries` / `atSaveDoor` lines in
`validateTranslationReferences`. This hunk decides what the door may
judge; a family added here without its collection in the snapshot is a
false advisory on every save.
2. `packages/lint/src/reference-integrity-suite.ts`: the member's
`runtimeTypes`.
3. `packages/lint/src/authoring-rules.ts`: the entry's `runtimeTypes`.

**Two-minute verification:** `pnpm --filter @objectstack/lint exec
vitest run --maxWorkers=2
src/runtime-gate.translation-writes-38623.test.ts` shows 9 passing. The
removed field key, the orphan object, rule and milestone, and the orphan
permission set come back in `advisories` with `errors` empty. Live keys
and the unjudged families come back with neither.

## Tests

New files, named for this card:

- `packages/lint/src/runtime-gate.translation-writes-38623.test.ts`,
through the gate's own entry (`runRuntimeAuthoringRules`):
  - the dispatch: suite on `translation`, exactly the translation member
  - a removed field → advisory, `errors` `[]`
  - an orphan object, validation rule and milestone → advisories
  - an orphan permission set → advisory
  - live keys → none
- apps, navigation, global actions, positions, views and sections → not
judged
  - a picklist-bound field's option keys → not judged
- under a package closure, an object outside it is not judged while its
sibling's removed field still is
  - the CLI reading is unchanged (a bundle, at `error`)
-
`packages/metadata-protocol/src/protocol.translation-target-door-38623.test.ts`,
through the real `saveMetaItem` / `publishMetaItem` write path over a
stub engine:
- an active save naming a removed field → `success`, the advisory, and
the row landed
- a draft save says nothing (D1), and its publish answers with the
advisory
  - a permission-set orphan → advisory
  - live keys → none
- an already-published orphan neither blocks nor rides on an unrelated
translation write

<details><summary>Test runs: the new files at 8775b06; the
whole-package readings at 66c22be (before the main merge, which
brought no lint or metadata-protocol file)</summary>

- At head 8775b06, under the verify lock, after a fresh build of the
`@objectstack/metadata-protocol...` closure:
`protocol.translation-target-door-38623.test.ts` Tests 5 passed (5),
`runtime-gate.translation-writes-38623.test.ts` Tests 9 passed (9),
`VERDICT command-exit 0`. The later docs commit changes no code.

- `pnpm --filter @objectstack/lint exec vitest run --maxWorkers=2`
(whole package): Test Files 247 passed (247), Tests 9977 passed (9977)
- `pnpm --filter @objectstack/lint typecheck`: exit 0 (`tsc --noEmit`
and `check:test-typecheck` OK)
- `pnpm --filter @objectstack/metadata-protocol typecheck`: exit 0
- `pnpm --filter @objectstack/metadata-protocol exec vitest run
--maxWorkers=2 src/protocol.translation-target-door-38623.test.ts`:
Tests 5 passed (5)
- The 29 metadata-protocol test files that mention `translation`: Test
Files 29 passed (29), Tests 862 passed (862)

</details>

<details><summary>Ablation: the entry widening reverted</summary>

`'translation'` removed from the entry's `runtimeTypes` through
`scripts/ablation-replace.mjs`:

- The anchor hit once and the mutation landed (blob 663f139 →
3068dd8e9df2).
- lint was rebuilt, and `ablation-dist-preflight.mjs @objectstack/lint
'"page", "action", "translation"]' --absent` confirmed the marker absent
from all 20 built files. It had been present in the pristine
`dist/runtime.js` and `dist/index.js`.

Results on the mutant:

- lint file: 5 failed / 4 passed. The dispatch case, the removed field,
the orphan object, rule and milestone, the permission set and the
closure case went quiet. Live keys stayed clean, and so did the
unjudged-families, picklist and CLI cases.
- protocol file: 4 failed / 1 passed. The active save, the draft publish
and the permission set went quiet. The live-key save stayed clean. The
already-published-orphan case also fails, because its first save asserts
the advisory as a precondition.

Restored: blob == HEAD (663f139) and `git diff HEAD` empty. lint
was rebuilt, and the protocol file then read 5 passed (5).

</details>

## Acceptance notes

- **False positives, measured on `examples/app-showcase`'s real
`ShowcaseTranslationBundle`** (en + zh-CN; context = the showcase's
objects, permissions, books and datasets):
  - whole-stack `validateTranslationReferences`: 0 findings
- the rule unrestricted on the door's snapshot: 85 phantom
`translation-target-unknown`. By family: `_views` 28, `_sections` 19,
positions 10, flows 10, dashboards 6, `_tabs` 4, reports 4,
`globalActions` 2, apps 1, mappings 1. That is why the door judges only
the families listed above.
- this PR, through `runRuntimeAuthoringRules({ type: 'translation' })`
per locale: errors 0, advisories 0
- the lit control on the same context (a removed `showcase_project`
field) comes back as one `warning` advisory
- A draft save is still never gated (objectstack-ai#4463 D1). The advisory appears on
an active save and on publishing a draft, not on the draft save itself.
- Found while measuring, not changed here: `os validate` refuses a
bundle key under the platform `studio` app at the app level, whatever
the navigation id (`translations[0]["zh-CN"].apps.studio`, "which this
stack neither defines nor contributes into"), even for a live id such as
`nav_api_console`. The lint's apps rung has no platform-app ladder; the
objects rung has `isPlatformProvidedObjectName`. Reported to the seat
with the CLI reproduction.

## Verification

<details><summary>Local gates, derived with dispatch-gates
--commands</summary>

At head 9b075e6. Gates were derived with `node
scripts/pm/dispatch-gates.mjs --commands` (105 families) and each exit
code was captured before any pipe. The `--ran` reconciliation reads: 105
derived, 103 run, 2 NOT MEASURED (derived from a recorded exit 3), 0
unrun.

- 68 code families were read at the code head: 266bea7, then
8775b06 for the ledger. The docs commit 9b075e6 changes only the
page.
- 37 families the docs path adds, all at 9b075e6: exit 0. They
include `check-adr-links` with its self-test (the local half of Check
Documentation Links; lychee runs only in CI, and the edit adds no link),
`check:doc-anchors`, `check:doc-frontmatter`, `check:docs-redirects`,
`check:docs-single-h1`, `check:docs-spec-enumerations`,
`check:docs-audit-scope` and `@objectstack/spec` `check:docs`.
- `@objectstack/spec` `check:skill-examples` first exited 3
(PREREQUISITE NOT MET: client SDK not built). After building
`@objectstack/client-react...` and `@objectstack/client...` under the
lock, it exits 0: "352 prose examples type-check across 3 surface(s)".
- `pnpm check:engine-double-contract`: exit 1 before the ledger commit,
exit 0 after it at 8775b06.
- `pnpm check:objectql-double-limit`: exit 0 ("none new").
- `node scripts/check-nul-bytes.mjs`: exit 0.
- `node scripts/pm/overlap-check.mjs --branch=HEAD` at 9b075e6:
`VERDICT clean exit 0`. The branch merges cleanly with origin/main and
with objectstack-ai#38643, objectstack-ai#38642, objectstack-ai#38594, objectstack-ai#38550 and objectstack-ai#38497.
- NOT MEASURED:
- `node scripts/check-plugin-teardown-shape.mjs --self-test`: exit 3
(shallow checkout).
- `pnpm check:dual-build-cjs-loads`: exit 3 (needs a full `pnpm build`).
- `pnpm check:dts-closure`: exit 1. The self-test passed. The scan's red
came from a local build that skipped declaration output in an earlier
worktree. `@objectstack/lint` and `@objectstack/metadata-protocol` were
not among the packages it named. CI's fresh build gives the real
reading.

The families CI runs (the repo-wide lint, `test:repo`, Check
Documentation Links' lychee step, the artifact roster) are read from
this PR's check-runs. They were not re-run here.

</details>

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

https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B

<!-- signed: repo:objectstack#3 · os-steve ·
session_01ADHkmSwS4mQyXWrddL4r6B -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…it was not granted (objectstack-ai#38650)

<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9JeHmqv6CKCkW8ewrPBLekk)_
Refs objectstack-ai#37815 (items a, b)
Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: follow-up objectstack-ai#38655

## 维护者速读

-
用户能看到什么变化:应用作者保存或校验一个脚本动作或自己写的钩子脚本时,如果代码调用了沙箱需要授权的功能(写数据、事务、日志、发邮件、写活动记录等)却没有声明对应权限,现在会在保存和本地校验时直接被拒并说明要加哪个权限;以前能保存,但每次运行都报错。
- 为什么做:属于脚本动作与钩子的权限检查跟进工作,把只覆盖动作写数据的检查扩展到钩子和沙箱的全部授权项。
-
出错会怎样:误判会让一个本来能运行的动作或钩子保存不了;用函数写、由构建转换出来的钩子和动作这次不做新增检查;已存的元数据不受影响,可以直接撤回;现有示例应用实测无一被拒。
- 要你做什么:无。

## What changes

The QuickJS sandbox gates seven tokens, and before this PR lint judged
one of them on one kind of body (`ctx.api` writes on action bodies,
`action-body-write-capability-undeclared`). A hook body, and an action
body calling any other gate, saved and published clean and then threw
`403 INSUFFICIENT_PRIVILEGES` at every call.

- **Runner census (measured first, read-only).** Every capability gate
in `packages/runtime/src/sandbox/quickjs-runner.ts` at `0ba5e06ae7`:
`api.read` on the `READ` leaves `find` / `findOne` / `count` /
`aggregate` (`installApiMethod`, line 755) and on `ctx.title(FIELD)`
with an argument (line 1035, hook bodies only: the action face builds no
`ctx.title`); `api.write` on the `WRITE` leaves (line 756);
`api.transaction` on `ctx.api.transaction` (`installTxLeaf`, line 783);
`log` on `ctx.log.debug|info|warn|error` (line 881); `crypto.uuid` on
`ctx.crypto.randomUUID` (line 907); `email.send` on `ctx.email.send` and
`activity.append` on `ctx.activity.append` (`installDoor`, lines 941 to
994). That set is exactly `HookBodyCapability` in the spec. The rule
judges exactly that set, as `SANDBOX_CAPABILITY_GATES`.
- **Arm (a), authored hook bodies.** `validateActionBodyCapabilities`
now walks `stack.hooks` too, with the same reading (blanked source; the
member itself, a local bound once to it, or a handle bound once to
`.object(…)`). New id `hook-body-capability-undeclared`, one finding per
body and token, at `hooks[i].body.capabilities`. A hook body is never
granted `email.send` (the hook's parse refuses the grant), so its
`ctx.email.send` call is refused with the remedy that works: remove the
call and send the mail from an action, a job or a flow. **Scope (route
C): authored hook bodies only.** A hook body that `os build` / `os
verify` lowered from an inline `handler` is not judged
(`isLoweredHandlerBody`): under the CLI exactly when
`ctx.loweredHookRefs` holds the hook's string `handler`, and at a door
that hands no lowered refs (the runtime publish doors) whenever a string
`handler` sits beside the body, the shape a build artifact carries. Its
grant is the build's inference, and the extractor does not yet infer
`api.transaction` or a read through a bound handle, so a finding there
would name a grant the handler author cannot write. objectstack-ai#38653 carries the
lowered-handler reading and both extractor gaps. The registry entry
keeps its name and gains `hook` in `runtimeTypes` (the
`validateHookAndJobBodyCompiles` precedent: one entry, ids per kind),
and now receives `ctx`.
- **Arm (b), the other tokens, authored action bodies.** On action
bodies, every gate other than the writes is judged under the new id
`action-body-capability-undeclared`. A missing `api.write` keeps its own
id and its exact words, so nothing that matches on it today changes.
**Scope (contract review M1, claim amendment 3): authored action bodies
only, past the writes.** An action body that `os build` / `os verify`
lowered from an inline `target` function is judged for `api.write` only,
as before (`isLoweredTargetBody`). Measured before the edit: the CLI
hands no lowered-action ref set (`LoweringResult` carries
`loweredHookRefs` only), and `lowerActionCallable` leaves a string
`target` (the registered ref) beside the minted body. So on every door,
the CLI included, a body is read as lowered when a string `target` sits
beside it. No `packages/cli` edit was needed. A JS body runs only on a
`script` action, where `target` is kept for legacy `functions`
references alone; an authored body beside a string `target` is therefore
not judged for the other tokens either, a missed finding, never a false
one. In `examples/app-showcase`, none of the 296 JS-body actions (318
actions in all) carries a string `target`. objectstack-ai#38653 carries the lowered
reading.
- **Pin.** The new test file reads the runner's source: the token set
from `caps.has('…')`, the `installApiMethod` tokens and the
`installDoor` calls must equal the census; the `caps.has(NAME)` calls
with a variable must be exactly the two known ones, so a third
parametrised gate turns it red; the `READ` list, the log levels and the
door triples are pinned; and the census token set must equal
`HookBodyCapability.options`.
- **L1-a's nit from objectstack-ai#38628.** The `action-body-write-unknown-field`
explanation now lists the installed field-carrying leaves: `insert`,
`update({ id, … })`, `updateById(id, { … })`, `upsert`, `updateMany`.
`updateById` landed with objectstack-ai#38643, which this branch merged from `main`;
the census and the gate table read the runner's `WRITE` list and needed
no edit.
- `os explain` entries for both new ids, and two rows in
`content/docs/deployment/validating-metadata.mdx`.
- **Upgrade guide and barrel.** `packages/lint/src/index.ts` exports
both new id constants. A new upgrade-guide entry,
`packages/spec/src/migrations/entries/semantic/19.hook-and-action-bodies-calling-an-ungranted-gate-refused.ts`,
follows the `hook-job-body-does-not-compile-refused` precedent and says
the hook arm covers authored bodies only; the changeset marker is
`registered` with that id, and the changeset carries an
`@objectstack/spec` patch line. The `os build` extractor
(`packages/cli`) is unchanged: byte-identical to `main`.

The rule file's header names `hook` as the third runtime door (review
N2), and the upgrade-guide entry's `acceptanceCriteria` names the inline
path `objects[N].actions[M].body.capabilities` (N2). S1 (`updateById` in
the `action-body-write-unknown-field` leaf list) was met at
`a60a6de915`.

This touches a contract face: the lint rule family's accept set at the
save door and in `os validate` (a narrowing).

## Tests

- New file
`packages/lint/src/validate-action-body-capabilities.hook-and-tokens-37815.test.ts`:
per arm a refused case, a granted control that passes, and an ungated
call that stays quiet; the hook case through the save door
(`runRuntimeAuthoringRules` on `type: 'hook'`) and through
`runAuthoringRules` for `validate` / `build` / `lint`; the hook
`email.send` remedy; `ctx.title(FIELD)` against `ctx.title()`; a shape
table for `bodyGatedCalls`; the runner pin.
- M1 pins, both sides, on one source (a write inside
`ctx.api.transaction`, granted `api.write` only, as the extractor
infers): the authored action body is refused; the same body beside a
string `target` is not judged, through `validateActionBodyCapabilities`,
through `runAuthoringRules` for `validate` / `build` / `lint` at the top
level and inline on an object, and at the `action` and `object` doors
(each with an authored positive control); a lowered body without
`api.write` is still refused under the write id.
- Route C pins, both sides, on one source (a read through a bound
handle): the authored body is refused; the same body lowered from a
handler is not judged, through `validateActionBodyCapabilities`, through
`runAuthoringRules` for `validate` / `build` / `lint` with
`loweredHookRefs`, and at the save door with a string `handler` beside
the body; a string `handler` the build did not lower leaves the authored
body judged.
- One ablation per behaviour with `scripts/ablation-replace.mjs`, each
restored to a clean tree.

<details><summary>Readings at 4c07e0d, 29d3b0f, a60a6de and
c3319db</summary>

- At 29d3b0f: `pnpm --filter @objectstack/lint typecheck && pnpm
--filter @objectstack/lint test`: typecheck clean,
`check:test-typecheck` OK; Test Files 248 passed, Tests 10035 passed.
The new test file: 46 passed. Ablation of the M1 exemption (`if
(lowered) continue;` deleted): Tests 3 failed / 43 passed, exactly the
three lowered-target pins; restored, blob equal to HEAD.
`check-adr-0087-registration --base origin/main`,
`check-changeset-no-major`, `check:spec-changes`, `check:upgrade-guide`
and `check-nul-bytes` exit 0; overlap-check clean.
- Full dogfood battery on 29d3b0f (`pnpm --filter
@objectstack/dogfood test` under the lock, after building the dogfood
closure): Test Files 495 passed / 3 skipped (498), Tests 4187 passed /
68 skipped (4255), VERDICT command-exit 0. The head after it,
4c07e0d, changes only one sentence of the upgrade-guide entry's
guidance text.
- At 4c07e0d, after a cli build: `pnpm --filter @objectstack/cli exec
vitest run --maxWorkers=2 test/migrate-meta-engine-guidance.test.ts
test/explain-rule-id.test.ts test/verify-delete-behaviors.test.ts`: Test
Files 3 passed, Tests 20 passed. The entry's printed guidance names no
tracker, so the Test Core (2/12) red at 29d3b0f is fixed.
`check-adr-0087-registration`, `check-changeset-no-major`,
`check:spec-changes`, `check:upgrade-guide`, `check:generated` and
`check-nul-bytes` exit 0; overlap-check clean.
- At a60a6de (after merging `main` with objectstack-ai#38643): `pnpm --filter
@objectstack/lint typecheck && pnpm --filter @objectstack/lint test`:
typecheck clean, `check:test-typecheck` OK; Test Files 248 passed, Tests
10031 passed. The new test file, census pin included: 42 passed.
`check-adr-0087-registration --base origin/main` exit 0;
`check-changeset-no-major` exit 0.
- At c3319db: lint suite Test Files 248 passed, Tests 10019 passed.
- `pnpm --filter @objectstack/cli exec vitest run --maxWorkers=2
test/verify-delete-behaviors.test.ts
test/published-subpath-hook-body.pin.test.ts
test/explain-rule-id.test.ts test/extract-hook-body.test.ts
test/lint-hook-rules-reach-handler-hooks.test.ts` (after a cli build):
Test Files 5 passed, Tests 109 passed.
- Ablation of the narrowing (the `isLoweredHandlerBody` early return
deleted): Tests 2 failed / 40 passed, exactly the two not-judged pins;
restored, blob equal to HEAD.
- Round 1 ablations: the hook walk removed, 8 failed / 31 passed; the
`api.transaction` gate entry removed, 8 failed / 31 passed; both
restored.
- After the build: `check-adr-0087-registration` exit 0 (1 migration
entry added); `check:spec-changes` exit 0; `check:upgrade-guide` exit 0;
`check:generated` all 14 artifacts current; `check-nul-bytes` OK. The
upgrade guide was regenerated with `gen:upgrade-guide` only.
- `node scripts/pm/dispatch-gates.mjs --commands`: 118 families derived;
116 exit 0, 2 NOT MEASURED (exit 3, PREREQUISITE NOT MET:
`check:skill-examples`, `check:dual-build-cjs-loads`); `--ran`
reconciliation: 118 accounted for. CI on c3319db: 72 check-runs, 62
success and 10 skipped, among them `Lint & Repo Gates`, `Test Core`,
`Check Changeset` and `Dogfood Regression Gate` green.
- Full dogfood battery on c3319db (`pnpm --filter
@objectstack/dogfood test` under the lock, after building the dogfood
closure): Test Files 495 passed / 3 skipped (498), Tests 4187 passed /
68 skipped (4255), VERDICT command-exit 0.
- First-party measurement of example apps before any edit: 0 findings. A
sweep of 50 handlers under `packages/*/test/**` and `examples/**` found
one body refused under the lowered-handler reading
(`packages/cli/test/verify-delete-behaviors.test.ts`); under route C it
is not judged, and that test is green.

</details>

## Acceptance notes

- Scope, route C (claim amendment 2): the hook arm judges authored hook
bodies only. Lowered handlers, and the two extractor gaps under them (no
`api.transaction` inference; no `api.read` inference through a bound
handle, `?.` before the leaf or an argument holding parentheses), are
carried by objectstack-ai#38653, a widening that follows this PR. The published
`@objectstack/cli/hook-body` type and its pin are untouched, so this PR
keeps its one Clause-② arm.
- At the runtime publish doors a hook carrying both a string `handler`
and a body is read as a build artifact and not judged. A hand-written
hook with both keys is therefore not judged either: a missed finding,
never a false one.
- An action carrying both a string `target` and a JS body is read as
lowered on every door, the CLI included, and judged for `api.write`
only. That covers an author who wrote a body beside a `target` function,
too: `lowerActionCallable` keeps that authored body and still turns the
`target` into a string ref. A missed finding, never a false one. objectstack-ai#38653
carries the lowered reading for both arms.
- Not changed, per the review: N1 (`ctx.title(undefined)` /
`ctx.title(null)` read as the related-record form) and N3 (job bodies
are not judged).

## Verification

Read first: `packages/lint/src/validate-action-body-capabilities.ts`
(`SANDBOX_CAPABILITY_GATES`, `bodyGatedCalls`, the hook walk), then
`isLoweredTargetBody` and the action loop's `lowered` skip, then the new
test file's runner-pin block, its M1 pins and its route C pins, then the
`authoring-rules.ts` entry (`runtimeTypes` gains `hook`, `run` receives
`ctx`).

Two-minute check: `pnpm --filter @objectstack/lint exec vitest run
src/validate-action-body-capabilities.hook-and-tokens-37815.test.ts`
shows 46 passed.

---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B)_

<!-- signed: repo:objectstack#3 · os-steve ·
session_01ADHkmSwS4mQyXWrddL4r6B -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
… whose documentBy is not a single-valued parent link (objectstack-ai#38662)

<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8Xj6YfMRKw8XnmTA1ohBr6K)_

Fixes objectstack-ai#38537

Clause-②: no
Metadata-protocol: none

**Lands after objectstack-ai#38594** (merged 2026-11-30T01:10Z; main merged into this
branch at `d1e1ba3f03`). Both PRs are seat 2's. The overlap is two files
(`packages/lint/src/index.ts`,
`packages/lint/src/rule-explanations.ts`), in hunks far apart;
`overlap-check` reads both clean against each other and main.

## 维护者速读

- 用户能看到什么变化:知识源的“文档单位”(`documentBy`)如果填的不是指向父记录的单值查找字段,`os validate` /
`os build` / `os lint` 和发布时都会报错并说明怎么改。之前只有在 Studio / 元数据 API 保存时才会拒绝。
- 为什么做:随包发布或代码注册的知识源不经过保存这道门,填错了没人拦,检索按父记录聚合会悄悄失效。这是 objectstack-ai#38537 的第二个也是最后一个
PR。
- 出错会怎样:只影响声明了 `documentBy` 的知识源;规则误判会让正确的知识源发布失败,删掉 `documentBy` 即可绕开。
- 要你做什么:无。

## What changes

- **New rule** `knowledge-source-document-by-not-parent-link` (`error`)
in `validate-knowledge-source.ts`. It refuses a `source.documentBy` that
`metadataFields` lists and that is not a single-valued parent link of
the indexed object. The checks run in the save door's order: declared by
the object, neither credential-class nor `internal`, a `lookup` /
`master_detail` type, a target `referenceTargetOf` can read, and not
`multiple: true`. Each reason gets its own message, worded like the save
door's `documentUnitRefusalText`, naming the field and the fix. Path:
`knowledgeSources[i].source.documentBy`.
- **Where it runs.** The rule rides the existing
`validateKnowledgeSource` registry entry, so it reaches `os validate` /
`build` / `lint` and the runtime publish gate (`knowledge_source`
writes) with no new wiring. This is what judges a source a package ships
or code registers; until now only the metadata API's save door did
(objectstack-ai#38564).
- **Not judged twice.** A `documentBy` that `metadataFields` does not
list is left to the parse, which already names that fix. A member the
object does not have is reported once, as
`knowledge-source-field-unknown`. An object with no readable field map
is not judged.
- **Published and explained.** The rule id is re-exported from the root
barrel (`index.ts`, one line in the knowledge block).
`rule-explanations.ts` gets its `os explain` entry and table row beside
the five sibling rules.
- **Census pin**
(`packages/core/src/security/second-object-read-exposure.pin.test.ts`):
the new `referenceTargetOf` import makes `validate-knowledge-source.ts`
a caller of the reference-target arbiter, so it is classified
`not-a-served-read` beside the other lint callers. It only asks whether
a target is declared, and reads and serves nothing of the target.
Admitted by the seat for this fix after CI's Test Core (8/12) flagged
the unclassified caller. Locally: 1 failed / 3 passed before the entry,
4/4 after.
- **Changeset** `patch` for `@objectstack/lint`.

## Route chosen for the parent-link rule (objectstack-ai#38564's PR 2 question)

objectstack-ai#38564 left PR 2 two ways to reach `parentLinkRule` / `documentUnitOf`
(`service-knowledge`'s `knowledge-search-scope.ts`). The seat accepted a
third:

- **A: lint imports `@objectstack/service-knowledge`.** Not taken.
`@objectstack/lint`'s package description says it "Depends on
@objectstack/spec; never on a runtime", and service-knowledge is a
runtime service. It would also need a new line on service-knowledge's
`exports` surface.
- **B: move the rule to "a package lint already reads, for example
`@objectstack/core`".** Not taken. Lint does not depend on
`@objectstack/core`; its workspace dependencies are `formula`,
`metadata-core`, `sdui-parser` and `spec`. Moving it to `spec` would put
runtime-shaped logic into the protocol package and widen this PR well
past its card.
- **C (taken): compose the verdict in lint from the spec predicates
`parentLinkRule` itself asks.** Withheld =
`isMaskedOnReadFieldType(type, managedBy)` or `internal === true`. That
is the reading this file already takes for
`knowledge-source-field-never-indexed`, and the one
`collectCredentialWriteResponseFields` /
`collectInternalWriteResponseFields` compute in core. Target =
`referenceTargetOf` (`@objectstack/spec/data`). The type pair `lookup` /
`master_detail` is spelled locally, as eight other lint rule files
already spell it. Cost: the four-part rule now lives in two places. No
test pins their agreement, because no package that depends on both can
import `documentUnitOf` without one more barrel line in
service-knowledge. The module header names the save door's function so a
change to one points at the other.

## Why

ADR-0161 K4: "a packaged item meets the gates that need no principal in
`os validate` and at publish". `documentBy` is such a gate: it reads
only the object definition. objectstack-ai#38564 left it judged at save only, and its
body says "PR 2's `os validate` rule covers packaged sources."

## Clause-② and Metadata-protocol, measured from the diff

`Clause-②: no` / `Metadata-protocol: none`, a judgement call stated here
for review. The rule refuses values of `source.documentBy`, a key objectstack-ai#38564
added in this same prerelease line. Its changeset
`.changeset/38537-knowledge-document-by.md` is still pending (not moved
to `.changeset/pre/`), so no published version carries the key and
nothing an author could write against a release is refused. The metadata
API's save door already refuses the same values. Read against `main`
instead, a packaged source with a non-parent-link `documentBy` passed
`os validate` before this PR and fails it after. If review prefers that
reading, the lines become `Clause-②: no (narrowing)` /
`Metadata-protocol: narrowed` (level `minor` and an ADR-0087
disposition).

## Verification

### Acceptance (the card's `os validate` half)

| Card line | Test (`validate-knowledge-source.document-by.test.ts`) |
|:--|:--|
| Refuse a text field, a `user` field, an `internal` lookup and a
`multiple` lookup, each naming the fix | "refuses a text field / a user
field / an internal lookup / a multiple lookup as the document unit,
naming the field and the fix" |
| (the save door's other reasons) | "… a credential-class field", "… a
lookup with no readable target", "… a system column the platform adds" |
| Positive controls | "CONTROL: a lookup and a master_detail to the
parent are admitted", "CONTROL: a source without documentBy is judged as
before" |
| Same verdict at publish | "refuses the publish with the words os
validate prints", "CONTROL: a single-valued parent link publishes with
nothing to report" |
| Published id + `os explain` | "the root barrel re-exports it", "os
explain answers it" |

### Ablation (`scripts/ablation-replace.mjs`, each mutation verified on
disk, each restore verified blob == HEAD `d9f63681062f` with an empty
`git diff HEAD`)

<details><summary>Call site disabled (<code>const refusal =
documentUnitRefusal(…)</code> → <code>undefined</code>): 9 red</summary>

`validate-knowledge-source.document-by.test.ts`: 9 failed / 8 passed.
All seven refusal tests, "a fields array is read like a field map", and
"refuses the publish with the words os validate prints". The controls
stay green.
</details>

<details><summary><code>multiple</code> arm deleted: 1 red</summary>

1 failed / 16 passed: "refuses a multiple lookup as the document unit…".
</details>

<details><summary><code>internal</code> half of the withheld arm
removed: 1 red</summary>

1 failed / 16 passed: "refuses an internal lookup as the document
unit…". (A first attempt was refused by the tool before running
anything, because its replacement text already occurred in the file; it
was re-run with a distinct replacement.)
</details>

### Package suite and typecheck

- `pnpm --filter @objectstack/lint test`: Test Files 248 passed (248),
Tests 9989 passed / 5 skipped. Exit 0.
- `pnpm --filter @objectstack/lint typecheck` (tsc + test layer): exit
0.
- `eslint` on the four changed source files: exit 0.
- `overlap-check`: VERDICT clean exit 0. origin/main merges cleanly, and
so do the 7 open PRs sharing a file (objectstack-ai#38651, objectstack-ai#38650, objectstack-ai#38643, objectstack-ai#38605,
objectstack-ai#38594, objectstack-ai#38550, objectstack-ai#38497).

### Derived gate families (`dispatch-gates.mjs --commands`, 70)

- First pass, captured per the tool's idiom: `--ran` reports "70 derived
famil(ies) accounted for — 66 run, 4 NOT-MEASURED (4 DERIVED from a
recorded exit 3)". All 66 that ran exited 0, including
`check-changeset-no-major --base origin/main`,
`check-adr-0087-registration --base origin/main`, `check:doc-authoring`,
`check:issue-citations` and `check:cross-package-test-inputs`.
- The four exit-3 families each had a prerequisite missing. Three were
re-run after fixing it, each exit 0: `check-plugin-teardown-shape
--self-test` (needed `git fetch --unshallow`),
`check:docs-transcript-drift` (needed the built lint) and
`check:lean-entry-closure` (needed the built objectql). These re-runs
were by hand, outside the `--ran` record.
- `check:dual-build-cjs-loads` was not measured locally: it reads every
package's `dist/`, which needs a full build. CI's `Build Core` job runs
it on this PR.

## Human Minimum

- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(spec untouched)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes (eslint on the changed
files).
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: n/a.
- [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 (the 维护者速读 block is the
maintainer's Chinese brief).
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.

## Read first

1. `packages/lint/src/validate-knowledge-source.ts`:
`documentUnitRefusal` and the call site after
`judgeMembers('metadataFields')`.
2. `packages/services/service-knowledge/src/knowledge-search-scope.ts`:
`parentLinkRule` / `documentUnitOf`, the save door's rule this one
restates.

**Two-minute check:** `pnpm --filter @objectstack/lint exec vitest run
src/validate-knowledge-source.document-by.test.ts`. Expect 17 passed.

Dogfood: n/a (no `!` in the title, no `(narrowing)` arm).

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

https://claude.ai/code/session_01JQwxbWsSJprjGydwaCH1gD

<!-- signed: repo:objectstack#2 · os-warren ·
session_01JQwxbWsSJprjGydwaCH1gD -->

---------

Co-authored-by: Claude <noreply@anthropic.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/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

3 participants