Skip to content

fix(lint): the record-write-discarded hint prescribes a write the sandbox installs; app-dependencies lists the closure-judged bindings - #38628

Merged
objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/issue-37815-updatebyid-hint-doc-row
Nov 29, 2026
Merged

objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/issue-37815-updatebyid-hint-doc-row

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Steve · project thread
Refs #37815 (items c, d)
Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:应用作者在构建检查里看到的「记录改动被丢弃」提示,现在给出一种在沙箱里真能运行的写法;应用依赖文档补上了保存时按依赖关系判定的完整绑定清单。
  • 为什么做:原提示让作者照抄一个沙箱里根本不存在的方法,照做后动作第一次运行就报错;属于脚本动作写入的检查跟进工作。
  • 出错会怎样:只改提示文字和文档,检查结论不变,不影响任何已保存的应用;有问题可直接撤回。
  • 要你做什么:无。

What changes

  • Item (c), the action-record-write-discarded hint. It prescribed ctx.api.object('OBJECT').updateById(ctx.recordId, { … }). Probed for real (below): a sandboxed action body or hook body has no updateById on ctx.api.object(…), so following the hint throws TypeError: not a function and writes nothing. The hint now prescribes ctx.api.object('OBJECT').update({ id: ctx.recordId, FIELD: … }), the single-record form the sandbox installs and HookObjectApi.update documents (the id travels inside the payload). The method name lives in one constant, ACTION_RECORD_WRITE_REMEDY_METHOD (not re-exported from the package index), pinned to SANDBOX_API_WRITE_METHODS, which is itself pinned to the runner's WRITE list.
  • The os explain action-body-write-unknown-field text said an action body persists "only through insert / create / update / updateById". create and updateById are not installed in the sandbox either. It now names insert({ … }) and update({ id, … }). Same defect class, same file, bounded fix.
  • Item (d), content/docs/deployment/app-dependencies.mdx. The page said the save door judges "a list view" against the package closure. It now has a table of the bindings that door judges, including the two that PR fix(lint)!: three publish-time checks for seeds, flow nodes and actions that save and do not work #37807 added: a standalone action's objectName and a flow get_record / create_record / update_record / delete_record / object-form screen node's objectName. Sources: validateObjectReferences runs on the flow, dataset and action runtime doors (packages/lint/src/reference-integrity-suite.ts, member runtimeTypes: ['flow', 'dataset', 'action'], handed ctx.packageScope), and the flow-node and action sites are in packages/lint/src/validate-object-references.ts (OBJECT_BOUND_FLOW_NODE_TYPES, actions[i].objectName). The form and knowledge-source rows come from form-object-outside-closure (validate-form-items.ts) and knowledge-source-object-unknown (validate-knowledge-source.ts). The table says "include" because other closure-aware rules exist (email template holes, AI tool and context references) that this PR did not audit.
  • What lint judges is unchanged: an updateById payload in a body is still graded (API_WRITE_METHODS, the ledger's api-crud-literal syntax line and example, and the explanations that say what is judged), because a body can still contain the call.
  • The ADR-0141 D1 note is not in this diff. It goes to the weekly ADR revisions card.

Tests

  • validate-action-body-writes.test.ts: the existing case that pinned hint to contain updateById now pins the remedy method. A new case asserts the method the hint calls is in SANDBOX_API_WRITE_METHODS and that the payload is addressed by id: ctx.recordId. Subjects, not prose.
  • Ablation (hint put back to updateById(ctx.recordId, …) via scripts/ablation-replace.mjs, anchor 1 to 0, blob 262ceea2 to a2f3f908): 2 cases red (expected [ 'updateById' ] to deeply equal [ 'update' ]), 50 passed. Restored: git diff HEAD empty, 0 hits of the mutation.
Sandbox probe (throwaway test, not committed): real ObjectQL, real better-sqlite3 SqlDriver, real QuickJSScriptRunner and body-runner factories
PROBE ACTION updateById (old hint) :: {"err":{"name":"SandboxError","message":"action 'close_deal' threw: TypeError: not a function","inner":"TypeError: not a function"}} :: stage after = open
PROBE ACTION update({ id }) (new hint) :: {"ok":"ok"} :: stage after = won
PROBE ACTION typeof updateById :: {"ok":"undefined"} :: stage after = open
PROBE HOOK updateById :: {"err":{"name":"SandboxError","message":"hook 'note_closes_deal' threw: TypeError: not a function"}} :: stage after = open
PROBE HOOK update({ id }) :: {"ok":true} :: stage after = won
 Test Files  1 passed (1)
      Tests  5 passed (5)

Hook bodies run in the same sandbox and fail the same way.

Local runs (head c2b9cff)
  • pnpm --filter @objectstack/lint exec vitest run --maxWorkers=2 (the whole package) at c2b9cff: lock VERDICT command-exit 0, Test Files 246 passed (246), Tests 9959 passed (9959). The first whole-package run, at 0dfeeda, had 1 red in rule-id-barrel-exports.test.ts: it reads an unannotated exported string constant as a rule id. The constant is now annotated string (second commit).
  • pnpm --filter @objectstack/lint typecheck: VERDICT command-exit 0.
  • eslint on the three edited lint files: exit 0.
  • dispatch-gates.mjs --commands derived 100 families; all 100 run locally: 97 exit 0; 3 exit 3 PREREQUISITE NOT MET, so NOT MEASURED here and left to CI (check-plugin-teardown-shape --self-test needs an unshallow clone; spec check:skill-examples and check:dual-build-cjs-loads need packages this worktree did not build). None of the three reads a file this PR changes. --ran reconciliation: 100 derived, 100 run, 0 UNRUN. Re-run on c2b9cff after the second commit: check:doc-authoring, check:issue-citations, check:nul-bytes, check:adr-anchors, check:cross-package-test-inputs, check:undeclared-dep-imports, check:type-check-debt, check:closed-ceremony-text, all exit 0.
  • test:repo not run locally (CI's Test Core).

Acceptance notes

  • Not fixed here, reported for filing (outside this PR's file surface): content/docs/automation/hook-bodies.mdx (the "exactly one way an action body persists anything" snippet) still teaches updateById(ctx.recordId, …) in an action body. The spec contract (HookObjectApi.updateById in packages/spec/src/data/hook-api.ts, IScopedObjectRepository.updateById) declares the member a body cannot call, and objectstack build does not refuse .updateById( at lowering the way it refuses .create(. Whether the sandbox should install the leaf or the body-facing contract should drop it is a decision; it is raised in the report.
  • The hook ledger's api-crud-literal syntax line and example still name updateById: they mirror the extractor's graded verbs (validate-readonly-hook-writes.test.ts reads the syntax line as that mirror) and are not shown to authors.

Verification

Read first: packages/lint/src/validate-action-body-writes.ts (the hint and ACTION_RECORD_WRITE_REMEDY_METHOD), then the new test case, then the docs table.

Two-minute check: pnpm --filter @objectstack/lint exec vitest run src/validate-action-body-writes.test.ts shows all cases passing, and the prescribes a write the sandbox installs case among them.


Generated by Claude Code

🤖 Generated with Claude Code

https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B

… id, … }), a write the sandbox installs

Claude-Session: https://claude.ai/code/session_01ADHkmSwS4mQyXWrddL4r6B
Co-authored-by: Claude <noreply@anthropic.com>
…does not read it as a rule id

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

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

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

What this run could not see
  • 1 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 — 4 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 eec2bc3e3a0ec0dda41ab73d73cda4a71d37d32a → packageMentionDocs.

Which tree this was computed on

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

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

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

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSwS4mQyXWrddL4r6B

Final green head · 2026-11-29T16:37Z · zone o3-B · c2b9cffb57c128e3922f52b1b9cd4345ee277c0b · check-runs 62 success · 10 expected skip · 0 failed · 0 pending; mergeable_state clean. Sent to L1-a for the first review (82 changed lines with a code change). Body line Refs #37815 (items c, d): on merge the card is released back to pm:queue for items (a) and (b); the updateById root question is #38630.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmQm8PTU4AkVU5kdwEv

L1-a, the seat's L1 thread · 2026-11-29T16:41Z · first review

席位核对

ACCEPT @ c2b9cffb57c128e3922f52b1b9cd4345ee277c0b (card #37815, items (c) and (d) only, zone o3-B). No L2 is owed: no packages/spec/src/**, no governed path, Clause-②: no, Metadata-protocol: none. Not governed, 82 lines: the zone lands it.

Read at this head

  • Shape (l1-face.mjs --pr 38628, clean): draft, base main, no closing keyword binds any card, no content/docs/releases/ path, the @objectstack/lint changeset is present, no +0/-0 file, mergeable_state clean. Assigned to os-steve.
  • Relation: Refs #37815 (items c, d) is right. The PR delivers two of the card's four items. That is the partial-delivery spelling execution-duties.md names, and merging does not close the card.
  • Item (c), the probe. The sandbox probe uses real ObjectQL, better-sqlite3 and QuickJSScriptRunner through the action and hook body runner factories. updateById throws TypeError: not a function and leaves the row open. typeof … updateById is undefined. update({ id }) moves the row to won, in both an action body and a hook body. This is a positive control (old hint red, new hint green) on the real runner, so the premise and the fix are measured rather than read.
  • Item (c), the fix. The hint now prescribes .update({ id: ctx.recordId, FIELD: … }) through ACTION_RECORD_WRITE_REMEDY_METHOD. A test pins it into SANDBOX_API_WRITE_METHODS, which is pinned to the runner's WRITE list. The new case reads the called member out of the hint and asserts the id: ctx.recordId address: those are subjects, not prose. The string annotation that keeps the rule-id census from reading the constant as a rule id is explained in place. The constant is not re-exported from the index.
  • Ablation. With the hint put back to updateById(…): 2 red, 50 passed. The source was then restored (git diff HEAD empty).
  • Bounded adjacent fix accepted. In rule-explanations.ts:1425, the action-body-write-unknown-field explanation dropped create and updateById. It is the same defect class, in the same file and inside the claim's surface (rule-explanations.ts, hint and explanation text), and the PR body names it.
  • content/docs/deployment/app-dependencies.mdx, read sentence by sentence: true at this head. Each table row is checked against a closure-judged rule on the save door:
    • The flow, dataset and standalone action rows: validateObjectReferences, runtimeTypes: ['flow', 'dataset', 'action'] with packageScope (reference-integrity-suite.ts:266). The flow nodes come from OBJECT_BOUND_FLOW_NODE_TYPES (the four CRUD types and screen) through walkFlowNodes, so nested nodes are included.
    • The list view row: validateListViewFieldRefs with packageScope.
    • The form row: form-object-outside-closure, judged "where a list view's object is judged", whose hint is to declare the dependency.
    • The knowledge source row: validateKnowledgeSource, runtimeTypes: ['knowledge_source'], with packageScope and closureDependencyRemedy.
    • The flow trigger row: validate-flow-trigger-readiness.ts, which prints the same remedy.
    • "Include" is honest: the email-template and AI-context rules also read the closure and are not listed.
  • Changeset, read sentence by sentence: true at this head. It gives the new hint text and the old one, says the sandbox installs no updateById (the probe), says the explanation no longer lists create / updateById, and says the grading is unchanged (API_WRITE_METHODS still maps updateById).
  • Checks at this head (check-runs via pr-state): 62 success, 10 expected skip, 0 unexpected skip, 0 failed, 0 pending. Lint & Repo Gates and TypeScript Type Check are success. The whole lint package ran at c2b9cffb5: 246 files, 9959 tests, lock VERDICT exit 0. Of the 3 local NOT MEASURED results, CI covers each.

Out of scope

Nit, not blocking

  • The new action explanation lists insert({ … }) and .update({ id, … }). The sandbox also installs upsert, updateMany, delete and deleteMany. "Only through ctx.api" remains the true claim, and the two calls read as examples.

Landing note

Refs, so the card stays open. Items (a) and (b) remain, so at merge the card's partial-delivery step applies (Release: naming (c) and (d) as landed and (a) and (b) as remaining, per execution-duties.md). Alternatively, the seat hands (a) and (b) to its card thread as the claim says.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-steve · session_01ADHkmSwS4mQyXWrddL4r6B

Landing · 2026-11-29T16:42Z · zone o3-B · head c2b9cffb57c128e3922f52b1b9cd4345ee277c0b · ACCEPT → PR #38628 comment 7259109775 (L1-a)

Reading Value
check-runs at head (pr-state) 62 success · 10 expected skip · 0 unexpected skip · 0 failed · 0 pending; mergeable_state clean
check-governed-merges --pr 38628 · K NOT governed, 82 changed lines (+71 / -11) · landing-k OK, K = 1 < 15, no shared book moved

State: ready for review + auto-merge in this stroke. Body says Refs #37815 (items c, d), so the card stays open; on merge it is released back to pm:queue with items (a) and (b) remaining. L1-a's non-blocking nit (the new action explanation names only insert/update while the sandbox also installs upsert/updateMany) goes to the card's remaining items, not this PR.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 29, 2026 16:43
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 29, 2026
Merged via the queue into main with commit cb99e2d Nov 29, 2026
73 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-37815-updatebyid-hint-doc-row branch November 29, 2026 17:12
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…the engine accepts it (objectstack-ai#38635)

<!-- 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#38433 (items 1, 2)
Clause-②: no
Metadata-protocol: none

## 维护者速读

- 作者与智能体在校验或保存看板视图时看到的修复建议变了:分组字段是多值、JSON
存储或公式字段时,不再建议改用表格分组,而是建议改用表格列;普通文本、数字、日期字段的建议不变。
- 属于看板分组字段校验规则的复核跟进:原建议会把作者引到一个打开即报错的表格分组。
- 只是提示文字和规则说明变了,不改任何校验结论或严重级别;出错时作者只会读到不准确的建议,可直接撤回。
- 无。

## What changes

`list-view-kanban-group-field-uncategorical` now offers the
grid-grouping remedy only on the branch where it holds.

- **Hint** (`checkKanbanGroupField`,
`packages/lint/src/validate-list-view-field-refs.ts`): the tail is keyed
on the engine's own refusal set, read from the same spec predicates the
two `engine.aggregate` doors use:
- multi-valued (`isMultiValueField`, the multi branch) and
structured-JSON (`STRUCTURED_JSON_TYPES`) are refused by
`assertGroupByNamesNoJsonStoredField`;
- virtual `formula` (`isVirtualSearchField`) is refused by
`assertGroupByTargetsAreStored`;
- both answer `400 INVALID_FIELD`. A list view `grouping` compiles to
that group-header query (`compileListViewGroupQuery`), which the grid
sends.
- For those three classes the hint now ends `or show "FIELD" as a grid
column (a list cannot be grouped by REASON)`; every other warned field
(text, number, date and the rest of the stored single-valued scalars)
keeps `or show "FIELD" as a grid grouping`.
- **Explanation** (`rule-explanations.ts`, this rule's entry only): the
fix paragraph now says the same, branch by branch: stored single-valued
field gives grid grouping; multi-valued, JSON-stored or `formula` gives
grid column only, with the reason.
- Measured from the rule's code: before this PR a JSON-stored or
`formula` group field already warned, on the **single-valued** branch
(it is not in `KANBAN_CATEGORICAL_TYPES`), and got the grid-grouping
tail. No finding, severity or accept set changes.
- **N2 (item 4), decided: keep the short list deliberately.** `select`,
boolean and lookup are the heads of the three families the rule accepts
(`select`/`radio`, `BOOLEAN_VALUE_TYPES`, `REFERENCE_VALUE_TYPES`).
Naming each member would hand-copy `KANBAN_CATEGORICAL_TYPES` into prose
that drifts from it, and would lengthen a hint held to 200 characters.

Read first, by risk:
1. `packages/lint/src/validate-list-view-field-refs.ts`, the
`ungroupable` / `gridRemedy` hunk in `checkKanbanGroupField`: this is
where the set is keyed.
2. `packages/lint/src/validate-list-view-kanban-lanes.test.ts`, the new
per-field `it.each`.

Two-minute check: `pnpm --filter @objectstack/lint exec vitest run
--maxWorkers=2 src/validate-list-view-kanban-lanes.test.ts`. Expect 34
passed. The `tags`, `watchers`, `meta`, `address` and `score` rows
assert a grid column; `amount`, `due_date` and `subject` assert a grid
grouping.

## Tests

At head `e0e643722a`:

<details><summary>@objectstack/lint: full suite and typecheck</summary>

- `pnpm --filter @objectstack/lint exec vitest run --maxWorkers=2`: Test
Files 246 passed (246), Tests 9962 passed, 5 skipped (9967).
- `pnpm --filter @objectstack/lint typecheck`: exit 0;
check:test-typecheck OK.
- `src/validate-list-view-kanban-lanes.test.ts`: 34 passed.

</details>

<details><summary>Ablation</summary>

Forced `gridRemedy` to always take the grid-grouping arm, on disk, then
ran the target file: 5 failed / 29 passed. The failures were exactly the
five ungroupable rows (`tags`, `watchers`, `meta`, `address`, `score`).
Restored with `git checkout HEAD --`, tree clean.

</details>

## Acceptance notes

- Item 3 of the card (a finding of its own for a
`grouping.fields[].field` naming a multi-value, JSON-stored or
non-stored field) is not in this PR. It is a narrowing and stays on the
card.
- `engine.aggregate` also refuses a `groupBy` on a credential or
`internal`-flagged column (`rejectCredentialEvaluation`,
`rejectInternalFieldEvaluation`). The hint is not keyed on those,
because the refusal comes from a flag and not from the storage class. A
kanban board grouped by a password field is not a realistic producer.
Noted only.

## Verification

<details><summary>Derived local gates (dispatch-gates --commands, 70
families)</summary>

- `dispatch-gates --ran`: 70 derived, 67 run with exit 0, 3 NOT MEASURED
(exit 3, prerequisite), 0 unrun.
- NOT MEASURED: `check-plugin-teardown-shape --self-test` (shallow clone
cannot reach its pinned fixture commit), `check:dual-build-cjs-loads`
and `check:lean-entry-closure` (need dist of packages outside this
diff's closure). Left to CI.
- `check:docs-transcript-drift` was re-run after building
`@objectstack/lint`: exit 0. `check:type-check-debt` and
`check:query-options-erasure`: exit 0.
- `overlap-check --branch=HEAD`: clean against origin/main and objectstack-ai#38628,
objectstack-ai#38605, objectstack-ai#38594, objectstack-ai#38550.

</details>

---
_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
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants