Repository navigation
Commit 60fca0f
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
File tree
- .changeset
- examples/app-todo/test
- packages
- mcp/src
- qa/dogfood/test
- runtime/src
- domains
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
230 | | - | |
| 230 | + | |
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
261 | 259 | | |
262 | 260 | | |
263 | 261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
431 | 431 | | |
432 | 432 | | |
433 | 433 | | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
434 | 438 | | |
435 | 439 | | |
436 | 440 | | |
| |||
469 | 473 | | |
470 | 474 | | |
471 | 475 | | |
472 | | - | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
473 | 479 | | |
474 | 480 | | |
475 | 481 | | |
| |||
3364 | 3370 | | |
3365 | 3371 | | |
3366 | 3372 | | |
3367 | | - | |
3368 | | - | |
3369 | | - | |
3370 | | - | |
| 3373 | + | |
| 3374 | + | |
| 3375 | + | |
| 3376 | + | |
| 3377 | + | |
| 3378 | + | |
| 3379 | + | |
| 3380 | + | |
| 3381 | + | |
| 3382 | + | |
3371 | 3383 | | |
3372 | 3384 | | |
3373 | 3385 | | |
| |||
3446 | 3458 | | |
3447 | 3459 | | |
3448 | 3460 | | |
3449 | | - | |
3450 | | - | |
3451 | | - | |
3452 | | - | |
3453 | | - | |
| 3461 | + | |
| 3462 | + | |
| 3463 | + | |
3454 | 3464 | | |
3455 | 3465 | | |
3456 | 3466 | | |
| |||
3545 | 3555 | | |
3546 | 3556 | | |
3547 | 3557 | | |
3548 | | - | |
3549 | | - | |
3550 | | - | |
| 3558 | + | |
| 3559 | + | |
| 3560 | + | |
| 3561 | + | |
| 3562 | + | |
| 3563 | + | |
3551 | 3564 | | |
3552 | 3565 | | |
3553 | 3566 | | |
| |||
3589 | 3602 | | |
3590 | 3603 | | |
3591 | 3604 | | |
3592 | | - | |
3593 | | - | |
3594 | | - | |
3595 | | - | |
3596 | | - | |
| 3605 | + | |
| 3606 | + | |
| 3607 | + | |
3597 | 3608 | | |
3598 | 3609 | | |
3599 | 3610 | | |
| |||
0 commit comments