Repository navigation
Commit 131f855
fix(mcp): a coded sandboxed hook crash is a fault on MCP, not a refusal at its declared status (#31290)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1X3apZSKwFDd6zvjM4gJPKAy)_
Fixes #31269
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:沙箱 hook 主体在声明了错误码的情况下崩溃(如 `TypeError`),MCP 不再把它当成业务拒绝(声明的码 + 409
+ 带 hook 名的包装文本)。现在它和不带码的同一个崩溃答得一样:六个记录数据工具答 `500 INTERNAL_ERROR` /
`Internal server error`,并在服务端记一行日志,与 `/api/v1/data` 一致。
- 为什么改:REST 各入口先判断"是不是崩溃"(`isSandboxCrash`),崩溃一律按服务端故障答 500;MCP
只看错误码,于是把 hook 内部名和原生错误文字以业务状态码交给 agent。
- 风险与回滚:只在 `@objectstack/mcp` 的 `thrownRefusalEnvelope` 加一行,直接调用
`@objectstack/types` 已导出的同一个判断函数;不带崩溃的带码拒绝不变。回滚即删这一行。patch。
- 先看:`packages/mcp/src/mcp-http-tools.ts` 的
`thrownRefusalEnvelope`;`packages/mcp/src/mcp-coded-refusal.test.ts` 末尾的
#31269 块。
- 两分钟验证:`pnpm --filter @objectstack/mcp exec vitest run
src/mcp-coded-refusal.test.ts -t 31269`,预期 15 个用例全部通过。
- 需要你做的:无,席位落地。
## What changes
`thrownRefusalEnvelope` (`packages/mcp/src/mcp-http-tools.ts`), the one
reader every MCP face uses to tell a coded refusal, now returns
`undefined` when `isSandboxCrash(err)`. `isSandboxCrash` is the
predicate `classifyDataError` and `resolveErrorResponse` ask before any
code-gated arm. `@objectstack/types` already exports it (`rest`'s
`error-response.ts` imports it), so no export is added and there is no
copy of the crash read in `packages/mcp`.
A sandboxed body that crashed while declaring a code is therefore no
coded refusal, and each face renders it as it renders the same crash
with no code. That is the fault answer each face already gives an
uncoded crash today, not a new shape. Measured on `/mcp` over a bridge
member throwing the real runner's `SandboxError` (`message` `hook
'demo_guard' threw: TypeError: boom`, `innerMessage` `TypeError: boom`,
`code` `RECORD_LOCKED`, `status` 409):
| Face | Before | Now (= that face's answer to the same crash with no
code) | REST door |
|---|---|---|---|
| `query_records`, `aggregate_records`, `get_record`, `create_record`,
`update_record`, `delete_record` | `RECORD_LOCKED` · wrapper · 409 |
`INTERNAL_ERROR` · `Internal server error` · 500, one `[5xx] 500
tools/call TOOL task — …` log line | `/data`: `500 INTERNAL_ERROR`
`Internal server error` |
| `delete_records` (a row that crashes) | fault with `code:
RECORD_LOCKED`, `status: 409`, the wrapper quoted | the uncoded fault
answer: no code, no status, the thrown message quoted (kept on purpose,
PR #31245 note) | n/a |
| `list_objects`, `describe_object`, `validate_expression`,
`list_actions`, `delete_records` outer catch | `RECORD_LOCKED` · wrapper
· 409 | the bare thrown text (today's uncoded rendering) | `/meta`: `500
INTERNAL_ERROR` |
| `run_action`, `resume_run` | `RECORD_LOCKED` · wrapper · 409 | the
bare thrown text (today's uncoded rendering) | `/actions`: `500
INTERNAL_ERROR` |
| record resource | `{ error: wrapper, code: RECORD_LOCKED, status: 409
}` | `{ error: wrapper }` (today's uncoded rendering) | `/data`: `500
INTERNAL_ERROR` |
No face serves the declared code or its business status for a crash any
more. The record data tools now give the doors' full fault answer. On
the other faces, the crash's text is still the face's uncoded rendering,
which carries the wrapper. Those renderings are the next cards in this
chain, which the order fences out of this PR: #31270 (record resource),
#31271 (`run_action` / `resume_run`), #31272 (metadata tools and
`list_actions`). When they land, the coded crash follows them, because
the pins hold each such face equal to its code-less answer.
`delete_records`' outer catch and its fault quote are kept as intended
(PR #31245 and #31268).
Unchanged, measured before and after on the same probe: a coded
sandboxed refusal (`Locked.` 409, #31246), a code-less sandboxed abort,
a bare `Error`, and a driver string code (`SQLITE_BUSY`, #31273's face)
answer byte for byte as before on every face.
## Tests
`packages/mcp/src/mcp-coded-refusal.test.ts`, a new `#31269` describe on
the shared `/mcp` harness:
- each of the six record data tools: `{ code: 'INTERNAL_ERROR', message:
'Internal server error', status: 500 }`, equal to `mapDataError`'s
answer to the same throw; the text carries no hook name and no
`TypeError`; one `[5xx] 500 tools/call TOOL task — ` log line;
- every other tool (the `SITES` table, which is held equal to the
registered tool list): the coded crash's answer equals the same crash's
answer with no code, and `RECORD_LOCKED` / `409` are absent;
- CONTROL: a coded sandboxed refusal keeps `{ code: 'RECORD_LOCKED',
message: 'Locked.', status: 409 }` on every tool.
In the record-resource describe: the coded crash answers byte for byte
what the same crash with no code answers, and `RECORD_LOCKED` is absent.
`packages/mcp/src/mcp-delete-records.test.ts`: a row that crashes with a
declared code stops the call as a fault with no code and no status, and
the whole answer equals the one for the same crash with no code.
<details><summary>Red first and ablation</summary>
Red first on `b3bd75d8` (`main`, with PR #31268), new pins and no fix:
`Tests 15 failed | 107 passed (122)` across the two files. The CONTROL
passed. The real runner probe (`QuickJSScriptRunner`, hook body `throw
Object.assign(new TypeError('boom'), { code: 'RECORD_LOCKED', status:
409 })`) gave `message` `hook 'demo_guard' threw: TypeError: boom`,
`innerMessage` `TypeError: boom`, `code` `RECORD_LOCKED`, `status` 409.
`mapDataError` answered `500 INTERNAL_ERROR` `Internal server error`,
while every MCP tool and the record resource answered `RECORD_LOCKED` /
wrapper / 409. With the fix: `Tests 122 passed (122)`.
Ablation (`node scripts/ablation-replace.mjs`, `mcp-http-tools.ts`): `if
(isSandboxCrash(err)) return undefined;` replaced by `if
(isSandboxCrash(err) && String("ABL").length < 0) return undefined;`.
Output: `ok mutation landed: anchor 1 -> 0, blob eca0c12 ->
c7b949836b5f`, then `Tests 15 failed | 107 passed (122)`, then `ok
restored: blob == HEAD (eca0c12) and git diff HEAD is empty`. The
tests import the package's source, so no `dist/` is involved.
</details>
## Acceptance notes
- `Clause-②: no`: no export is added (`isSandboxCrash` was already on
`@objectstack/types`' entry), and no published type changes. The answer
that moves is a crash's text and status on MCP, which become the fault
answer each face already gives.
- The hook name still reaches an agent on the record resource,
`run_action` / `resume_run`, and the metadata tools and `list_actions`,
through their code-less renderings. Their carriers are #31270, #31271
and #31272, as the order rules.
## Verification
Base: `b3bd75d8`; head: `f7517feb`.
- `pnpm --filter @objectstack/mcp test`: `Test Files 60 passed (60)`,
`Tests 822 passed (822)`, lock `VERDICT command-exit 0`.
- `pnpm --filter @objectstack/mcp typecheck`: exit 0
(`check:test-typecheck`: 53 errors / 8 pinned signatures held).
- `pnpm exec eslint --no-inline-config` on the three touched `.ts`
files: exit 0 (`@objectstack/mcp` has no `lint` script).
<details><summary>Derived gates (node scripts/pm/dispatch-gates.mjs
--commands, 62 commands, all on f7517fe)</summary>
- `node scripts/check-adr-0087-registration.mjs --base origin/main` ::
exit 0
- `node scripts/check-adr-0087-registration.mjs --self-test` :: exit 0
- `node scripts/check-changeset-no-major.mjs --base origin/main` :: exit
0
- `node scripts/check-closing-keyword-parity.mjs` :: exit 0
- `node scripts/check-closing-keyword-parity.mjs --self-test` :: exit 0
- `node scripts/check-comment-mask-adoption.mjs` :: exit 0
- `node scripts/check-comment-mask-adoption.mjs --self-test` :: exit 0
- `node scripts/check-comment-mask-corpus.mjs` :: exit 0
- `node scripts/check-dts-emitted.mjs --self-test` :: exit 0
- `node scripts/check-empty-changeset.mjs --base origin/main` :: exit 0
- `node scripts/check-empty-changeset.mjs --self-test` :: exit 0
- `node scripts/check-issue-citations.mjs` :: exit 0
- `node scripts/check-plugin-teardown-shape.mjs` :: exit 0
- `node scripts/check-plugin-teardown-shape.mjs --self-test` :: exit 0
- `node scripts/ci/assert-turbo-remote-cache.mjs --self-test` :: exit 0
- `node scripts/ci/plan-test-core-shards.mjs --self-test` :: exit 0
- `node scripts/ci/prune-turbo-cache.mjs --self-test` :: exit 0
- `node scripts/ci/snapshot-next.mjs --self-test` :: exit 0
- `node scripts/docs-audit/check-affected-docs.mjs` :: exit 0
- `node scripts/docs-audit/check-drift-comment.mjs` :: exit 0
- `node scripts/pm/release-rehearsal-clone.mjs --self-test` :: exit 0
- `node scripts/release-pending-publish.mjs --self-test` :: exit 0
- `pnpm --filter @objectstack/spec run check:duration-unit-keys` :: exit
0
- `pnpm --filter @objectstack/spec run check:error-code-provenance` ::
exit 0
- `pnpm check:adr-symbol-anchors` :: exit 0
- `pnpm check:changeset-gate-self-tests` :: exit 0
- `pnpm check:ci-filter-parity` :: exit 0
- `pnpm check:closed-ceremony-text` :: exit 0
- `pnpm check:cross-package-test-inputs` :: exit 0
- `pnpm check:dispatcher-error-vocabulary` :: exit 0
- `pnpm check:doc-authoring` :: exit 0
- `pnpm check:driver-memory-census` :: exit 0
- `pnpm check:dts-closure` :: exit 0
- `pnpm check:dual-build-cjs-loads` :: exit 0
- `pnpm check:engine-double-contract` :: exit 0
- `pnpm check:error-status-conformance` :: exit 0
- `pnpm check:gitlink-declared` :: exit 0
- `pnpm check:issue-citations` :: exit 0
- `pnpm check:keyed-text-bounds` :: exit 0
- `pnpm check:lean-entry-closure` :: exit 0
- `pnpm check:logger-receiver-detach` :: exit 0
- `pnpm check:nul-bytes` :: exit 0
- `pnpm check:objectql-double-limit` :: exit 0
- `pnpm check:org-identifier` :: exit 0
- `pnpm check:page-declaration-shape` :: exit 0
- `pnpm check:platform-object-tenancy-census` :: exit 0
- `pnpm check:published-files` :: exit 0
- `pnpm check:query-options-erasure` :: exit 0
- `pnpm check:refd-timer-probe` :: exit 0
- `pnpm check:registry-log-declared` :: exit 0
- `pnpm check:rest-log-spy-declared` :: exit 0
- `pnpm check:slot-lookup` :: exit 0
- `pnpm check:sourcemap-no-sources-content` :: exit 0
- `pnpm check:system-context-census` :: exit 0
- `pnpm check:test-source-alias` :: exit 0
- `pnpm check:tier-file-adoption` :: exit 0
- `pnpm check:type-check-coverage` :: exit 0
- `pnpm check:type-check-debt` :: exit 0
- `pnpm check:undeclared-dep-imports` :: exit 0
- `pnpm check:vouch-for-reference-callers` :: exit 0
- `pnpm check:watch-hint-literal` :: exit 0
- `pnpm check:where-matcher` :: exit 0
`node scripts/pm/dispatch-gates.mjs --ran`: `62 derived famil(ies)
accounted for — 62 run, 0 NOT-MEASURED`. `check:dual-build-cjs-loads`
first exited 3 (PREREQUISITE NOT MET: not every package had a dist). It
exited 0 when re-run after `check:type-check-debt` had built every
package.
Not run locally (CI's): `test:repo`, the dogfood shards, the type-check
lanes.
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(Not touched.)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes. (eslint on the touched
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: its generated artifacts are
regenerated and committed. (Not touched.)
- [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.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01FEkQ5oWCPWH6i2Lsts9cdP
Co-authored-by: Claude <noreply@anthropic.com>1 parent 534a287 commit 131f855
4 files changed
Lines changed: 127 additions & 1 deletion
File tree
- .changeset
- packages/mcp/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
553 | 553 | | |
554 | 554 | | |
555 | 555 | | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
556 | 567 | | |
557 | 568 | | |
558 | 569 | | |
| |||
561 | 572 | | |
562 | 573 | | |
563 | 574 | | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
680 | 680 | | |
681 | 681 | | |
682 | 682 | | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
683 | 707 | | |
684 | 708 | | |
685 | 709 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
1131 | 1131 | | |
1132 | 1132 | | |
1133 | 1133 | | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
1134 | 1147 | | |
1135 | 1148 | | |
1136 | 1149 | | |
1137 | 1150 | | |
| 1151 | + | |
1138 | 1152 | | |
1139 | 1153 | | |
1140 | 1154 | | |
| |||
0 commit comments