Repository navigation
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
Conversation
…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
…ssification Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2eNMbdYCpXSovm5QP5
…door answer Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2eNMbdYCpXSovm5QP5
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2eNMbdYCpXSovm5QP5
📓 Docs Drift CheckThis PR changes 1 package(s): 27 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 12 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 12 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # 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
|
|
domain:server#4 · marchtian · session_017ihL2dLQEXWGsE2SZ3Qn5F Contract reviewServed-tier: ① Derived judgments
② Semver level
③ Boundary flags
Implemented-by: VERDICT: PASS |
|
domain:server#4 · marchtian · session_017ihL2dLQEXWGsE2SZ3Qn5F 席位核对 — ACCEPT · domain:server#4 · Head-sha:
|
Requested by 田騏 · project thread
Fixes #31218
Clause-②: yes
Metadata-protocol: none
维护者速读
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]日志。带错误码的异常照旧。hook 'NAME' threw: Error: …,没有错误码,还暴露 hook 内部名字;同一个中止在 REST 上是400 HOOK_ABORTED。agent 分不清"业务拒绝"和"故障",场景跑分也读不到码。{ 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.tsrendered a thrown error that carries no stringcodeas its bare message (errorResult(messageOf(err))). A QuickJS hook body'sthrow new Error('…')arrives as aSandboxErrorwith nocode, whose.messageis thehook 'NAME' threw: Error: …debug wrapper, so the agent read the wrapper (hook name included) and noErrorCode, while/api/v1/dataanswers the same throw400 HOOK_ABORTEDwith the inner sentence.dataDoorErrorResult(err, tool, objectName), the catch ofquery_records,aggregate_records,get_record, and (throughlandedWriteResultOrError'sotherwise, now a required argument)create_record,update_record,delete_record:thrownRefusalEnvelopeexactly as before (read first);/datadoor's answer,{ "error": { "code", "message", "status" } }, read offmapDataError(err, objectName)(@objectstack/types) bydataDoorAnswerOf. No second classification exists inpackages/mcp;logServerFault([5xx] 500 tools/call update_record task — THROWN-MESSAGE), since its message no longer reaches the agent.rowRefusalOf(the per-row grouping ofdelete_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 samedataDoorAnswerOfinstead of its own inline read ofmapDataError; its answers are unchanged.codedErrorResultaccepts an envelope withoutcode, for a throw that declared a status and no code (the door invents none).@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
mapDataErroron the same throw):/dataSandboxError,innerMessage)hook 'demoleave_leave_request_guard' threw: Error: Not enough annual leave remainingHOOK_ABORTED· 400 ·Not enough annual leave remainingSandboxErrorinstance lost (wrapper text only)HOOK_ABORTED· 400 · inner sentencestatus: 422, no codeHOOK_ABORTED· 422throw new Error(…)INTERNAL_ERROR· 500 ·Internal server error(message logged)TypeError: …)INTERNAL_ERROR· 500callData's{ statusCode: 503, message: 'Data service not available' }Internal server error(message logged){ statusCode: 400, message }, no codeRECORD_LOCKED/ 409) — CONTROLTests
packages/mcp/src/mcp-coded-refusal.test.ts: a new top-level describe (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), in the shared/mcpHTTP harness (rpcOverHttp,bridgeThrowing): the undeclared abort for each of the six tools (hook name andthrewabsent from the text), the lost-instance wrapper, the declared-4xx abort, the 4xx-is-not-logged pin, the bare throw (message withheld, one[5xx]line naming tool and object), the crash, the 503, the declared 400 with no code, the coded CONTROL on every data tool, and a CONTROL that the other tools still answer a code-less throw with its bare message. The mcp: the data tools and the record resource render a coded refusal as its message alone, so a stdio client never reads MFA_REQUIRED (ruling C′ item 1's "same code") or any other refusal's code #23509 table's "code-less throw answers its bare message" row now splits: data tools answer the door's 500, the rest are unchanged. The "not a code" row moves tolist_actions, which still renders that case.packages/mcp/src/mcp-server-runtime.http.test.ts: two pins that threw an uncodedErrorread the new answer. The aggregate pin's fixture becomes the codedPermissionDeniedErrorthe security plugin really throws for that denial (security-plugin-authz-middleware.ts).Base re-measure (order step 1) and ablation
Base re-measure:
mcp-http-tools.tsrestored 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 washook 'demo…(SyntaxError: Unexpected token 'h', "hook 'demo"... is not valid JSON, ×5 tools + the lost-instance row), and the 503 / bare / 400 rows answeredData servi…/Not enough…/aggregate …as bare text. Restored withgit checkout HEAD --,git diff HEADempty.Ablation (one-time,
node scripts/ablation-replace.mjs): indataDoorErrorResult,return codedErrorResult(door);replaced byreturn 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 nodist/is involved.Acceptance notes
throwwithcode+statusin a hook body) answers the wrapper text with the hook name,{ code: 'RECORD_LOCKED', message: "hook 'guard' threw: Error: Locked.", status: 409 }, measured onMCPServerRuntime;/dataanswers the inner sentence.thrownRefusalEnvelopereads.message; the order kept the coded path unchanged.list_objects,describe_object,validate_expression),list_actions, the record resource,run_action/resume_runanddelete_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 containsnot, the unknown-object limb), so it keepserrorResultWithCode.delete_records' fault answer still quotes the faulting row's thrown message.code(SQLITE_BUSY) rides the coded path with its message, where/dataanswers500 INTERNAL_ERROR.logServerFault's, withrequest: { method: 'tools/call', path: 'TOOL OBJECT' }as its coordinates; the MCP tool layer has no HTTP request in hand.Verification
Merged
origin/mainonce before opening (a0f8cfb; the merge touchedpackages/lintandplugin-authtests only).pnpm --filter @objectstack/mcp teston a0f8cfb:Test Files 60 passed (60),Tests 789 passed (789), lockVERDICT command-exit 0.pnpm --filter @objectstack/mcp typecheck: exit 0 (includescheck:test-typecheck, 53 errors / 8 pinned signatures held).pnpm exec eslint --no-inline-configon the three touched.tsfiles: exit 0 (@objectstack/mcphas nolintscript).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 0node scripts/check-adr-0087-registration.mjs --self-test:: exit 0node scripts/check-changeset-no-major.mjs --base origin/main:: exit 0node scripts/check-closing-keyword-parity.mjs:: exit 0node scripts/check-closing-keyword-parity.mjs --self-test:: exit 0node scripts/check-comment-mask-adoption.mjs:: exit 0node scripts/check-comment-mask-adoption.mjs --self-test:: exit 0node scripts/check-comment-mask-corpus.mjs:: exit 0node scripts/check-dts-emitted.mjs --self-test:: exit 0node scripts/check-empty-changeset.mjs --base origin/main:: exit 0node scripts/check-empty-changeset.mjs --self-test:: exit 0node scripts/check-issue-citations.mjs:: exit 0node scripts/check-plugin-teardown-shape.mjs:: exit 0node scripts/check-plugin-teardown-shape.mjs --self-test:: exit 0node scripts/ci/assert-turbo-remote-cache.mjs --self-test:: exit 0node scripts/ci/plan-test-core-shards.mjs --self-test:: exit 0node scripts/ci/prune-turbo-cache.mjs --self-test:: exit 0node scripts/ci/snapshot-next.mjs --self-test:: exit 0node scripts/docs-audit/check-affected-docs.mjs:: exit 0node scripts/docs-audit/check-drift-comment.mjs:: exit 0node scripts/pm/release-rehearsal-clone.mjs --self-test:: exit 0node scripts/release-pending-publish.mjs --self-test:: exit 0pnpm --filter @objectstack/spec run check:duration-unit-keys:: exit 0pnpm check:changeset-gate-self-tests:: exit 0pnpm check:ci-filter-parity:: exit 0pnpm check:closed-ceremony-text:: exit 0pnpm check:cross-package-test-inputs:: exit 0pnpm check:dispatcher-error-vocabulary:: exit 0pnpm check:doc-authoring:: exit 0pnpm check:driver-memory-census:: exit 0pnpm check:dts-closure:: exit 0pnpm check:dual-build-cjs-loads:: exit 0pnpm check:engine-double-contract:: exit 0pnpm check:error-status-conformance:: exit 0pnpm check:gitlink-declared:: exit 0pnpm check:issue-citations:: exit 0pnpm check:keyed-text-bounds:: exit 0pnpm check:lean-entry-closure:: exit 0pnpm check:logger-receiver-detach:: exit 0pnpm check:nul-bytes:: exit 0pnpm check:objectql-double-limit:: exit 0pnpm check:org-identifier:: exit 0pnpm check:page-declaration-shape:: exit 0pnpm check:platform-object-tenancy-census:: exit 0pnpm check:published-files:: exit 0pnpm check:query-options-erasure:: exit 0pnpm check:refd-timer-probe:: exit 0pnpm check:registry-log-declared:: exit 0pnpm check:rest-log-spy-declared:: exit 0pnpm check:slot-lookup:: exit 0pnpm check:sourcemap-no-sources-content:: exit 0pnpm check:system-context-census:: exit 0pnpm check:test-source-alias:: exit 0pnpm check:tier-file-adoption:: exit 0pnpm check:type-check-coverage:: exit 0pnpm check:type-check-debt:: exit 0pnpm check:undeclared-dep-imports:: exit 0pnpm check:vouch-for-reference-callers:: exit 0pnpm check:watch-hint-literal:: exit 0pnpm check:where-matcher:: exit 0node 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
packages/specholds no runtime logic. (Not touched.)pnpm lintpasses. (eslint on the touched files.)main, one pull request.packages/spectouched: its generated artifacts are regenerated and committed. (Not touched.)content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.Generated by Claude Code
🤖 Generated with Claude Code