Repository navigation
Commit 961f474
fix(runtime): an action body that runs out of time answers a sentence naming the action and its limit (#35093)
<!-- 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 #35027
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:动作脚本超时(CPU 时限,或等待平台调用超过墙钟上限)时,REST `/actions` 与 MCP `run_action`
仍回答 `500 INTERNAL_ERROR`,但消息从光秃秃的 "Internal server error"
变成点名动作和时限的一句话,例如 `Action 'X' timed out: it exceeded its 50 ms time limit
and was stopped.`
- 为什么改:按裁决 C(「35027 C」,记录 6965765884)。调用方(尤其 MCP 里的
AI)以前分不清"这个动作慢"和"平台坏了"。状态码与错误码不变,只换句子;句子只含动作名和毫秒数,不含任何数据。
- 风险与回滚:只动 `budgetError` 的动作分支;钩子、定时任务的超时完全不变(无 `innerMessage`、无
`status`),崩溃仍是消毒后的 500。句子声明为 500,所以 `/data` 门不会把它当业务原文转出。第 3 轮修了合同审查的
F1:声明了 `refusals` 的动作以前会把这句话(以及编译失败那句)当成"没带 code 的抛出"改写成裸
500,日志也记错原因;现在运行器按身份标记自己的故障,拒绝目录直接放行。动作自己抛的无 code 错误(哪怕带
500、哪怕抄了超时原文)仍按未声明拒绝。回滚即 revert。
-
先看:`packages/runtime/src/sandbox/hook-refusal-catalogue.ts`(`resolveSandboxedRefusal`
第一行的 `isRunnerOwnFault`
放行);`packages/runtime/src/sandbox/quickjs-runner.ts`(`budgetError` 的两个
`action` 分支、`actionTimeoutSentence` 与
`runnerOwnFaults`);`packages/runtime/src/sandbox/action-refusal-catalogue.test.ts`(末尾新
describe 的四个钉子)。
- 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run
src/sandbox/sandboxed-action-crash-is-a-fault.test.ts
src/sandbox/action-refusal-catalogue.test.ts`,预期 31 条全过,其中声明了 `refusals`
的动作超时,在 HTTP 门与 MCP 读取器上同样给出那句话,日志保留 CPU 时限那一行。
- 需要你做的:无,席位落地。
## What changes
- **`@objectstack/runtime`, `quickjs-runner.ts`.** `budgetError` gains
an `action` arm on each of its two limits. For an action, the
`SandboxError` keeps its operator line in `.message` (`action 'NAME'
exceeded CPU budget of Nms (after P pump iterations)`, unchanged), and
now carries `innerMessage` = `actionTimeoutSentence(...)` and a declared
`status: 500`, with no `code`. This is the shape of the compile-failure
precedent (`actionBodyCompileFailure`, merged in 743308b). The two
sentences:
- CPU budget: `Action 'NAME' timed out: it exceeded its N ms time limit
and was stopped.`
- Wall-clock ceiling: `Action 'NAME' timed out: it exceeded its N ms
time limit while waiting on platform calls, and was stopped.`
- **What answers it.** `actionsDoorAnswerOf` (`@objectstack/types`, not
edited) reads the sentence through `sandboxBusinessMessage`. Arm 2
(crash) does not take it, because the sentence is not
native-error-named. Arm 3 serves the declared status, with the status's
own `INTERNAL_ERROR` and the sentence (`looksLikeInternalErrorLeak`
reads false). The HTTP door (`HttpDispatcher.handleActions`) and MCP
`run_action` / `resume_run` (`errorResultFromThrown`) both render that
one reader, so they give the same sentence.
- **Ruling conditions, as measured:**
1. Only a timeout gains a sentence. Status and code stay `500` /
`INTERNAL_ERROR`. A crash keeps `Internal server error`: the crash path
is untouched, and a pin holds it on both doors.
2. Actions only. Hook and job timeouts keep the 1-argument
`SandboxError` with no `innerMessage` and no `status`. On `/data`,
`mapDataError` relays a sandbox `innerMessage` only below the server
band, so the declared `500` keeps the action sentence off that door too.
A pin measures this. `sandbox-business-message.ts` needed no edit.
3. Both doors give the same sentence, and
`content/docs/api/error-catalog.mdx` gains a "Sandboxed body timed out"
row under Action Errors. "sandbox timeout" moves out of the crash row.
- **Core sandbox-fault census**
(`packages/core/src/utils/import-runner-sandbox-fault-row.test.ts`, not
edited). Each new construction keeps a literal template as its message,
using interpolations the census already samples (`args.origin.name`,
`cpuBudget`, `wallCeiling`, `pumps`). The census picks the new sites up
(`quickjs-runner.ts:250` and `:262` in its §2) with no new sample, and
still finds the hook/job fault sites its `CPU budget` / `wall-clock
ceiling` floors need. 48/48 green.
- **Tests.** Two existing pins asserted the old action-timeout shape, so
they now assert the sentence. `unreadable-rejection-recorded.test.ts`:
the never-settles control expected `innerMessage` undefined.
`sandbox-unreadable-rejection-door.test.ts`: a real-stack `/actions`
door case now also asserts the message. That file also gains the
module-top `import '@objectstack/metadata'` that
`check:test-source-alias` asks of an edited door test.
- **Docs made consistent (round 2, L1 S1 / N1).**
`content/docs/ui/actions.mdx`: the 500 bullet now reads "it **crashed**
(a `TypeError` in your handler, a driver error) or **timed out**; a
timeout's message names the action and its limit, while a crash answers
only `Internal server error`", matching the catalog row. The header
comment of `packages/runtime/src/domains/actions.ts` no longer lists a
sandbox timeout under crash.
- **Fix round 3 (contract review 6972256765, F1).** An action that
declares `refusals` lost the timeout sentence: `boundActionHandler`
hands every throw to `resolveActionRefusal`, and the catalogue read the
sentence as the body's code-less throw, replaced it with the
undeclared-refusal fault, answered the bare 500 on both doors and logged
"threw no code" instead of the budget line. Measured before the fix on
this branch's head `ddee9584b9`, through the real bound handler: both
doors answered `Internal server error`. The compile-failure fault
(`actionBodyCompileFailure`) had the same route, and the same mark
covers it with no extra path.
- `quickjs-runner.ts`: a module-level `runnerOwnFaults` WeakSet beside
`hostRelayedErrors`. The runner marks the faults it makes itself that
carry a caller sentence: the action arms of `budgetError` (CPU budget,
wall-clock ceiling) and `actionBodyCompileFailure`. `isRunnerOwnFault`
reads the mark. Identity, not a field: a body can throw `innerMessage` +
`status: 500` + no code itself, so no field tells the two apart. The
runner's other faults carry no `innerMessage` and pass as before.
- `hook-refusal-catalogue.ts`: `resolveSandboxedRefusal` passes a
runner-own fault through before it reads any field. There is no
pass-through on a declared server-band status: a body's own code-less
throw with `status: 500`, even one spelled with the timeout's exact
words, is still refused as undeclared. The module header says so.
- `action-refusal-catalogue.test.ts` (the action-catalogue harness): a
new top-level describe, through the real `actionBodyRunnerFactory` and
read on the `/actions` door and `actionsDoorAnswerOf` (the reader MCP
`run_action` renders). A CPU timeout and a wall-clock timeout each
answer `500 INTERNAL_ERROR` with the sentence on both doors, and the
error logged at `error` still carries the runner's operator line, read
at log time. A compile failure answers its sentence on both doors, and
the log names the compiler. A control holds three code-less body throws
(plain, `status: 500`, and `status: 500` with the timeout's own
sentence) to the undeclared refusal and the bare 500 on both doors.
- **Changeset:** `@objectstack/runtime` patch. Round 3 adds one
paragraph: the same holds for an action that declares `refusals`.
## Tests
<details><summary>Round 3 (head 48170d2): F1 red then green,
ablation, package suite</summary>
- **Red before the fix.** The new describe, run against the unfixed
runner and catalogue (`ddee9584b9` plus the test only): `Tests 3 failed
| 17 passed (20)`. CPU timeout, received on both doors `"message":
"Internal server error"` where the sentence was expected. Wall-clock
timeout, the same. Compile failure: `expected 'Internal server error' to
contain 'Action 'submit_signoff' cannot run:…'`. The control (code-less
body throws stay refused) was green.
- **Green after the fix** (331f618): `action-refusal-catalogue`,
`sandboxed-action-crash-is-a-fault`, `hook-refusal-catalogue`,
`unreadable-rejection-recorded`, `sandbox-unreadable-rejection-door`,
`quickjs-runner`: `Test Files 6 passed (6)`, `Tests 145 passed (145)`.
- **Ablation** through `scripts/ablation-replace.mjs`: in
`hook-refusal-catalogue.ts`, replaced the line `if
(isRunnerOwnFault(err)) return err;` with a comment. `ok mutation
landed: anchor 1 -> 0, blob 1d140e6 -> 7bd11f4783b5`. The suite
imports the catalogue from `src/` by relative path, so no dist rebuild
was needed. Result: `Tests 3 failed | 17 passed (20)`; red: the
CPU-timeout, wall-clock-timeout and compile-failure pins; the control
stayed green. Restore: `ok restored: blob == HEAD (1d140e6) and git
diff HEAD is empty`.
- `pnpm --filter @objectstack/runtime test` (`--project local`): `Test
Files 619 passed (619)`, `Tests 11500 passed | 23 skipped (11523)`, exit
0. The run was on the fix's code. The commit after it changes only the
changeset.
- `pnpm --filter @objectstack/runtime typecheck`: exit 0,
`check:test-typecheck: OK`.
- Core census `import-runner-sandbox-fault-row.test.ts` (`repo` project,
run locally because it parses the edited runner): `Tests 48 passed
(48)`.
</details>
<details><summary>Targeted files, package suites, typecheck (head
d50f969 for the re-runs after the last edit)</summary>
- `pnpm exec vitest run` (runtime) on
`sandboxed-action-crash-is-a-fault`, `unreadable-rejection-recorded`,
`sandbox-unreadable-rejection-door` and `quickjs-runner`: `Test Files 4
passed (4)`, `Tests 87 passed (87)`.
- Re-run after the import fix (d50f969),
`sandbox-unreadable-rejection-door` and
`sandboxed-action-crash-is-a-fault`: `Test Files 2 passed (2)`, `Tests
16 passed (16)`.
- `pnpm --filter @objectstack/runtime test` (`--project local`): `Test
Files 618 passed (618)`, `Tests 11470 passed | 23 skipped (11493)`, exit
0. This ran on 1a88607. The only change since then is a module-top
side-effect import in one test file, and that file was re-run above.
- `pnpm --filter @objectstack/mcp test`: `Test Files 71 passed (71)`,
`Tests 1260 passed (1260)`, exit 0.
- `mcp-coded-refusal.test.ts`: 180/180.
`import-runner-sandbox-fault-row.test.ts` (core census, `repo` project,
run locally because it parses the edited runner): 48/48.
- `pnpm --filter @objectstack/runtime typecheck`: exit 0
(`check:test-typecheck: OK`). The first run was red on two untouched
files, `TS2307 Cannot find module '@objectstack/driver-turso'`, because
that dist had not been built. It went green once the dist was built.
`@objectstack/mcp typecheck`: `tsc --noEmit` and `check:test-typecheck:
OK`.
</details>
<details><summary>Ablations: three pins, each mutated once through
scripts/ablation-replace.mjs, restored to blob == HEAD</summary>
The mutations are all in `quickjs-runner.ts`, which the suite imports
from `src/` by relative path, so no dist rebuild was needed.
`ablation-replace` reported each mutation as landed (anchor 1 -> 0).
After each leg, the restore showed `git hash-object` = HEAD blob
`bd7078824818` and `git diff HEAD` empty.
- **(a) The timeout sentence, the same on both doors.** Replaced
`actionTimeoutSentence(args.origin.name, cpuBudget, false),` with
`undefined,`. Result: `Tests 2 failed | 9 passed (11)`. Red: "the runner
keeps its operator line, and declares 500 with the sentence and no code"
and "the /actions door and the MCP run_action reader answer 500
INTERNAL_ERROR with the same sentence".
- **(b) A crash still sanitised.** Prefixed the crash relay's
`innerMessage` with `'Action failed internally: '`, so it no longer
reads as a native error. Result: `Tests 5 failed | 6 passed (11)`. Red:
the new "control: a crash beside it keeps the sanitised 500 on both
doors", plus the existing crash, runtime-SyntaxError and
negative-control pins.
- **(c) A hook timeout unchanged on /data.** Widened the CPU arm's
`args.origin.kind === 'action'` to `!== 'job'`, which pulls hooks into
the action arm. Result: `Tests 1 failed | 10 passed (11)`. Red:
"control: a hook timeout is unchanged, and the /data door answers it the
sanitised fault".
</details>
## Acceptance notes
- `Clause-②: no` and `Metadata-protocol: none` hold after round 3: the
fix restores the ruled answer on a path the round-1 pins did not reach,
and refuses nothing it accepted before.
- Round 2 fixed `content/docs/ui/actions.mdx` (the 500 bullet) and the
`domains/actions.ts` header comment, after the claim amendment added
both to the surface.
- The MCP pin (`mcp-coded-refusal.test.ts`) drives `run_action` /
`resume_run` with the runner's measured timeout shape.
`@objectstack/mcp` does not depend on `@objectstack/runtime`, so the
real-run half lives in the runtime file. That file feeds the same real
error to the HTTP door and to `actionsDoorAnswerOf`, the reader the MCP
tools render.
## Verification
<details><summary>Gates, round 3 (head 48170d2)</summary>
- `dispatch-gates --commands` derived 100 commands. All 100 were run,
and each exited 0 (exit codes captured per command before any pipe). On
the first pass `check:skill-examples` and `check:dual-build-cjs-loads`
exited 3 (PREREQUISITE NOT MET, dists missing). After a whole-workspace
build (`turbo run build`, 120/120 tasks) both exited 0. The changeset
gates and the text gates that read `.changeset/` were re-run on
48170d2, the changeset commit.
- `--ran` reconciliation: `100 derived, 100 run, 0 NOT-MEASURED, 0
UNRUN`.
- The derivation warned that the tree is behind origin/main, and that
one gate file changed on main across that range:
`scripts/check-skill-identifier-liveness.mjs`. Its family ran from this
branch's copy and exited 0. Main was not merged: the branch has no
conflict and main does not make it red.
- `overlap-check` before each push: `VERDICT clean exit 0` against
origin/main `f7960893cd` and `99a0e4fbfc`, with no open PR head
overlapping.
</details>
<details><summary>Gates, round 2 (head 8010091)</summary>
- `dispatch-gates --commands` on 8010091 derived 98 commands (round
1's 96, plus `check:adr-symbol-anchors` and `check:route-envelope`). I
ran 97 of them on 8010091, and each exited 0.
- NOT MEASURED: `pnpm check:dual-build-cjs-loads`. It exited 3 with
PREREQUISITE NOT MET, because it reads built output and this fresh
worktree has no dist for `@objectstack/account`, `@objectstack/setup`,
`@objectstack/studio`, `@objectstack/cloud-connection` and 30-odd more.
A whole-tree build was not started, because the maintainer's hand-off
order said to start no new long steps. CI's Lint lane runs it. On
d50f969 it passed (124 entries / 72 packages).
- `--ran` reconciliation over the 97 measured commands: `98 derived, 97
run, 0 NOT-MEASURED, 1 UNRUN`. The UNRUN entry is
`check:dual-build-cjs-loads`, above.
- Re-run on 8010091 (diff since d50f969: docs bullet + one code
comment): runtime pins `sandboxed-action-crash-is-a-fault`,
`unreadable-rejection-recorded`, `sandbox-unreadable-rejection-door` and
`quickjs-runner`: 4/4 files, 87/87 tests. `mcp-coded-refusal`: 180/180.
Core census: 48/48. The package suites and typecheck were not re-run;
the round-1 readings on d50f969 stand for unchanged code.
- `overlap-check` before the push: `VERDICT clean exit 0` against
origin/main 154cb72, and against #35085, which shares
`content/docs/ui/actions.mdx` and `quickjs-runner.ts` and merges
cleanly.
</details>
<details><summary>Gates, round 1 (head d50f969)</summary>
- `node scripts/pm/dispatch-gates.mjs --commands`: 96 derived commands.
All 96 were run on d50f969 and every one exited 0 (exit codes
captured per command before any pipe). `--ran` reconciliation: `96
derived famil(ies) accounted for — 96 run, 0 NOT-MEASURED`.
- On the earlier pass, three gates refused or failed:
`check:skill-examples` (exit 3, client-react dist missing),
`check:dual-build-cjs-loads` (exit 3, dists missing) and
`check:test-source-alias` (exit 1, the door test's missing module-top
import, now fixed). All three exit 0 on the final pass.
- `node scripts/pm/overlap-check.mjs` before each push: `VERDICT clean
exit 0` (origin/main 301b7c1; #35085 shares `quickjs-runner.ts` and
merges cleanly).
- NOT MEASURED, CI-owned: the families `dispatch-gates` lists as
CI-measured-only or workflow-valued, the type-check lanes, and the
path-scheduled CI jobs. The full dogfood is not owed (no `!`, no
`(narrowing)` arm).
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufziunkXbDT7wUWqfmWz)_
<!-- signed: repo:objectstack#1 · os-warren ·
session_01JQwxbXGvw43spR79ztEvWt -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent 2fea6d2 commit 961f474
11 files changed
Lines changed: 350 additions & 17 deletions
File tree
- .changeset
- content/docs
- api
- ui
- packages
- mcp/src
- runtime/src
- domains
- sandbox
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
708 | 708 | | |
709 | 709 | | |
710 | 710 | | |
711 | | - | |
| 711 | + | |
| 712 | + | |
712 | 713 | | |
713 | 714 | | |
714 | 715 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
699 | 699 | | |
700 | 700 | | |
701 | 701 | | |
702 | | - | |
703 | | - | |
704 | | - | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
705 | 706 | | |
706 | 707 | | |
707 | 708 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
990 | 990 | | |
991 | 991 | | |
992 | 992 | | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
993 | 1015 | | |
994 | 1016 | | |
995 | 1017 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
| |||
158 | 161 | | |
159 | 162 | | |
160 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
161 | 168 | | |
162 | 169 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
56 | 63 | | |
57 | 64 | | |
58 | | - | |
| 65 | + | |
59 | 66 | | |
60 | 67 | | |
61 | 68 | | |
| 69 | + | |
62 | 70 | | |
63 | 71 | | |
64 | 72 | | |
| |||
271 | 279 | | |
272 | 280 | | |
273 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
40 | 43 | | |
41 | 44 | | |
42 | 45 | | |
| |||
82 | 85 | | |
83 | 86 | | |
84 | 87 | | |
| 88 | + | |
85 | 89 | | |
86 | 90 | | |
87 | 91 | | |
| |||
453 | 457 | | |
454 | 458 | | |
455 | 459 | | |
456 | | - | |
457 | | - | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
458 | 466 | | |
459 | 467 | | |
460 | 468 | | |
| |||
0 commit comments