Skip to content

Commit 60fca0f

Browse files
feat(runtime,mcp)!: a confirmation-gated action never runs on the MCP caller's own confirm — run_action and resume_run hand it to the person (#34202)
domain:server#5 · zhuangjianguo · session_01QsR2jTEivi2wogPpeo3xd5 <!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbTGhxJSYAmQXU7efVdNqrpw)_ Fixes #33690 Clause-②: no (narrowing) Metadata-protocol: semantic Skills-docs: follow-up #34210 ## 维护者速读 - 改了什么:作者声明 `ai.requiresConfirmation: true` 的动作,经 MCP `run_action` / `resume_run` 调用时,不再因调用方自己发的 `confirm: true` 而执行;改为交给宿主的待确认服务(返回待确认编号),没有该服务时拒绝(428,`reason: no_confirmation_service`)。 - 为什么改:AI 自己说“已确认”就能跑高危动作,等于没有确认;裁决要求由本人在应用里确认。 - 风险与回滚:BREAKING——依赖 `confirm: true` 无人值守跑这类动作的脚本/代理会被挂起或拒绝;开源版无该服务,这类调用一律 428。回滚即 revert 本 PR。 - 先看:`packages/runtime/src/action-dispatch.ts`(admitResolvedAction 中新分支,只对 MCP 门生效);`packages/runtime/src/domains/mcp.ts`(resume_run 的移交分支);`packages/runtime/src/action-execution.ts`(handOffActionConfirmation)。 - 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/action-confirmation-handoff-33690.test.ts`,预期 16 个全绿(同一请求发 5 次,执行 0 次、5 个待确认编号)。 - 需要你做的:无,席位落地。 ## What changes **BREAKING** for an MCP client, an agent or a script that runs an action declaring `ai.requiresConfirmation: true` through `run_action` or `resume_run` by sending `confirm: true` itself. Ruled on the card (re-sequencing comment 6890862846): the caller's own `confirm: true` never counts on such a call. The person it runs as confirms it in the app. This implements the hand-off and refusal steps of the amended confirmation contract (`AI_ACTION_CONFIRMATION_CAPABILITY`, the docblock of `packages/spec/src/contracts/ai-service.ts`, read and not edited). No door elicits yet (#33712), so every declared-gated MCP call takes the hand-off. - **Hand-off (MCP door only).** After every admission gate, the subject load and the caller-scope subject verdict included, a declared-gated call goes to the host's `IActionConfirmationService` (registered under `ACTION_CONFIRMATION_SERVICE`) through `submit`. The tool answers `status: 'pending_confirmation'` with the service's `pendingId`, a plain message, `actionName` and `objectName`. That answer is the tool's successful result. Nothing runs, and no `action_invocation` row is written. A `resume_run` hand-off carries `run: { runId, values }`, and the run stays paused. - **No service** (the open-source build ships none): the call is refused `428 ACTION_CONFIRMATION_REQUIRED` with `details.reason: 'no_confirmation_service'`, with or without `confirm: true`. - **A service that answers no `pendingId`** is a fault. The call fails and nothing runs. - **AI service account** acting for itself: refused as before (ADR-0151 D3 rule 3). Its refusal now carries `details.reason: 'service_account'` at every action door. - **Unchanged (bounds):** - REST `/actions` stays outside the gate for a person. - A host's door (`dispatchAction`) under the `ai` posture still reads `confirm`. The hand-off is keyed on the MCP door, not the posture. - The MCP `delete_record` and `delete_records` gates still read `confirm: true`. - `confirm` stays accepted on `run_action` and `resume_run`; it is not read, and its tool text says so. Files: - `packages/runtime/src/action-execution.ts`: - `aiDoorConfirmation` - `resolveActionConfirmationService` - `handOffActionConfirmation` - `refuseDeniedSubjectBeforeHandOff` - the `service_account` reason - `invokeBusinessAction` returns the pending answer. - Runtime wiring: - `action-dispatch.ts`: `confirmationHandOff` on the resolved call, the `handedOff` run outcome, and `handOffAdmittedAction` after the verdict. - `domains/mcp.ts`: `resumeAdmissionRefusal` answers the hand-off step (name kept, ADR-0066 anchors it), and `refuseUnresumableAdmittedRun` is factored out so the hand-off branch runs steps 4 and 5 first. - `packages/mcp/src/mcp-http-tools.ts`: the `run_action` / `resume_run` descriptions teach the pending answer and the refusal. ## Tests - New `packages/runtime/src/action-confirmation-handoff-33690.test.ts` (16 tests): - Sent 5 times with `confirm: true`, the call executes 0 times, and each attempt is held with its own pending id. - The member is not read. - A delegated agent is handed off for its person. - A flow starts no run; a declarative update writes nothing. - A denied record is 404 with no hand-off. - With no service, the call is 428 with the reason. - A missing `pendingId` throws. - An account is refused with `service_account` and nothing is read. - `resume_run`: 5 sends resume 0 times, the run rides the hand-off, and with no service the run stays paused. - CONTROLs: REST `/actions` for a person, the host door under the `ai` posture, and a plain action. - New `packages/mcp/src/mcp-action-confirmation-handoff-33690.test.ts` (4 tests) uses the real MCP HTTP door: - The pending answer is a non-error result. - The no-service envelope keeps `code` + `status` + `details.reason`. - The member stays in both schemas. - New dogfood twin `packages/qa/dogfood/test/action-confirmation-handoff-33690.dogfood.test.ts` runs the real stack, `SecurityPlugin`, MCP over HTTP and a service double. Sent 3 times, the call writes 0 times and is held 3 times for the person. CONTROL: an undeclared action runs at once. - Flipped pins (they encoded the caller's `confirm: true` running the action): - `packages/runtime/src/action-confirmation-gate.test.ts`: the MCP-door describe. - `packages/runtime/src/mcp-resume-run.test.ts`: the confirmed resume, the account details, and the delegated CONTROL. - `packages/runtime/src/action-dispatch.test.ts`: the ADR-0151 D3 rule 3 account details, plus the person and delegated MCP CONTROLs. - `packages/runtime/src/domains/api-action-forward.test.ts`: in the #28943 pair, the gated call is now held. The API-key guard and the session revoke are kept on a twin that declares no confirmation. - `packages/runtime/src/mcp-system-object-action-exposure.test.ts`: the HITL gate test. - `packages/runtime/src/platform-admin-action-gate.test.ts`: the ruling E CONTROL. Gated actions are held for member and admin; ungated ones are unchanged. - `packages/mcp/src/mcp-resume-run-tool.test.ts`: the tool text. - `examples/app-todo/test/mcp-actions.test.ts`: step 7. - `packages/qa/dogfood/test/approval-decide-over-mcp.dogfood.test.ts` - `packages/qa/dogfood/test/approval-read-over-mcp.dogfood.test.ts` - `packages/qa/dogfood/test/mcp-system-object-action-exposure.dogfood.test.ts` ## Acceptance notes - **Approvals over MCP.** On a host without a pending-confirmation service, the approve, reject, recall, send-back and resubmit actions (#32442) are now refused at MCP for a person. That is the ruling: the person decides in the app. - **Pre-forward refusals.** An `api`-typed declared-gated action whose forward would be refused (the `sys_api_key` credential guard, an organization-role endpoint) is now held or refused at the confirmation step before that refusal is reached. The contract places the hand-off after admission and before execution, and those refusals sit in the forward. `list_actions` still marks them unavailable. - **No-service message wording.** The message says to perform the action in the app. It does not name a client that supports confirmation, because no door elicits yet (#33712). - **Stale served text.** The served skill text (`packages/mcp/src/skill-md.ts`, and its mirror `ui/apps/console/src/pages/developer/objectstack-skill.ts`) and `TOOL_RETIRED_KEY_GUIDANCE` in `packages/spec/src/ai/tool.zod.ts` still teach `confirm: true` for `run_action`. The mirror is outside this card's surface, so this is reported for follow-up. `Skills-docs:` above names the published skills. - **Grader.** `packages/qa/scenarios/src/runner/observe.ts` rule 1 reads a successful write call as `applied`, so a hand-off answer would be graded `applied` on a host that registers the service. No open-source stack registers one. This is reported for follow-up. ## Verification Final head `292c638502`. Every family CI runs is read from this PR's check-runs, not re-run here. <details><summary>Focused pins and suites</summary> - `pnpm --filter @objectstack/runtime exec vitest run` (whole package) at `2266f4da70`, the last source commit before the main merge: Test Files 610 passed (610), Tests 12430 passed, 19 skipped. RUNTIME_EXIT=0. - `pnpm --filter @objectstack/mcp exec vitest run` (whole package) at `2266f4da70`: Test Files 66 passed (66), Tests 1189 passed (1189). MCP_EXIT=0. - The four runtime files whose pins flipped last, plus `mcp-resume-run-tool.test.ts`: Test Files 4 passed (4), Tests 160 passed; Test Files 1 passed (1), Tests 10 passed. - At `292c638502`, re-run after the test-only commits that followed the battery: - The five touched dogfood files (the hand-off twin, `mcp-delete-record-confirmation`, the two approvals files, and the system-object exposure file): Test Files 5 passed (5), Tests 35 passed (35). - `src/mcp-system-object-action-exposure.test.ts`: Test Files 1 passed (1), Tests 11 passed (11). - `@objectstack/example-todo` test, `@objectstack/runtime` typecheck (with `check:test-typecheck`) and `@objectstack/mcp` typecheck all exit 0 at `56a42d81e2`, after the closure build exited 0. - eslint `--no-inline-config` on every changed `.ts` file: exit 0. </details> <details><summary>Ablation: put the caller's confirm back as the confirmation</summary> Both legs used `node scripts/ablation-replace.mjs`, which checks that the anchor hits, that the mutation lands on disk, and that the restore matches the blob at HEAD. - **A1**, `packages/runtime/src/action-execution.ts`: - Mutation: `confirmationHandOff: { door: 'mcp', … }` was replaced with `confirmation: input`. Anchor x1 to x0; blob `fa5e3071e0da` to `93e90f85b005`. - Result: `action-confirmation-handoff-33690.test.ts` went red, Tests 6 failed, 10 passed. Among the failures: "the same request with confirm: true, sent 5 times, executes 0 times and is held 5 times with a pending id", "holds the call with the member and without it alike", and "no service registered: refused 428 … reason no_confirmation_service". - Restore: blob back to `fa5e3071e0da`; `git diff HEAD` empty. - **A2**, `packages/runtime/src/domains/mcp.ts`: - Mutation: `if (handOff) {` was replaced with `if (handOff && (input as any)?.confirm !== true) {`. Blob `0be1c84eed37` to `a50361d0cffd`. - Result: red, Tests 2 failed, 14 passed. The failures were "confirm: true sent 5 times resumes 0 times; each call is held with a pending id carrying its run and values" and "no service registered: refused 428, reason no_confirmation_service, and the run stays paused". - Restore: blob back to `0be1c84eed37`; `git diff HEAD` empty. - After both legs, `git diff HEAD` measured 0 bytes. </details> <details><summary>Full dogfood battery (the title carries a bang)</summary> - Run at `56a42d81e2` under the verify lock (VERDICT command-exit 0 for the batch; DOGFOOD=1): Test Files 2 failed, 466 passed, 3 skipped (471); Tests 1 failed, 3959 passed, 42 skipped (4002). - Both reds were consequences of this change, and both are fixed in this PR by test-only commits: - The new twin's `ai.description` was under the 40-character floor. That made a ZodError at collection. - `mcp-delete-record-confirmation.dogfood.test.ts` compared the delete gate's detail keys with `run_action`'s, which now carry `reason`. The pin now leaves `reason` aside and asserts that the delete gate carries none, per the bounds. - Both files were re-run green at `292c638502` (above). The battery was not re-run end to end after those two test-only commits, and CI runs it. </details> <details><summary>Gates</summary> - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`: 74 families derived at `292c638502`. 72 ran with exit 0. - Two are NOT MEASURED: - `check:dual-build-cjs-loads`: exit 3, PREREQUISITE NOT MET, because there is no full workspace build here. - `check:type-check-debt`: a lock queue-timeout, and then the re-measure was killed by my own timeout wrapper. - `--ran` reconciliation: "74 derived famil(ies) accounted for — 72 run, 2 NOT-MEASURED", exit 0. - `node scripts/check-platform-checklist.mjs --changed-from origin/main`: OK, 29 anchors judged, 0 lost. - Body gates run before opening: - `check-changeset-no-major --event`: exit 0, narrowing arm, `Metadata-protocol: semantic`. - `check-adr-0087-registration`: exit 0, not-required (already-registered). - `check-partof-closing-keyword`: exit 0. - `check-closing-keyword-parity --body`: binds only the card named on line 4 of this body. - `git merge-tree --write-tree` is clean against origin/main and against the head of the open spec PR that edits `ai-service.ts`. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5 --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 109a903 commit 60fca0f

20 files changed

Lines changed: 1360 additions & 293 deletions
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
'@objectstack/runtime': minor
3+
'@objectstack/mcp': minor
4+
---
5+
6+
feat(runtime,mcp)!: an action declaring `ai.requiresConfirmation: true` never runs on the MCP caller's own `confirm: true` — `run_action` and `resume_run` hand it to the person in the app
7+
8+
Clause-②: no (narrowing)
9+
Metadata-protocol: semantic
10+
Skills-docs: follow-up #34210
11+
12+
<!-- adr-0087: not-required (already-registered action-requires-confirmation-elicited) The semantic entry registered with the contract already carries this move to the upgrade guide and os migrate meta: no key is added, removed or re-shaped, and nothing an author wrote is rewritten. -->
13+
14+
**BREAKING** for an MCP client, an agent or a script that runs an action declaring `ai.requiresConfirmation: true` through the `run_action` or `resume_run` tool by sending `confirm: true` itself. Ruled by the account owner on the safety fix: the caller's own `confirm: true` never counts on such a call; the person it runs as confirms it in the app.
15+
16+
This release implements the hand-off and refusal steps of the amended confirmation contract (`AI_ACTION_CONFIRMATION_CAPABILITY`, `@objectstack/spec/contracts`). The MCP doors do not elicit in the client yet: every declared-gated call takes the hand-off, whatever the client advertised.
17+
18+
- After every admission gate, the subject load and the caller-scope subject verdict included, a declared-gated call is handed to the host's pending-confirmation service (`IActionConfirmationService`, registered under `ACTION_CONFIRMATION_SERVICE` = `'ai.actionConfirmation'`) through its `submit` member, and the call is answered with `status: 'pending_confirmation'`, the service's `pendingId`, a plain message, `actionName` and `objectName`. That answer is the tool's successful result. Nothing runs, and no `action_invocation` row is written. A `resume_run` hand-off carries its run (`run: { runId, values }`) and the run stays paused; approving it is the host's, as is what happens after.
19+
- A host that registers no such service (the open-source build ships none) refuses the call `428 ACTION_CONFIRMATION_REQUIRED` with `details.reason: 'no_confirmation_service'`, with or without `confirm: true`. The person performs the action in the app.
20+
- A service that answers no `pendingId` is a fault: the call fails and nothing runs.
21+
- An AI service account acting for itself is refused whatever it sends, as before (ADR-0151 D3 rule 3). Its refusal now carries `details.reason: 'service_account'` at every action door, REST `/actions` and a host's door included.
22+
- Unchanged: REST `/actions` stays outside the gate for a person; a host's door (`dispatchAction`) under the `ai` posture still reads `confirm`; the MCP `delete_record` and `delete_records` gates still read `confirm: true`. The `confirm` member stays accepted on `run_action` and `resume_run` and is not read.
23+
24+
What changes for a caller:
25+
26+
- FROM confirm with the person yourself, then send `confirm: true` on `run_action` / `resume_run` TO relay the pending answer's message and let the person approve it in the app; do not retry the call.
27+
- FROM a script or agent that runs a gated action unattended with `confirm: true` TO a pending answer the person decides in the app, or the `no_confirmation_service` refusal on a host without the service. Where the action is safe unattended, its author declares `ai.requiresConfirmation: false`.
28+
- A host that wants its people to approve these calls registers an `IActionConfirmationService` under `ACTION_CONFIRMATION_SERVICE`.

‎examples/app-todo/test/mcp-actions.test.ts‎

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ describe('app-todo business actions over MCP (CE runtime, no service-ai)', () =>
227227
// bridge never sees the runtime gate. Here the member travels from a real
228228
// JSON-RPC `tools/call`, through both of those layers, into the real gate —
229229
// and the record afterwards says whether anything ran.
230-
it('step 7: ai.requiresConfirmation is ENFORCED, and satisfiable', async () => {
230+
it('step 7: ai.requiresConfirmation is ENFORCED, and the caller\'s confirm: true never satisfies it', async () => {
231231
// Same app, but todo_complete_task now declares the author's gate.
232232
const gatedConfirmObjects = withTaskAction(mergedObjects, 'todo_complete_task', (a) => ({
233233
...a,
@@ -241,23 +241,21 @@ describe('app-todo business actions over MCP (CE runtime, no service-ai)', () =>
241241

242242
const gatedId = await seedTask('Needs a human');
243243

244-
// 7a — WITHOUT the member: refused, with the declared code, and NOTHING ran.
245-
const refused = await callMcp(confirmBridge, toolsCall(12, 'run_action', { actionName: 'todo_complete_task', recordId: gatedId }));
246-
expect(refused.result?.isError).toBe(true);
247-
const refusedEnvelope = JSON.parse(refused.result?.content?.[0]?.text ?? '{}');
248-
expect(refusedEnvelope?.error?.code).toBe('ACTION_CONFIRMATION_REQUIRED');
249-
expect(refusedEnvelope?.error?.status).toBe(428);
250-
expect(refusedEnvelope?.error?.details?.actionName).toBe('todo_complete_task');
251-
expect(refusedEnvelope?.error?.details?.confirmationMember).toBe('confirm');
252-
expect(await statusOf(gatedId)).toBe('not_started');
253-
254-
// 7b — WITH the member: the identical call succeeds and the handler runs.
255-
// This is the leg that proves the member is not stripped: before the door
256-
// grew it, this call was refused exactly like 7a and the action was
257-
// permanently un-invokable.
258-
const confirmed = await callMcp(confirmBridge, toolsCall(13, 'run_action', { actionName: 'todo_complete_task', recordId: gatedId, confirm: true }));
259-
expect(confirmed.result?.isError, confirmed.result?.content?.[0]?.text).not.toBe(true);
260-
expect(await statusOf(gatedId)).toBe('completed');
244+
// 7a/7b — [#33690] WITH the member and WITHOUT it alike: this app registers
245+
// no pending-confirmation service, so the call is refused with the
246+
// declared code and `details.reason: 'no_confirmation_service'`, and
247+
// NOTHING ran. Before the amended contract 7b (with `confirm: true`) ran
248+
// the handler; the member now travels the whole path and confers nothing.
249+
for (const [id, extra] of [[12, {}], [13, { confirm: true }]] as const) {
250+
const refused = await callMcp(confirmBridge, toolsCall(id, 'run_action', { actionName: 'todo_complete_task', recordId: gatedId, ...extra }));
251+
expect(refused.result?.isError).toBe(true);
252+
const refusedEnvelope = JSON.parse(refused.result?.content?.[0]?.text ?? '{}');
253+
expect(refusedEnvelope?.error?.code).toBe('ACTION_CONFIRMATION_REQUIRED');
254+
expect(refusedEnvelope?.error?.status).toBe(428);
255+
expect(refusedEnvelope?.error?.details?.actionName).toBe('todo_complete_task');
256+
expect(refusedEnvelope?.error?.details?.reason).toBe('no_confirmation_service');
257+
expect(await statusOf(gatedId)).toBe('not_started');
258+
}
261259

262260
// 7c — the heuristic must NOT gate: todo_delete_completed is `variant:'danger'`
263261
// and the listing calls it requiresConfirmation, but its author declared
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#33690] The `run_action` and `resume_run` tools relay the amended
5+
* confirmation contract's two answers through the real MCP door
6+
* (`MCPServerRuntime.handleHttpRequest`, JSON-RPC `tools/call`):
7+
*
8+
* - a hand-off (`ActionConfirmationPending`, `status: 'pending_confirmation'`)
9+
* is the call's SUCCESSFUL answer: not an error result, the pending id and
10+
* message intact, so an agent tells its person where to approve;
11+
* - the `no_confirmation_service` refusal keeps the registered envelope
12+
* (`428 ACTION_CONFIRMATION_REQUIRED`) with `details.reason`.
13+
*
14+
* The bridge is a double standing in for the runtime door, whose hand-off is
15+
* pinned in `packages/runtime/src/action-confirmation-handoff-33690.test.ts`;
16+
* this package asserts the tool's half (relay, envelope) without depending on
17+
* `@objectstack/runtime`, which deliberately does not depend back.
18+
*/
19+
20+
import { describe, it, expect } from 'vitest';
21+
22+
import { AI_ACTION_CONFIRMATION_MEMBER, type ActionConfirmationPending } from '@objectstack/spec/contracts';
23+
24+
import { MCPServerRuntime } from './mcp-server-runtime.js';
25+
import type { McpDataBridge, McpActionBridge } from './mcp-http-tools.js';
26+
27+
const GATED = 'archive_account';
28+
29+
const pendingOf = (n: number): ActionConfirmationPending => ({
30+
status: 'pending_confirmation',
31+
pendingId: `pa_${n}`,
32+
message: `Action '${GATED}' on 'account' declares ai.requiresConfirmation: true, so a person confirms it. Pending confirmation: pa_${n}.`,
33+
actionName: GATED,
34+
objectName: 'account',
35+
});
36+
37+
const NO_SERVICE = () => Object.assign(
38+
new Error(`Action '${GATED}' on 'account' declares ai.requiresConfirmation: true, so a person confirms it — nothing was run.`),
39+
{
40+
code: 'ACTION_CONFIRMATION_REQUIRED',
41+
status: 428,
42+
details: { actionName: GATED, objectName: 'account', confirmationMember: AI_ACTION_CONFIRMATION_MEMBER, reason: 'no_confirmation_service' },
43+
},
44+
);
45+
46+
function makeBridge(mode: 'service' | 'none'): McpDataBridge & McpActionBridge & { calls: any[] } {
47+
const calls: any[] = [];
48+
let n = 0;
49+
const answer = async () => {
50+
if (mode === 'none') throw NO_SERVICE();
51+
return pendingOf(++n);
52+
};
53+
return {
54+
calls,
55+
async listObjects() { return []; },
56+
async describeObject() { return null; },
57+
async query() { return { records: [] }; },
58+
async get() { return null; },
59+
async create() { return {}; },
60+
async update() { return {}; },
61+
async remove() { return {}; },
62+
async listActions() {
63+
return [{ name: GATED, objectName: 'account', type: 'script', requiresRecord: true, requiresConfirmation: true }];
64+
},
65+
async runAction(name: string, input: any) {
66+
calls.push(['runAction', name, input]);
67+
return answer();
68+
},
69+
async resumeRun(runId: string, input: any) {
70+
calls.push(['resumeRun', runId, input]);
71+
return answer();
72+
},
73+
};
74+
}
75+
76+
function mcpRequest(body: unknown): Request {
77+
return new Request('http://localhost/api/v1/mcp', {
78+
method: 'POST',
79+
headers: { 'content-type': 'application/json', accept: 'application/json, text/event-stream' },
80+
body: JSON.stringify(body),
81+
});
82+
}
83+
84+
const toolsCall = (id: number, name: string, args: Record<string, unknown>) => ({
85+
jsonrpc: '2.0', id, method: 'tools/call', params: { name, arguments: args },
86+
});
87+
88+
async function call(bridge: McpDataBridge & McpActionBridge, body: unknown): Promise<any> {
89+
const runtime = new MCPServerRuntime({ name: 'objectstack-test', version: '9.9.9' });
90+
const res = await runtime.handleHttpRequest(mcpRequest(body), { bridge, parsedBody: body });
91+
return res.json();
92+
}
93+
94+
describe('[#33690] run_action and resume_run relay a hand-off as the call\'s successful answer', () => {
95+
it('run_action: each confirm: true call answers pending_confirmation with its own pending id, never an error', async () => {
96+
const bridge = makeBridge('service');
97+
for (let i = 1; i <= 3; i++) {
98+
const json = await call(bridge, toolsCall(i, 'run_action', { actionName: GATED, recordId: 'a1', [AI_ACTION_CONFIRMATION_MEMBER]: true }));
99+
expect(json.result.isError).toBeFalsy();
100+
expect(JSON.parse(json.result.content[0].text)).toEqual(pendingOf(i));
101+
}
102+
});
103+
104+
it('resume_run: the hand-off is relayed the same way', async () => {
105+
const bridge = makeBridge('service');
106+
const json = await call(bridge, toolsCall(1, 'resume_run', { runId: 'run_1', values: { reason: 'x' }, [AI_ACTION_CONFIRMATION_MEMBER]: true }));
107+
expect(json.result.isError).toBeFalsy();
108+
expect(JSON.parse(json.result.content[0].text)).toEqual(pendingOf(1));
109+
expect(bridge.calls[0]).toEqual(['resumeRun', 'run_1', { values: { reason: 'x' }, [AI_ACTION_CONFIRMATION_MEMBER]: true }]);
110+
});
111+
112+
it('no service: the refusal keeps the registered envelope and carries details.reason', async () => {
113+
for (const [tool, args] of [
114+
['run_action', { actionName: GATED, recordId: 'a1', [AI_ACTION_CONFIRMATION_MEMBER]: true }],
115+
['resume_run', { runId: 'run_1', [AI_ACTION_CONFIRMATION_MEMBER]: true }],
116+
] as const) {
117+
const json = await call(makeBridge('none'), toolsCall(1, tool, args));
118+
expect(json.result.isError, tool).toBe(true);
119+
const envelope = JSON.parse(json.result.content[0].text);
120+
expect({ code: envelope.error.code, status: envelope.error.status }, tool).toEqual({ code: 'ACTION_CONFIRMATION_REQUIRED', status: 428 });
121+
expect(envelope.error.details, tool).toEqual({
122+
actionName: GATED, objectName: 'account', confirmationMember: AI_ACTION_CONFIRMATION_MEMBER, reason: 'no_confirmation_service',
123+
});
124+
}
125+
});
126+
127+
it('the member stays accepted on both tools, so a call carrying it is not refused for it', async () => {
128+
const json = await call(makeBridge('service'), { jsonrpc: '2.0', id: 1, method: 'tools/list' });
129+
for (const name of ['run_action', 'resume_run']) {
130+
const tool = json.result.tools.find((t: any) => t.name === name);
131+
expect(tool?.inputSchema.properties[AI_ACTION_CONFIRMATION_MEMBER]?.type, name).toBe('boolean');
132+
}
133+
});
134+
});

‎packages/mcp/src/mcp-http-tools.ts‎

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@ export interface McpActionBridge {
431431
* as the caller, loads the subject record under RLS when row-context, then
432432
* dispatches through the framework action runner. Throws on
433433
* denial / not-found / handler failure so the tool surfaces a tool-error.
434+
* [#33690] An action declaring `ai.requiresConfirmation: true` is not run:
435+
* the host hands it to the person and resolves to the contract's
436+
* `ActionConfirmationPending` (`status: 'pending_confirmation'`), which the
437+
* tool relays as its successful result; the request's `confirm` is not read.
434438
*/
435439
runAction(
436440
name: string,
@@ -469,7 +473,9 @@ export interface McpActionBridge {
469473
* caller, and the run is parked on a screen. Resolves to `runAction`'s
470474
* envelope (`{ ok, action, objectName, recordId?, result }`). A run that
471475
* pauses on its next screen comes back paused again. Throws on refusal, with
472-
* the ADR-0112 `code` / `status` on the thrown value.
476+
* the ADR-0112 `code` / `status` on the thrown value. [#33690] A resume of a
477+
* gated action resolves to `ActionConfirmationPending` instead, as
478+
* {@link runAction} does, and the run stays parked.
473479
*
474480
* OPTIONAL, like {@link McpDataBridge.aggregate}. A host that cannot resume
475481
* runs omits it, and `resume_run` is then not registered.
@@ -3364,10 +3370,16 @@ export function registerActionTools(
33643370
'this can mutate data or trigger flows. Invocation is gated (author AI opt-in + your capabilities), ' +
33653371
'but the action body itself runs as trusted application code with the app\'s full data authority. ' +
33663372
'Supply recordId for actions that operate on a specific record, and params for any declared inputs. ' +
3367-
'An action the author gated (list_actions reports requiresConfirmation) is REFUSED unless you also ' +
3368-
'send confirm: true — ask the human first, then retry; nothing runs on a refused call. ' +
3369-
// [ADR-0151 D3 rule 3] `actionConfirmationRefusal` (runtime) never reads
3370-
// the member for an AI service account, so no retry is taught to one.
3373+
// [#33690] The amended confirmation contract: the caller's `confirm`
3374+
// never counts on an action whose author declared
3375+
// `ai.requiresConfirmation: true`; the person is asked in the app.
3376+
'An action its author declared ai.requiresConfirmation: true never runs on this call, and confirm: true ' +
3377+
'does not change that: the call is handed to the person you act for, who approves or rejects it in ' +
3378+
'the app, and you are answered status "pending_confirmation" with a pendingId and a message to pass on. ' +
3379+
'Nothing has run then; do not retry, tell the user to approve it. Where the server cannot hand it off, ' +
3380+
'the call is refused ACTION_CONFIRMATION_REQUIRED (details.reason "no_confirmation_service"): the user ' +
3381+
'performs the action in the app. ' +
3382+
// [ADR-0151 D3 rule 3] An AI service account is refused, never handed off.
33713383
'Under an AI service account\'s own key (an agent acting for itself, for no person) the call is ' +
33723384
'refused whatever it sends and nothing runs: hand the action to a person, or its author declares ' +
33733385
'ai.requiresConfirmation: false when it is safe unattended. ' +
@@ -3446,11 +3458,9 @@ export function registerActionTools(
34463458
.boolean()
34473459
.optional()
34483460
.describe(
3449-
'Set to true to confirm a call the app author gated with ai.requiresConfirmation '
3450-
+ '(list_actions reports requiresConfirmation for each action). Assert this only when '
3451-
+ 'the human in the loop has approved THIS call; without it a gated action is refused '
3452-
+ 'and nothing runs. Under an AI service account\'s own key it is not read: the call is '
3453-
+ 'refused whatever it sends.',
3461+
'Not read by this tool: an action its author declared ai.requiresConfirmation: true is handed '
3462+
+ 'to the person to approve in the app whatever this member says, and any other action runs '
3463+
+ 'without it. Accepted so that a call carrying it is not refused for it.',
34543464
),
34553465
},
34563466
),
@@ -3545,9 +3555,12 @@ export function registerActionTools(
35453555
'pauses again on its NEXT screen with a new screen to fill (call resume_run again for it). Only ' +
35463556
'the user whose call started the run can resume it, and it is gated exactly as run_action is ' +
35473557
'(author AI opt-in, your capabilities, your read access to the record). The rest of the flow runs ' +
3548-
'the app\'s business logic and can mutate data. When list_actions reports requiresConfirmation for ' +
3549-
'the action that started the run, send confirm: true (ask the human first); without it the call ' +
3550-
'is refused and the run stays paused. Under an AI service account\'s own key the call is refused ' +
3558+
'the app\'s business logic and can mutate data. When the action that started the run was declared ' +
3559+
'ai.requiresConfirmation: true, the run does not continue on this call and confirm: true does not ' +
3560+
'change that: it is handed to the person you act for, who approves or rejects it in the app, and you ' +
3561+
'are answered status "pending_confirmation" with a pendingId; the run stays paused until they ' +
3562+
'approve. Where the server cannot hand it off, the call is refused ACTION_CONFIRMATION_REQUIRED and ' +
3563+
'the run stays paused. Under an AI service account\'s own key the call is refused ' +
35513564
'whatever it sends and the run stays paused: hand it to a person. A run that fails answers as ' +
35523565
'run_action does: tell the user the reason in the second text block, never the flow and node chain ' +
35533566
'in the error message.',
@@ -3589,11 +3602,9 @@ export function registerActionTools(
35893602
.boolean()
35903603
.optional()
35913604
.describe(
3592-
'Set to true to confirm resuming a run of an action the app author gated with '
3593-
+ 'ai.requiresConfirmation (list_actions reports requiresConfirmation). Assert this only when '
3594-
+ 'the human in the loop has approved THIS call; without it the call is refused and the run '
3595-
+ 'stays paused. Under an AI service account\'s own key it is not read: the call is refused '
3596-
+ 'whatever it sends.',
3605+
'Not read by this tool: a resume of a run whose action was declared ai.requiresConfirmation: '
3606+
+ 'true is handed to the person to approve in the app whatever this member says. Accepted so '
3607+
+ 'that a call carrying it is not refused for it.',
35973608
),
35983609
},
35993610
),

0 commit comments

Comments
 (0)