Repository navigation
fix(mcp): a coded sandboxed hook refusal answers the body's sentence, not the wrapper naming the hook - #31268
Conversation
…the wrapper naming the hook thrownRefusalEnvelope reads the caller-addressed sentence through sandboxBusinessMessage (@objectstack/types), the read the /api/v1/data door makes, and the record resource renders the envelope's message. Code and status are unchanged; a coded non-sandbox refusal keeps its message. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5oWCPWH6i2Lsts9cdP
📓 Docs Drift Check2 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run. 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 acedf75f1cb1d39de836767d31bf64b403282dd7 && git checkout acedf75f1cb1d39de836767d31bf64b403282dd7
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 8f4e8fb9def634d62d9f7d418a9707f4bc400f25 a8855476e91d945fefd9f5b2d6f1365e84a78be1 && git checkout -B drift-repro 8f4e8fb9def634d62d9f7d418a9707f4bc400f25 && git merge --no-ff a8855476e91d945fefd9f5b2d6f1365e84a78be1
node scripts/docs-audit/affected-docs.mjs --json 8f4e8fb9def634d62d9f7d418a9707f4bc400f25 |
|
domain:server#6 · os-project-manager · session_01FEkQ5p3T5YWhLjurajudnQ 席位核对 · ACCEPT · 2026-11-07T21:37Z · head
|
Requested by Leehom · project thread
Fixes #31246
Clause-②: no
Metadata-protocol: none
维护者速读
Locked.),错误码和状态码不变;读法用/api/v1/data同一个函数sandboxBusinessMessage,没有复制逻辑。hook 'NAME' threw: Error: Locked.,把 hook 内部名字暴露给 agent;REST 对同一个拒绝只回那句话。@objectstack/mcp的两处读法,patch;非沙箱的带码拒绝逐字不变,沙箱里崩溃的主体也保持原样。回滚即还原这两处。packages/mcp/src/mcp-http-tools.ts的thrownRefusalEnvelope;packages/mcp/src/mcp-server-runtime.ts记录资源的 catch;packages/mcp/src/mcp-coded-refusal.test.ts的 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 块。pnpm --filter @objectstack/mcp exec vitest run src/mcp-coded-refusal.test.ts -t 31246,预期 16 个用例全部通过。What changes
A QuickJS hook or action body that runs
throw Object.assign(new Error('Locked.'), { code: 'RECORD_LOCKED', status: 409 })leaves the runner as aSandboxErrorwithmessage=hook 'NAME' threw: Error: Locked.,innerMessage=Locked.,codeandstatusas declared (measured on the realQuickJSScriptRunneratmain169ff7e). MCP renderedmessage, so the agent read the hook's internal name;/api/v1/dataanswers409 RECORD_LOCKEDwithLocked.(mapDataError→armSentence→sandboxBusinessMessage).thrownRefusalEnvelope(packages/mcp/src/mcp-http-tools.ts) readsmessageassandboxBusinessMessage(err) ?? messageOf(err).sandboxBusinessMessageis the one reader in@objectstack/typesthat the/datadoor uses; there is no second copy of its logic inpackages/mcp. The code and status are unchanged.MCPServerRuntime.bridgeResources,packages/mcp/src/mcp-server-runtime.ts) answered a coded refusal with its ownerr.message. It now uses the envelope'smessage, so it gives the same sentence as the tools. The code-less{ error }answer is unchanged.The envelope is the one reader, so every face that renders a coded refusal moves together: the 13 tools (
list_objects,describe_object,validate_expression, the six record data tools,delete_records,list_actions,run_action,resume_run), the per-row grouping ofdelete_records(rowRefusalOf), the record resource, and the object resources' coded refusal (objectResourceRefusal)./api/v1/dataRECORD_LOCKED/409, innerLocked.)RECORD_LOCKED·hook 'demo_guard' threw: Error: Locked.· 409RECORD_LOCKED·Locked.· 409RECORD_LOCKED·Locked.· 409Tests
packages/mcp/src/mcp-coded-refusal.test.ts: a new#31246describe on the shared/mcpHTTP harness. Each of the 13 tools (theSITEStable, which is held equal to the registered tool list) answers the coded sandboxed refusal with{ code: 'RECORD_LOCKED', message: INNER_SENTENCE, status: 409 }. Each case also checks that this equalsmapDataError's answer to the same throw, and that the hook name andthreware absent. CONTROL: three coded non-sandbox throws (a plain sentence, a sentence that reads like the wrapper, and aSandboxErrorwith an emptyinnerMessage) render byte for byte asJSON.stringify({ error: { code, message, status } }, null, 2). In the record-resource describe: the coded sandboxed refusal answers{ error: INNER_SENTENCE, code, status }, and a CONTROL keeps a coded non-sandbox wrapper-like sentence.packages/mcp/src/mcp-delete-records.test.ts: a coded sandboxed row refusal is grouped as{ code: 'RECORD_LOCKED', status: 409, reason: INNER_SENTENCE }, and the call goes on.Red first and ablations
Red first on
bdefd49f(after PR #31245 merged, before the fix): the two files answeredTests 15 failed | 91 passed (106). The 13 tool rows, the resource row and thedelete_recordsrow failed; the CONTROLs passed. After the fix:Tests 106 passed (106).Ablation 1 (
node scripts/ablation-replace.mjs,mcp-http-tools.ts):message: sandboxBusinessMessage(err) ?? messageOf(err),replaced bymessage: messageOf(err) as string,. Output:ok mutation landed: anchor 1 -> 0, blob 9cca1c033a19 -> 58b6b2bf2013, thenTests 15 failed | 91 passed (106), thenok restored: blob == HEAD (9cca1c033a19) and git diff HEAD is empty.Ablation 2 (
mcp-server-runtime.ts):error: envelope.message,replaced byerror: message as string,. Output:ok mutation landed: anchor 1 -> 0, blob 38c17f5605e4 -> c385c405c4f1, thenTests 1 failed | 105 passed (106)(the resource row only), thenok restored: blob == HEAD (38c17f5605e4).The tests import the package's source, so no
dist/is involved.Acceptance notes
Item 2 of the card: each listed face was measured against the REST door that serves the same verb, using five throws: V1 coded sandboxed refusal, V2 code-less sandboxed abort, V3 bare
Error, V4 driver string codeSQLITE_BUSY, V5 coded sandboxed crash (innerTypeError: boom, codeRECORD_LOCKED, status 409; the real runner's shape). MCP was measured over/mcpon this branch with a bridge member throwing each value. REST was measured with the door's own responder:mapDataErrorfor/data,handleRouteErrorfor/meta, and the runtimeHttpDispatcher.handleActionsfor/actions.RECORD_LOCKED·hook 'demo_guard' threw: TypeError: boom· 409/data,/meta:500 INTERNAL_ERRORInternal server error;/actions: 500INTERNAL_ERRORsandboxBusinessMessagedeclines a crash by contract); findinglist_actionssocket hang up/meta:500 INTERNAL_ERRORInternal server errorlist_actionsSQLITE_BUSY· driver text/meta:500 DATABASE_ERRORInternal data error{ error: "hook 'demo_guard' threw: Error: Not enough leave" }/data:400 HOOK_ABORTEDNot enough leave{ error: 'socket hang up' }/{ error, code: 'SQLITE_BUSY' }500 INTERNAL_ERROR/500 DATABASE_ERRORrun_action/resume_run/actions:400 HOOK_ABORTEDinner sentencerun_action/resume_run/actions:400 VALIDATION_ERRORsame textrun_action/resume_runSQLITE_BUSY· text, no status/actions:400 VALIDATION_ERROR· text ·declaredCode: SQLITE_BUSYSQLITE_BUSY· driver text, no status (coded path is read first)/data:500 DATABASE_ERRORInternal data errorHOOK_ABORTED400 /INTERNAL_ERROR500delete_recordsouter catchKept as intended:
delete_records' outer catch stays onerrorResultWithCode. It also renders this file's own code-less sentences (delete_records could not read the records the query on 'OBJ' answered), whichmapDataError's unknown-object heuristic would misread as404 OBJECT_NOT_FOUND(the PR #31245 note). Its fault answer still quotes the faulting row's thrown message, asmcp-delete-records.test.tspins on purpose. Each divergence above is listed for the seat to file, one card per face.Verification
Base:
bdefd49f(main, with PR #31245 merged); head:a8855476.pnpm --filter @objectstack/mcp test:Test Files 60 passed (60),Tests 806 passed (806), 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 four touched.tsfiles: exit 0 (@objectstack/mcphas nolintscript).Derived gates (node scripts/pm/dispatch-gates.mjs --commands, 60 commands, all on a885547)
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:60 derived famil(ies) accounted for — 60 run, 0 NOT-MEASURED. Two gates first exited 3 on a prerequisite and were re-run after it was met:check-plugin-teardown-shape --self-test(shallow clone; fetched its pinned fixture commit) andcheck:dual-build-cjs-loads(needed every package's dist, built bycheck:type-check-debt). Both then exited 0.Not run locally (CI's):
test:repo, the dogfood shards, 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 with Claude Code
https://claude.ai/code/session_01FEkQ5oWCPWH6i2Lsts9cdP