Repository navigation
Commit 743308b
fix(lint, runtime)!: an action body that cannot compile in its (input, ctx) wrapper is refused at validate, build and publish, and at run time answers naming itself (#34980)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBLW6dHPW6sSheA32XPKZzPV)_
repo:objectstack#3 · os-support-ai · session_01WGufziunkXbDT7wUWqfmWz
Fixes #34884
Clause-②: no (narrowing) — an L2 action body (`type: 'script'`,
`body.language: 'js'`) that does not compile as the body of `(async
(input, ctx) => { … })` passed `os validate`, `os build`, `os lint`, `os
verify` and the runtime publish door; it is now refused there as
`action-body-does-not-compile` at `error` (on the publish door for
`action` writes and for `object` writes carrying inline `actions[]`).
One arm advises instead of refusing: a regular-expression literal the
host engine refuses is a `warning`. Such a body never ran: every run
failed with a SyntaxError before its first statement.
`@objectstack/lint` also gains exports (`validateActionBodyCompiles`,
`hostCompileFailure`, `ACTION_BODY_DOES_NOT_COMPILE`,
`ACTION_BODY_PARAMETERS`, `actionBodyFunctionExpression` and two finding
types on `.`, `actionBodyFunctionExpression` on `./runtime`).
Metadata-protocol: narrowed
Skills-docs: follow-up owed —
skills/objectstack-data/references/data-hooks.md (it teaches the action
wrap `(async (input, ctx) => { … })` without saying a body must not
declare `input` / `ctx` again); follow-up #34988 (blocked on #34504,
which holds that file); this PR teaches it in
`content/docs/ui/actions.mdx` and
`content/docs/automation/hook-bodies.mdx`.
## 维护者速读
- 改了什么:脚本动作的 `body.source` 如果在运行时的包装 `(async (input, ctx) => { … })`
里编译不过(最常见是 `const input = ctx.input || {}` 重复声明参数),现在 `os validate` /
`os build` / `os lint` /
发布保存(动作写入和对象写入)都会报错拒绝,点名动作、编译错误和行号;运行时若仍遇到这种动作,REST `/actions` 与 MCP
`run_action` 回答 `500 INTERNAL_ERROR`,消息点名动作和编译错误,不再是光秃秃的 "Internal
server error"。
- 为什么改:这种动作以前四道门全过,部署后每次运行都失败,调用方(尤其 AI)只看到不透明的 500,只好绕开去直接写数据,把状态弄错。
- 风险与回滚:新拒绝的只有本来就永远跑不起来的动作体;检查用宿主 JS 引擎(Node 的 V8)编译、不执行,与运行时 QuickJS
唯一实测分歧在正则字面量,那一支只给警告不拒绝。四个示例应用实测 0 处命中,全量 dogfood 绿。回滚即 revert。
-
先看:`packages/lint/src/validate-action-body-compiles.ts`(编译方式与正则分支);`packages/runtime/src/sandbox/quickjs-runner.ts`(`actionBodyCompileFailure`
与包装改用共享函数);`packages/lint/src/authoring-rules.ts`(注册:门禁级、发布门 `action` +
`object`)。;`packages/spec/src/migrations/entries/semantic/18.action-body-does-not-compile-refused.ts`(ADR-0087
语义迁移条目,升级指南与 `os migrate meta` 读它)。
- 两分钟验证:`pnpm --filter @objectstack/lint exec vitest run
src/validate-action-body-compiles.test.ts`,预期 14 条全过,其中含卡里那句原样的动作体被拒。
- 需要你做的:无,席位落地(收窄需一次契约级审查,由席位安排)。
## What changes
- **Author time (`@objectstack/lint`)** — new gating rule
`action-body-does-not-compile` (`validate-action-body-compiles.ts`). It
compiles each L2 action body inside
`actionBodyFunctionExpression(source)`, the wrapper the runtime builds,
from the same function, with the host engine, as a script, never running
it (`node:vm` `Script`; the `Function` constructor where `node:vm` is
absent; no verdict where the host refuses to compile at all). The
finding names the action, the compiler's sentence and the line of
`body.source`; a redeclared wrapper parameter gets a hint naming it.
Registered in `authoring-rules.ts` as `gating` on all three commands and
on the runtime publish door for `action` and `object` writes; `os
explain action-body-does-not-compile` added; barrel exports added. The
object door's roster pin in `runtime-gate.object-writes.test.ts` names
the join.
- **The shared wrapper** — `packages/lint/src/action-body-wrapper.ts`
holds the one spelling, `(async (input, ctx) => { SOURCE })`.
`quickjs-runner.ts` now builds its action wrapper from it through
`@objectstack/lint/runtime` (the runtime already depends on that entry);
the wrapper text is byte-identical to before.
- **Run time (`@objectstack/runtime`)** — when evaluating an action's
wrapper fails with a `SyntaxError` (a compile failure: an async body
cannot throw synchronously, so anything the body itself throws crosses
`__error` instead), the runner throws a `SandboxError` with `status:
500`, no code, the operator line `action 'NAME' does not compile:
SyntaxError: …` and the caller sentence `Action 'NAME' cannot run: its
body does not compile (SyntaxError: …). The action's author must fix its
body.source and publish it again.` The doors answer the status's own
`INTERNAL_ERROR` and relay that sentence. A crash while running (a
`TypeError`, a `SyntaxError` thrown by `JSON.parse`) keeps the sanitised
500. Hook and job bodies are unchanged.
- **Protocol (`@objectstack/spec`)** — the ADR-0087 semantic entry
`packages/spec/src/migrations/entries/semantic/18.action-body-does-not-compile-refused.ts`
(`action-body-does-not-compile-refused`: surface, replacement, reason,
acceptance criteria) registers the narrowing for the upgrade guide and
`os migrate meta`; the generated registry picks it up, no other spec
file changes. The changeset declares `Metadata-protocol: narrowed`,
carries `adr-0087: registered action-body-does-not-compile-refused`, and
grades `@objectstack/lint` and `@objectstack/spec` `minor`,
`@objectstack/runtime` `patch`.
- **Docs** — `content/docs/automation/hook-bodies.mdx` and
`content/docs/ui/actions.mdx` teach the rule;
`content/docs/api/error-catalog.mdx` gains the Action Errors row; the
author-time rule count the CLI prints goes 70 to 71 in the four
transcript pages. `content/docs/deployment/validating-metadata.mdx`
gains the rule's row in the four-doors table (`✓ ✓ ✓ ✓ᵃᶜᵒ`: the three
commands, and the publish door for `action` and `object` writes).
## Tests
- `packages/lint/src/validate-action-body-compiles.test.ts` (14): the
card's body byte for byte refused (`error`, path, `'input'`, line 1,
parameter hint); the same source compiling in the parse check's own
wrapper (why no check saw it); `let ctx` on line 3; an unparseable body;
`new.target`; four bodies that compile (`var input`, reading `input`, …)
admitted; the regex arm at `warning`; a body that closes the wrapper
early compiles and never executes; both registration sites, merged
action once, non-script and non-js skipped; `validate` / `build` /
`lint` each refuse; the `action` and `object` publish doors refuse and
admit; an unrelated write is not charged with a stored bad body.
-
`packages/runtime/src/sandbox/sandboxed-action-crash-is-a-fault.test.ts`,
new top-level describe (3): the real runner on the card's body (message,
`status: 500`, no code, sentence); the real `/actions` door answers `500
INTERNAL_ERROR` with the sentence, not `Internal server error`; control:
a runtime `SyntaxError` stays a sanitised crash.
- `packages/core/src/utils/import-runner-sandbox-fault-row.test.ts`
(round 2): the census that renders every `SandboxError` construction in
`quickjs-runner.ts` gains crash samples for the new site's two
interpolations, `actionName` and `compilerError`; the census is not
loosened, and the new site becomes one more §2 case (the door withholds
a sandbox fault's text, the import row reads the door's sentence). Red
before on `bc80b37795` (`quickjs-runner.ts:2407 (relayed): no sample for
the interpolation actionName`, 1 failed, 44 passed), green after (46
passed).
<details><summary>Live measurement before and after (scratch app, CLI
built from this tree)</summary>
Before (origin/main fff0ad0), action body `const input = ctx.input ||
{}; return 1;`:
- `os validate` exit 0, `os build` exit 0, `os verify` exit 0 ("verify
passed — no runtime failures").
- REST `POST /api/v1/actions/OBJ/ACTION/ID`: `500
{"code":"INTERNAL_ERROR","message":"Internal server error"}`.
- MCP `run_action`:
`{"error":{"code":"INTERNAL_ERROR","message":"Internal server
error","status":500}}`.
- `PUT /api/v1/meta/action/NAME` with that body: `200` saved active.
- Server log: `ERROR [BodyRunner] sandboxed action threw … action
'rpc_decide' threw: SyntaxError: invalid redefinition of parameter
name`, then `sandboxed body crashed: …`.
- First door that could see the error and did not: `os validate` (every
author-time door shares the registry).
After (this branch, the pre-fix artifact booted with `-a` to stand for a
body deployed before the rule):
- `os validate` / `os build` / `os verify` exit 1,
`action-body-does-not-compile` at `actions[0].body.source`
("SyntaxError: Identifier 'input' has already been declared, line 1").
- REST and MCP: `500 INTERNAL_ERROR`, message `Action 'rpc_decide'
cannot run: its body does not compile (SyntaxError: invalid redefinition
of parameter name). The action's author must fix its body.source and
publish it again.`
- `PUT /api/v1/meta/action/NAME`: `422 INVALID_METADATA` with the rule's
issue; a body using `const params = ctx.input || {}` saves `200`.
- Server log: `action 'rpc_decide' does not compile: SyntaxError:
invalid redefinition of parameter name`.
- Control action `return { ok: true }`: `200` both times.
</details>
<details><summary>Engine probe (36 bodies, Node 22 V8 vs the runtime's
QuickJS)</summary>
Agreed on every redeclaration, grammar error, strict-mode error, `super`
and `new.target` (with the wrapper compiled as a script). Disagreed
once: `/(?<a>x)|(?<a>y)/` (duplicate named groups) is refused by Node
22's V8 and accepted by QuickJS, hence the regex `warning` arm.
</details>
<details><summary>Ablations (each restored to blob == HEAD, `git diff
HEAD` empty)</summary>
- `validate-action-body-compiles.ts`: `if (!failure) continue;` → `if
(!failure || site) continue;` via `scripts/ablation-replace.mjs` (anchor
1 → 0, blob 9e2fd44 → 1f242fac955b): 9 of 14 red; restored
9e2fd44.
- `quickjs-runner.ts`: the compile-failure branch disabled (`&& !err`,
anchor 1 → 0, blob 571aa67 → a06de24caa83): the 2 compile-failure
pins red, the control and the 3 earlier cases green; restored
571aa67.
- Both test files import the code under test from `src/` (relative), so
no dist rebuild sits between the mutation and the run.
</details>
## Acceptance notes
- **Metadata-protocol: narrowed** (seat ruling 21:04Z on the round-1
question, option B; claim amendment on #34884): the semantic entry
above, in the precedent's shape
(`.changeset/34378-lookup-filter-record-path-multi-valued.md`,
`.changeset/33435-injected-column-null-guard-at-build.md`): BREAKING
scope, FROM → TO, Fix, measured first-party exposure (zero).
- **The object publish door runs the rule too** (`runtimeTypes:
['action', 'object']`, kept by the seat's ruling): an object write
carries inline `actions[]`, the second place a body is published, so an
object write cannot republish a refused body inline. The publish gate
charges a write with every non-compiling inline body the written object
carries, changed or not (only another entry's findings cancel), so an
object publish is refused while it still carries such a body, a body
stored before this rule included; a write of another object is not
charged with it (pinned). This is the surface the semantic entry
declares. The registration comment in `authoring-rules.ts` still says
"only the bodies it adds"; that sentence is left for a later touch of
the file (seat contract review 6964237524, N1).
- Hook and job bodies (`(async (ctx) => { … })`) are not judged and
their run-time answer is unchanged (seat ruling: they stay out of this
PR; follow-up #34987).
- No user-text catalog (`*.user-text.ts`) is authored for the new rule:
the publish door renders its `message`.
- Text conflict with open PR #34791 on the four rule-count transcript
lines (both bump 70 to 71); whichever lands second re-bumps. No overlap
with #34719's lines (`overlap-check`: merges cleanly).
## Verification
Head `15faf1da07` (round 2: `origin/main` merged twice, the spec entry,
the changeset rewrite, the docs row, the core census samples). Local
readings (CI runs the full farm):
<details><summary>Round 2 — spec, core census, docs</summary>
- `pnpm --filter @objectstack/spec gen:migration-registry` then `vitest
run src/migrations`: 5 files, 198 passed (the generated registry carries
`action-body-does-not-compile-refused` once).
- `pnpm --filter @objectstack/spec run check:generated` exit 0 (14
generated artifacts up to date); `check:adr-0087-registration --base
origin/main` exit 0 (`registered action-body-does-not-compile-refused
(new here)`); `check:changeset-no-major` exit 0; `check:issue-citations`
exit 0.
- `pnpm --filter @objectstack/core exec vitest run --project repo
src/utils/import-runner-sandbox-fault-row.test.ts`: before the samples
(on `bc80b37795`) VERDICT command-exit 1, 1 failed / 44 passed, the
census naming `quickjs-runner.ts:2407 (relayed): no sample for the
interpolation actionName`; after, VERDICT command-exit 0, 46 passed.
`pnpm --filter @objectstack/core run test:repo`: 8 files, 106 passed.
The other tests that read `quickjs-runner.ts` from disk or pin its arms:
`packages/rest` `error-response-sandbox-arm-message`,
`rest-sandbox-declared-status`, `rest-hook-script-fault-envelope` (3
files, 120 passed); `packages/core` `import-runner-sandbox-refusal-row`
(23 passed).
- `check:doc-authoring`, `check:docs-transcript-drift` (4 transcript
values), `check:doc-anchors` exit 0 after the `validating-metadata.mdx`
row.
</details>
<details><summary>Round 1 — package tests and typecheck (at
`f34867b93d`; round 2 changed no lint or runtime source)</summary>
- `pnpm --filter @objectstack/lint typecheck` exit 0; `pnpm --filter
@objectstack/lint exec vitest run`: 218 files, 9200 tests, 2 red in
`runtime-gate.object-writes.test.ts` (the object roster pins), fixed in
this PR; re-run of that file and the new file: 69 passed.
- `pnpm --filter @objectstack/runtime typecheck` exit 0; `vitest run
src/sandbox`: 47 files, 497 passed; the edited pin file: 6 passed.
- `packages/metadata-protocol` runtime-authoring-gate files: 13 files,
320 passed.
- Ablations as listed under Tests (round 2 adds a registry entry, a
changeset, a docs row and test samples: no tested behaviour changed, so
no new ablation).
</details>
<details><summary>Dogfood battery (owed by the narrowing arm) — on the
final head</summary>
At `15faf1da07`: packages and examples built under the lock (exit 0),
`pnpm --filter @objectstack/dogfood test`: VERDICT command-exit 0, Test
Files 479 passed | 3 skipped (482), Tests 4072 passed | 68 skipped
(4140). (Also green at `bc80b37795` with the same counts.)
</details>
<details><summary>Derived gates (`dispatch-gates --commands` at the
final head, 118 commands)</summary>
All 118 exit 0 at `15faf1da07`, after the full build, including
`check:type-check-debt` (0 ledger entries above their measurement),
`check:dts-closure`, `check:dual-build-cjs-loads`,
`check:test-source-alias`, the spec projections (`check:spec-changes`,
`check:upgrade-guide`, `check:api-surface`, `check:authorable-surface`)
and `check:kernel-hook-pairs`. `dispatch-gates --ran` with each exit
code recorded: 118 derived, 118 run, 0 NOT-MEASURED, 0 UNRUN (a derived
zero). `overlap-check`: `origin/main` merges cleanly; text conflict with
#34791 only, on the rule-count transcript lines and the
`validating-metadata.mdx` table (left for whichever lands second).
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufziunkXbDT7wUWqfmWz)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01WGufziunkXbDT7wUWqfmWz
<!-- signed: repo:objectstack#3 · os-support-ai ·
session_01WGufziunkXbDT7wUWqfmWz -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 367e324 commit 743308b
20 files changed
Lines changed: 605 additions & 6 deletions
File tree
- .changeset
- content/docs
- api
- automation
- deployment
- getting-started
- ui
- packages
- core/src/utils
- lint/src
- runtime/src/sandbox
- spec/src/migrations/entries/semantic
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
709 | 709 | | |
710 | 710 | | |
711 | 711 | | |
| 712 | + | |
712 | 713 | | |
713 | 714 | | |
714 | 715 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
| 230 | + | |
230 | 231 | | |
231 | 232 | | |
232 | 233 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
887 | 887 | | |
888 | 888 | | |
889 | 889 | | |
890 | | - | |
| 890 | + | |
891 | 891 | | |
892 | 892 | | |
893 | 893 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
519 | 519 | | |
520 | 520 | | |
521 | 521 | | |
| 522 | + | |
522 | 523 | | |
523 | 524 | | |
524 | 525 | | |
| |||
865 | 866 | | |
866 | 867 | | |
867 | 868 | | |
868 | | - | |
| 869 | + | |
869 | 870 | | |
870 | 871 | | |
871 | 872 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
314 | | - | |
| 314 | + | |
315 | 315 | | |
316 | 316 | | |
317 | 317 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
76 | 79 | | |
77 | 80 | | |
78 | 81 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
407 | | - | |
| 407 | + | |
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
125 | 129 | | |
126 | 130 | | |
127 | 131 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
0 commit comments