Skip to content

fix(mcp): the record data tools answer a code-less throw as the /data door does, so an undeclared hook abort is HOOK_ABORTED - #31245

Merged
objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-vvleyi
Nov 7, 2026
Merged

objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-vvleyi

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by 田騏 · project thread

Fixes #31218

Clause-②: yes
Metadata-protocol: none

维护者速读

  • 改了什么:MCP 的六个记录数据工具(query_records、aggregate_records、get_record、create_record、update_record、delete_record)遇到不带错误码的异常时,改用 /api/v1/data 同一个分类函数 mapDataError 来回答:沙箱 hook 的业务中止回 HOOK_ABORTED + hook 自己写的那句话;代码 hook 的裸 throw、崩溃、驱动错误回 500 INTERNAL_ERROR,原文不再给 agent,改为在服务端打一条 [5xx] 日志。带错误码的异常照旧。
  • 为什么改:之前 agent 看到的是沙箱调试包装 hook 'NAME' threw: Error: …,没有错误码,还暴露 hook 内部名字;同一个中止在 REST 上是 400 HOOK_ABORTED。agent 分不清"业务拒绝"和"故障",场景跑分也读不到码。
  • 风险与回滚:这六个工具对无码异常的回答从纯文本变成 JSON 信封 { error: { code, message, status } },且 5xx 原文被隐去(与 REST 一致);只改 @objectstack/mcp,patch。回滚即还原 mcp-http-tools.ts。
  • 先看:packages/mcp/src/mcp-http-tools.ts 的 dataDoorErrorResult / dataDoorAnswerOf;packages/mcp/src/mcp-coded-refusal.test.ts 末尾的 mcp: the data tools answer an undeclared sandboxed hook abort with no code and the sandbox wrapper text, where /data answers 400 HOOK_ABORTED #31218 块。
  • 两分钟验证:pnpm --filter @objectstack/mcp exec vitest run src/mcp-coded-refusal.test.ts -t 31218,预期 16 个用例全部通过。
  • 需要你做的:无,席位落地。

What changes

The record data tools of packages/mcp/src/mcp-http-tools.ts rendered a thrown error that carries no string code as its bare message (errorResult(messageOf(err))). A QuickJS hook body's throw new Error('…') arrives as a SandboxError with no code, whose .message is the hook 'NAME' threw: Error: … debug wrapper, so the agent read the wrapper (hook name included) and no ErrorCode, while /api/v1/data answers the same throw 400 HOOK_ABORTED with the inner sentence.

  • dataDoorErrorResult(err, tool, objectName), the catch of query_records, aggregate_records, get_record, and (through landedWriteResultOrError's otherwise, now a required argument) create_record, update_record, delete_record:
    • a coded throw renders through thrownRefusalEnvelope exactly as before (read first);
    • a code-less throw renders the /data door's answer, { "error": { "code", "message", "status" } }, read off mapDataError(err, objectName) (@objectstack/types) by dataDoorAnswerOf. No second classification exists in packages/mcp;
    • a 5xx answer is logged once through logServerFault ([5xx] 500 tools/call update_record task — THROWN-MESSAGE), since its message no longer reaches the agent.
  • rowRefusalOf (the per-row grouping of delete_records, MCP: delete records by filter in one confirmed call, with refusals grouped by reason, instead of one delete_record per row #30891) reads the same dataDoorAnswerOf instead of its own inline read of mapDataError; its answers are unchanged.
  • codedErrorResult accepts an envelope without code, for a throw that declared a status and no code (the door invents none).
  • No change to @objectstack/types, packages/spec, the other tools, or the coded path.

The family, each answered as the door answers it (pinned at the MCP door, each asserted literally AND equal to mapDataError on the same throw):

Throw Before (MCP) Now (MCP) = /data
sandboxed hook abort, no code (SandboxError, innerMessage) text hook 'demoleave_leave_request_guard' threw: Error: Not enough annual leave remaining HOOK_ABORTED · 400 · Not enough annual leave remaining
the same abort with the SandboxError instance lost (wrapper text only) the wrapper text HOOK_ABORTED · 400 · inner sentence
sandboxed abort that declared status: 422, no code the wrapper text HOOK_ABORTED · 422
code hook's bare throw new Error(…) its message INTERNAL_ERROR · 500 · Internal server error (message logged)
sandboxed body that crashed (TypeError: …) the wrapper text INTERNAL_ERROR · 500
runtime callData's { statusCode: 503, message: 'Data service not available' } its message no code · 503 · Internal server error (message logged)
{ statusCode: 400, message }, no code its message no code · 400 · its message
coded refusal (RECORD_LOCKED / 409) — CONTROL coded envelope unchanged, not logged

Tests

Base re-measure (order step 1) and ablation

Base re-measure: mcp-http-tools.ts restored to the base blob (2b752f1, hash match checked), the #31218 block run: Tests 13 failed | 3 passed | 46 skipped (62). Each data tool's text was hook 'demo… (SyntaxError: Unexpected token 'h', "hook 'demo"... is not valid JSON, ×5 tools + the lost-instance row), and the 503 / bare / 400 rows answered Data servi… / Not enough… / aggregate … as bare text. Restored with git checkout HEAD --, git diff HEAD empty.

Ablation (one-time, node scripts/ablation-replace.mjs): in dataDoorErrorResult, return codedErrorResult(door); replaced by return errorResult(messageOf(err));. ok mutation landed: anchor 1 -> 0, blob 15cb855c1f9c -> 62f6a65d8a2b; src/mcp-coded-refusal.test.ts: Tests 19 failed | 43 passed (62) (the 13 rows above plus the 6 table rows); ok restored: blob == HEAD (15cb855c1f9c) and git diff HEAD is empty. The test imports the package's source, so no dist/ is involved.

Acceptance notes

  • Still answered differently from REST, not changed here (listed for the seat):
    • a CODED sandboxed refusal (throw with code + status in a hook body) answers the wrapper text with the hook name, { code: 'RECORD_LOCKED', message: "hook 'guard' threw: Error: Locked.", status: 409 }, measured on MCPServerRuntime; /data answers the inner sentence. thrownRefusalEnvelope reads .message; the order kept the coded path unchanged.
    • the metadata tools (list_objects, describe_object, validate_expression), list_actions, the record resource, run_action / resume_run and delete_records' outer catch still render a code-less throw as its bare message. delete_records' outer catch also renders this file's own code-less sentences, which the door's message heuristics would misread (its "could not read the records" sentence names the object and contains not, the unknown-object limb), so it keeps errorResultWithCode.
    • delete_records' fault answer still quotes the faulting row's thrown message.
    • a driver's own string code (SQLITE_BUSY) rides the coded path with its message, where /data answers 500 INTERNAL_ERROR.
  • The 5xx log line is logServerFault's, with request: { method: 'tools/call', path: 'TOOL OBJECT' } as its coordinates; the MCP tool layer has no HTTP request in hand.

Verification

Merged origin/main once before opening (a0f8cfb; the merge touched packages/lint and plugin-auth tests only).

  • pnpm --filter @objectstack/mcp test on a0f8cfb: Test Files 60 passed (60), Tests 789 passed (789), lock VERDICT command-exit 0.
  • pnpm --filter @objectstack/mcp typecheck: exit 0 (includes 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).
Derived gates (node scripts/pm/dispatch-gates.mjs --commands, 60 commands, all on a0f8cfb)
  • 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 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: Run reconciliation — 60 derived, 60 run, 0 NOT-MEASURED, 0 UNRUN.

Not run locally (CI's): test:repo, the dogfood shards (queue only), the type-check lanes.

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic. (Not touched.)
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; pnpm lint passes. (eslint on the touched files.)
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec touched: its generated artifacts are regenerated and committed. (Not touched.)
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English.
  • The Before Submitting list in CONTRIBUTING.md is done.

Generated by Claude Code

🤖 Generated with Claude Code

…ta door does

A sandboxed hook body's undeclared abort reached update_record and its
siblings as the QuickJS debug wrapper text, hook name included, with no
ErrorCode, where /api/v1/data answers 400 HOOK_ABORTED with the inner
sentence. The record data tools now render a code-less throw through
mapDataError, the door's own classifier: HOOK_ABORTED for an undeclared
abort, 500 INTERNAL_ERROR with the message withheld (and logged through
logServerFault) for a bare code-hook throw, a declared status with no
code invented. A coded throw renders exactly as before.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ihL2eNMbdYCpXSovm5QP5
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/mcp, touching 14 documentable anchor(s).

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

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

What this run could not see
  • 1 anchor(s) matched too much of the corpus to be a work list: /api/v1/data (route, 50 pages)
  • the SDK route bridge reached 63 of 226 client-bound route-ledger rows — the other 163 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 163: 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; 104 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 — 12 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 30f23fef481c89e8e94beb45f6b912d56dea0ea1 → packageMentionDocs.

Which tree this was computed on

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

node scripts/docs-audit/affected-docs.mjs --json 30f23fef481c89e8e94beb45f6b912d56dea0ea1

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

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 30f23fef481c89e8e94beb45f6b912d56dea0ea1 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#4 · marchtian · session_017ihL2dLQEXWGsE2SZ3Qn5F

Contract review

Served-tier: TIER_DEFAULT
Head-sha: a0f8cfb56f18b996a72a5edb3fb396710823f849
Local-runs: none

① Derived judgments

  • Face: declared-output change on six MCP tools' error results (Clause-②: yes on the claim 6711692486, PR body and changeset). No path under packages/spec/** or packages/types/**, no governed path, no new error code. Diff read in full: 4 files, +318/−33.
  • One classifier, never a copy. dataDoorAnswerOf reads mapDataError (@objectstack/types) — the function /api/v1/data answers with — for code, sentence and status; rowRefusalOf (delete_records) now reads the same helper. MCP and the data door cannot drift on a code-less throw.
  • Coded path first and unchanged. dataDoorErrorResult asks thrownRefusalEnvelope before the door, so a thrown code renders byte for byte as before (CONTROL pinned, unique-violation spelling included); the non-record tools keep errorResultWithCode (CONTROL pinned).
  • No leak a REST 500 would sanitize. A fault answers 500 INTERNAL_ERROR / Internal server error, a declared 5xx's prose is withheld, and the message reaches the operator through the shared logServerFault line; 4xx refusals are not logged (pinned).
  • The ruled answers: undeclared sandboxed abort → HOOK_ABORTED + inner sentence, hook name absent (also when the SandboxError instance is lost); declared 4xx kept; crash → 500; {statusCode:503} → 503, no invented code. Ablation on the classification: 19 red.
  • Test edits checked, not loosened: the aggregate FLS fixture now throws coded — verified against the real throwers (PermissionDeniedError in plugin-security, fieldReadDeniedError, the plugin-audit and plugin-approvals guards all carry PERMISSION_DENIED/403); the RLS: not permitted fixture is a code-less Error, which the door answers as a fault, now pinned exactly.

② Semver level

  • The accept set is unchanged; only error-result bodies move (bare text → the JSON envelope the coded path already uses; fault prose withheld). Additive-to-safer output change ⇒ patch, as the changeset declares, with the migration sentence (error.message, branch on error.code). Not a narrowing: no call that succeeded now fails.

③ Boundary flags

Implemented-by: claude/project-thread-vvleyi
Reviewed-by: session_017ihL2dLQEXWGsE2SZ3Qn5F

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#4 · marchtian · session_017ihL2dLQEXWGsE2SZ3Qn5F

席位核对 — ACCEPT · domain:server#4 · Head-sha: a0f8cfb56f18b996a72a5edb3fb396710823f849

  • Shape: draft → main, Fixes #31218 once, Clause-②: yes and Metadata-protocol: none line-initial; changeset @objectstack/mcp patch. 4 files, +318/−33, all under packages/mcp plus the changeset; not governed, under 3000 lines.
  • Diff read by the seat: the six record data tools' catches go through dataDoorErrorResult — coded path first and unchanged, then the /data door's own mapDataError read once in dataDoorAnswerOf (which rowRefusalOf now shares); faults are withheld and logged with the shared logServerFault. The two edited existing pins were checked against the real throwers (the aggregate FLS denial is coded at every source; the RLS fixture is a code-less Error).
  • Premise measured: baseline on MCPServerRuntime reproduced the wrapper text with the hook name and no code (13 red before the fix, report 6712120510).
  • Gates (check-runs on the head): 48 runs — 35 success, 13 skipped, 0 failed. Dev: mcp 789/789; dispatch-gates --ran 60/60, 0 NOT-MEASURED; typecheck and eslint green; ablation on the classification 19 red.
  • Accepted deviations: delete_records' outer catch keeps errorResultWithCode (its own code-less sentences would trip mapDataError's unknown-object heuristic); the coded sandboxed refusal stays a CONTROL as ordered.
  • Out of scope: the coded sandboxed refusal's wrapper text on MCP and the other MCP faces' divergences from REST → mcp: a CODED sandboxed hook refusal still answers the sandbox wrapper text with the hook's name, where /data answers the body's sentence — and the other MCP tools still render a throw unlike REST #31246 (finding).
  • Landing: Tier: none, not a narrowing (no call that succeeded now fails). Seat lands: pr_ready + automerge_enable through the relay.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 7, 2026 20:03
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 7, 2026 20:03
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 1aa4dd1 Nov 7, 2026
49 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-vvleyi branch November 7, 2026 20:26
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/m 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.

mcp: the data tools answer an undeclared sandboxed hook abort with no code and the sandbox wrapper text, where /data answers 400 HOOK_ABORTED

2 participants