Skip to content

Commit 99992dd

Browse files
feat(runtime): one admitted action sequence, exported as dispatchAction for a host's own action door (#32032)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9MXxr73rZnwBvPkBEGg21ES)_ Fixes #31923 Clause-②: yes (narrowing) Metadata-protocol: none Skills-docs: none — the narrowing is below the published `run_action` tool, whose input schema already refuses an array `params`; no skill teaches the bridge seam Measured on base (c924627) and head with one probe (seat review S1): every REST `/actions` answer is unchanged (the existing REST suites pass with no edit). The widening is the new entry: a host reaches the door's sequence with `dispatchAction`. The one narrowing is at the MCP action bridge (`invokeBusinessAction`): an ARRAY `params` ran on base (spread into numeric keys) and is refused `400 VALIDATION_FAILED` on head. Every other row in "Served refusal codes that change" was refused on base and is still refused on head; only the status, code, sentence or `details` moved to the REST door's. > **BREAKING (narrowing):** a caller of the MCP action bridge that passes `params` as an array is now refused `400 VALIDATION_FAILED` before anything runs. First-party count: **0**. The bridge's one first-party caller is the published `run_action` tool (`packages/mcp/src/mcp-http-tools.ts`), whose input schema (`params: z.record(z.string(), z.unknown())`) already refuses an array before the bridge is reached, on base and head. Only an embedder that calls the bridge's `runAction` directly can observe the change. Claim by `domain:server#1`, card-thread session_01ADHkmQ1usEQkFW4fXE6dPZ. Seat 2's rulings (claim amendment 6741181718) and seat 1's answers to Q6/Q7 bind the shape. Built on main in parallel with #31980 (seat 1's order); this diff stays out of `collectActionDeclarations`, `resolveActionByName` and `pickActionHolder`. ## 维护者速读 - 改了什么:把 REST `/actions` 门的准入与派发抽成一条共享序列(`action-dispatch.ts`),REST 门、MCP `run_action` 和新导出的 `dispatchAction` 三处都走它。`@objectstack/runtime` 新增导出 `dispatchAction` 及三个类型。 - 为什么改:cloud 的产品内 AI 动作工具现在自己抄了一份准入规则,规则一改就会漂移。导出后 host 直接拿到 REST 门的答案,`posture: 'ai'` 再加上 MCP 的三条 AI 规则。 - 风险与回滚:REST 答案逐字节不变。MCP `run_action` 有六类拒绝的状态码或文案换成 REST 门的(下面「Served refusal codes that change」逐条列出并有钉子),都是原本就拒绝、仍然拒绝。回滚即 revert。 - 先看:`packages/runtime/src/action-dispatch.ts`(`admitResolvedAction` 的闸门顺序与 `dispatchActionRequest`),`packages/runtime/src/action-dispatch.test.ts`。 - 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/action-dispatch.test.ts`,预期 18 条全过。 - 需要你做的:无,席位落地;落地后席位通知 cloud 信箱 #31366 删除其镜像。 ## What changes - **`packages/runtime/src/action-dispatch.ts`** (new): the one admitted sequence, value-form. Resolution stays a per-door prelude (REST bare, REST addressed / MCP `namespace`, MCP bare), each followed by the shared sequence: refusal 409 → degraded 503 → undeclared 404 → [ai] `sys_*` exposure → [ai] `ai.exposed` → D4 403 → activation 409 → owner gate → type 400 → flow-without-automation 503 → [ai] script binding (`isHeadlessInvokableAction`, C10 kept) → body / params / recordId 400 → `enforceActionParams` 400 → [ai] confirmation 428 → subject load → dispatch arms (declarative, api forward, flow, script) → invocation row. The outcome is a value (`answered` / `refused` / `forward-refused` / `thrown`); each door renders it: REST and the host export as the REST envelope through `deps.error` / `deps.success`, MCP as its throw or `{ ok, … }` answer. `refuseDispatchToDisabledObject` stays a separate step that every door calls BEFORE its resolver (the addressed resolver's merged listing omits a disabled package's object; R1 is pinned on the addressed arm so a later move cannot turn it into `RESOURCE_NOT_FOUND`). - **Public names** (seat 2's ruling): `dispatchAction(kernel, request)`, `ActionDispatchRequest` (`executionContext`, `environmentId?`, `objectName?`, `actionName`, `namespace?`, `recordId?`, `params?`, `credentialHeaders?`, `posture?`, plus `confirm` from `AIActionConfirmation`), `ActionDispatchAnswer` (`{ status, body, headers? }`), `ActionDispatchPosture` (`'rest' | 'ai'`, default `'rest'`; any other value is refused 400 `VALIDATION_FAILED` before resolution). Exported from `src/index.ts`; `package.json` exports unchanged. `namespace?` is seat 1's Q6 answer: read with the addressed path's rules (`_env` the environment's own, an installed namespace its package, otherwise 404), qualifier only, no bare fallback. A host call writes its invocation row with no `surface`; no spec edit. - **`packages/runtime/src/domains/actions.ts`**: the door keeps its floor, method, path parse, activation write door and resolution prelude, then calls `runResolvedActionAsRest(…, 'rest')`. `dispatchAdmittedRestAction` moved into the shared module. - **`packages/runtime/src/action-execution.ts`**: `invokeBusinessAction` keeps its resolution prelude and calls `runResolvedAction` under `posture: 'ai'`; `dispatchAdmittedBusinessAction` is deleted (seat 2's ruling). - **`packages/runtime/src/http-dispatcher.ts`**: `dispatchHostAction(request)`, which the export calls with the REST door's deps. - **Docs**: `content/docs/ui/actions.mdx` gains "Call it from your own host code": the export, its posture table (a host's in-product AI tool takes `'ai'`), `namespace`, and the MCP refusals that now carry the REST codes. - **Ledgers that follow the move**: `scripts/check-route-envelope.mjs` lowers `actions.ts` `handBuilt` 3 → 1 and, per the seat's ruling S2, adds `DISPATCHER_SHARED_FILES`: `src/action-dispatch.ts` is scanned with the domain scanner and held at `handBuilt: 2` (the two api-forward relays, now returned as `{ handled, response }` pairs from `restAnswerOf` so the scanner sees them), with a self-test battery (`Dispatcher shared files (#31923)`, 5 cases: the production table names the file, an undeclared relay reds, a declared one is green, a count without a note reds, a missing path reds); `content/docs/permissions/system-context.mdx` row 52 names `dispatchActionRequest`'s anonymous floor and its site register is regenerated (`check:system-context-census --write`). - **Checklist**: `docs/qa/platform-checklist/areas/api-backend.json` re-points one `source` anchor (`domains/actions.ts#record`) at `action-dispatch.ts#admitResolvedAction`, where the ordered gates live now. ## Served refusal codes that change (MCP `run_action` / the action bridge only) | Row | Base | Head | Pin (`src/action-dispatch.test.ts`) | |:--|:--|:--|:--| | C3 undeclared name | uncoded 400 "not found" | 404 `RESOURCE_NOT_FOUND`, the REST door's sentence (with an object named); 404 `RESOURCE_NOT_FOUND` "Action 'X' not found" (no object) | `C3 — …` | | C4 flow, no automation | 400 | 503 `SERVICE_UNAVAILABLE` | `C4 — …` | | C5 client-side action, caller lacks its capability | 400 (type check before D4) | 403 `PERMISSION_DENIED` | `C5 — …` | | C5 family: the installation switched it off | 400 | 409 `ACTION_DISABLED` | `C5 family — …` | | C6 entitled client-side action | 400 "cannot be invoked via MCP" | 400 with the REST door's type prescription | `C6 — …` | | C6 family: client-side action never exposed to AI | 400 "cannot be invoked via MCP" | 400, the `ai.exposed` sentence (that gate runs before the type check) | `C6 family — …` | | C7 flow ran and failed | 400 `FLOW_FAILED`, no `details` | 400 `FLOW_FAILED` with the run `details` the REST door serves | `C7 — …` | | R1 object of a disabled package | 400 "not found" (bare) / 404 `RESOURCE_NOT_FOUND` (addressed) | 404 `OBJECT_PACKAGE_DISABLED`, both arms | `R1 — …` | | **S1 (a2) `params` is an array — NARROWING** | **ran** (array spread into numeric keys) | 400 `VALIDATION_FAILED` "`params` expected an object", nothing runs | `NARROWING — …` | | S1 (a1) `params` is a string | ran, read as no params | unchanged (base also) | `unchanged — a string params …` | | S1 (b) `recordId` is a number or an object | ran, read as a record-less call | unchanged (base also) | `unchanged — a non-string recordId …` | | S1 (c) metadata plane degraded | a degraded read ran; a listing that throws was refused 400 | unchanged (base also): MCP's resolution carries no `degraded`, so the shared 503 never fires there | `unchanged — no degraded 503 at MCP …` | Unchanged at MCP, pinned as controls: C1 confirmation 428, C2 `ai.exposed` 400, C10 unbound script 400, and the admitted `{ ok, action, objectName, result }` shape. Same status and sentence for C2 and C10; the thrown value now also carries `code` (`VALIDATION_ERROR`) and `status` (400), where base threw an uncoded `Error` that the tool read as 400. ## Tests New `packages/runtime/src/action-dispatch.test.ts` (18 tests, real `HttpDispatcher`, `dispatchAction` and `invokeBusinessAction` over scripted services): - The card's "Done when": `dispatchAction`'s answer equals the REST door's for a gated action (member refused 403, holder run) and an elevated flow (`runAs: 'system'` autolaunched: member refused, system principal run), with the same ran-count. - A `posture` other than `'rest'` / `'ai'` / absent (`'AI'`, `'mcp'`, `''`, `1`) is refused 400 `VALIDATION_FAILED` (field `posture`, `invalid_option`) before anything resolves, runs or writes a row (seat review F1). - Also equal: an addressed call (`namespace`) and an unknown namespace (404), the anonymous floor (401), a non-object `params` (400); the host row has no `surface` while the REST row has `rest`. - `posture: 'ai'`: an unexposed action refused as `run_action` refuses it; confirmation 428 without `confirm`, run with it. - One pin per row of the table above, plus the controls. Four of them are S1's base-vs-head readings (probe output in the project folder, `server-seat1/31923-s1-probe.txt`). Forced edits of existing tests (each asserts an MCP refusal in the table above; no REST assertion was edited): - `src/http-dispatcher.test.ts` "run_action refuses a UI-only (modal) action": `/cannot be invoked/` → `/is not exposed to AI/` (C6 family). - `src/domains/api-action-forward.test.ts` "an OFF-ORIGIN api action …": the REST off-origin prescription and status 400 (C6). - `src/domains/actions-addressed-route.test.ts` "CONTROL — MCP bare run_action(log_call, { objectName: lead }) …": 404 and the REST undeclared sentence (C3). - `src/domains/mcp-package-object-discovery.test.ts`: the `CONTROL: a name the package does not declare …` case (C3); `run_action refuses ${name} …` on a disabled package (R1 scoped, C3 unscoped); the two object-less disabled-package cases (C3, scoped and unscoped). Forced edit outside runtime: `packages/spec/src/ai/tool-confirmation-prescription-tense.pin.test.ts` re-points its "pre-dispatch" reading at the shared sequence (see Deviations); assertions kept at least as strong. Other test-file edits: `src/action-dispatch.test.ts` and `src/domains/api-action-forward.test.ts` gain a module-top `import '@objectstack/metadata';` (`check:test-source-alias`: an edited file pays that load at collection); the pin file's engine double routes `findOne` through `assertEngineFindOnePredicate` and is recorded in `scripts/engine-double-contract.pinned.json`. Ablations (`scripts/ablation-replace.mjs`, each red, restored, `git diff HEAD` empty; log `server-seat1/31923-ablations.log` in the project folder): - A1 bare MCP miss thrown uncoded → C3 red. - A2 the old MCP invokability check put back before D4 → C4, C5, C5 family, C6 red. - A3 MCP pre-resolution disabled-object check removed → R1 red. - A4 REST pre-resolution disabled-object check removed → R1 (REST addressed) red. - A5 D4 dropped from the shared sequence → the gated-action equality pin and C5 red. - A6 MCP flow refusal `details` not attached → C7 red. - A7 the export's `namespace` qualifier dropped → the addressed-call pin red. - A8 the host call writes `surface: 'rest'` → the invocation-row pin red. - A9 the params-shape check dropped from the shared sequence → the S1 NARROWING pin red. - A10 a throwing metadata listing swallowed at the MCP prelude (the action runs) → the S1 (c) pin red. - A11 `DISPATCHER_SHARED_FILES` declares `action-dispatch.ts` one relay short → `check:route-envelope` red (`handBuilt: found 2, declared 1`), proving the file is scanned. - A15 `dispatchActionRequest` reads any posture but `'ai'` as `'rest'` (the posture check removed) → the posture pin red (`expected 200 to be 400`). - A12 the confirmation gate call removed from `admitResolvedAction`'s `ai` branch → the spec pin "the AI-facing door still calls the gate pre-dispatch" red. - A13 `runResolvedAction` no longer returns the admission refusal before it dispatches → the same pin red. - A14 `invokeBusinessAction` enters the sequence as `rest` → the same pin red. ## Acceptance notes - The MCP type check now runs after D4, activation and the owner gate (the REST door's order), so an unentitled caller no longer learns an action's type from a 400 (C5). That is the reason the order follows REST rather than the old MCP order. - `credentialHeaders` are lower-cased onto the request the sequence sees, so a same-origin `api` action forwards with the host's caller credentials as the REST door forwards with the request's. ## Verification Head e6dc065 = 1683e99 (contract review PASS) + the review round: acc37ce (F1, the posture refusal) and e6dc065 (F4, prose only). No main merge in this round. Heavy runs through `os-verify-lock.sh`; times are shared-box seconds. - This round: `src/action-dispatch.test.ts` 23 passed (+ the posture pin); with `http-dispatcher.test.ts` and `domains/api-action-forward.test.ts`, 3 files / 362 passed. The spec confirmation pin: 8 passed. `tsc --noEmit` for `@objectstack/runtime` and eslint over `action-dispatch.ts` and its test: exit 0. Ablation A15 reds the posture pin. - This round, the gates the two commits touch, all exit 0: `check:adr-0087-registration` (both forms), `check-changeset-no-major`, `check-empty-changeset` (both forms), `check:changeset-gate-self-tests`, `check-docs-section-name` (both forms), `check-affected-docs`, `check-drift-comment`, `check:docs-audit-scope`, `check:docs-redirects`, `check:docs-single-h1`, `check:docs-spec-enumerations`, `check:docs-transcript-drift`, `check:route-envelope`, spec `check:docs`, `check:empty-state`, `check:variant-docs`. - Readings on 1683e99, unchanged by this round's code (the F1 check sits ahead of resolution in `dispatchActionRequest`): - Full `@objectstack/runtime` suite on 93dabc9 (the runtime tree of that head): 579 files, 10726 passed, 19 skipped (VERDICT command-exit 0). - `packages/spec` `test:repo` (the CI red on Test Core 2/8): 91 files, 1556 passed (command-exit 0), with the re-pointed confirmation pin. - `@objectstack/dogfood`, built closure, before the S1/S2 round: 448 files passed, 3 skipped; 3689 tests passed (command-exit 0). Not re-run, per the seat; the Dogfood Regression Gate check on 1683e99 is success. - `dispatch-gates --commands`: 135 families; `--ran`: 135 derived, 135 run, 0 NOT-MEASURED. - S1 probe (base c924627 vs head): `server-seat1/31923-s1-probe.txt` in the project folder. Ablations A1–A15: `server-seat1/31923-ablations.log`. ## Deviations - `packages/spec/src/ai/tool-confirmation-prescription-tense.pin.test.ts` is edited (a test file only, no schema or format change), at the seat's direction: the pin read the confirmation gate inside `invokeBusinessAction`, and the gate now lives in the shared sequence. It now reads the door entering the sequence as `ai`, the gate under `posture === 'ai'` in `admitResolvedAction`, and the refusal returned before dispatch; REST must enter as `rest`. Ablations A12–A14 (gate call removed, refusal not returned before dispatch, MCP entering as `rest`) each red it. - The body opens with the session attribution block, then `Fixes #31923`. _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmQ1usEQkFW4fXE6dPZ)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmQ1usEQkFW4fXE6dPZ <!-- signed: domain:server#1 · os-steve · session_01ADHkmQ1usEQkFW4fXE6dPZ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3fb67d6 commit 99992dd

17 files changed

Lines changed: 1715 additions & 1023 deletions
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
'@objectstack/runtime': patch
3+
---
4+
5+
**BREAKING (narrowing):** a caller of the MCP action bridge that passes `params` as an array is now refused `400 VALIDATION_FAILED` before anything runs (it ran before, the array spread into numeric keys). First-party count: 0 — the published `run_action` tool's input schema already refuses an array.
6+
7+
Export `dispatchAction(kernel, request)` (with `ActionDispatchRequest`, `ActionDispatchAnswer` and `ActionDispatchPosture`): the REST `/actions` door's admission and dispatch as a function, so a host's own action door (an in-product AI tool, a job runner) answers what that door answers instead of keeping a second copy of its rules. `posture: 'ai'` adds the MCP `run_action` tool's rules (`sys_*` exposure, `ai.exposed`, `ai.requiresConfirmation`); `namespace` addresses an installed package's action as the addressed REST path does. A host call writes its invocation row without a `surface`. A `posture` that is neither `'rest'` nor `'ai'` is refused `400 VALIDATION_FAILED` before anything resolves. The export runs through a new public method, `HttpDispatcher.dispatchHostAction(request)`, which answers the same `ActionDispatchAnswer` with the REST door's dependencies.
8+
9+
The REST door, the host export and MCP `run_action` now run one admitted sequence (`action-dispatch.ts`). The REST door's answers are unchanged. MCP `run_action` refusals that change (each was refused before and stays refused; nothing new runs):
10+
11+
- C3: a name nothing declares is `404 RESOURCE_NOT_FOUND` with the REST door's sentence (was an uncoded 400 "not found").
12+
- C4: a flow action with no automation service is `503 SERVICE_UNAVAILABLE` (was 400).
13+
- C5: a client-side action whose caller lacks its capability is `403 PERMISSION_DENIED`, and one the installation switched off is `409 ACTION_DISABLED` (was 400, the type check ran before both).
14+
- C6: an entitled client-side action keeps its 400 with the REST door's type prescription; one never exposed to AI is refused at the exposure gate first.
15+
- C7: a flow run that failed (`400 FLOW_FAILED`) carries the run `details` the REST door serves.
16+
- R1: an object whose package is disabled is `404 OBJECT_PACKAGE_DISABLED`, bare and addressed (was 400 / `404 RESOURCE_NOT_FOUND`).
17+
18+
One narrowing, at the MCP action bridge below the published tool: an array `params` is refused `400 VALIDATION_FAILED` before anything runs (it ran before, spread into numeric keys). The `run_action` tool's input schema already refused an array, so no first-party caller changes.
19+
20+
Clause-②: yes (narrowing)
21+
Metadata-protocol: none
22+
23+
<!-- adr-0087: not-required (no-migration-prescription) no metadata shape, schema, stored row or registered node type changes: the one narrowing is a malformed `params` array passed to the MCP action bridge (`run_action`), which ran before and is now refused before anything runs; the stored metadata is read exactly as before, so there is nothing for `objectstack migrate meta` to rewrite -->

‎content/docs/permissions/system-context.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ One of the largest consumers of the flag;
203203
| 50 | `manage_metadata` bypassed on metadata writes | runtime, rest | Get: schema writes without the capability (the permission-set clone door's save included) — and, because REST's save door and the stored-version read doors ask one save verdict, an app's full stored version on `/layers`, `?layers=true` and `/diff`, whatever its entry gates withhold | `handleMetadataRequest`, `registerMetaCollectionRoutes`, `registerMetaItemWriteRoutes`, `registerMetaItemHistoryRoutes`, `metaSaveVerdict`, `handlePermissionSetCloneWrite` |
204204
| 50b | `setup.write` bypassed on the record-currency code backfill door | rest | Get: `POST /meta/_migrate-record-currency-codes` without the capability. The door still fills only the caller's current organization's rows: a system context with no organization is refused like any other caller | `registerMetaRecordCurrencyBackfillRoute` |
205205
| 51 | The shared metadata-write verdict itself returns `allowed` | metadata-core | Get: the one function all of row 50's doors consult answers yes before any capability is examined | `metaWriteCapabilityVerdict` |
206-
| 52 | Anonymous-deny seam satisfied on the domain dispatchers and the package/federation routes | runtime, rest | Get: passes with no `userId` | `handleActionsRequest`, `handleAIRequest`, `handleAutomationRequest`, `handleMetadataRequest`, `handleSecurityRequest`, `handlePackagesRequest`, `handleAnalyticsRequest`, `handleI18nRequest`, `registerExternalDatasourceRoutes`, `refusePackageRequest` |
206+
| 52 | Anonymous-deny seam satisfied on the domain dispatchers and the package/federation routes | runtime, rest | Get: passes with no `userId` | `handleActionsRequest`, `dispatchActionRequest`, `handleAIRequest`, `handleAutomationRequest`, `handleMetadataRequest`, `handleSecurityRequest`, `handlePackagesRequest`, `handleAnalyticsRequest`, `handleI18nRequest`, `registerExternalDatasourceRoutes`, `refusePackageRequest` |
207207
| 53 | MCP principal check satisfied | runtime | Get: MCP surface reachable with no user | `handleMcpRequest` |
208208
| 54 | Package REST route capability gate bypassed | rest | Get: a marketplace publish over REST (`POST /packages/publish`, the one route the REST registrar mounts since #14503) without `manage_metadata`; the package read cohort (`studio.access` / `setup.access`) is enforced by the dispatcher `/packages` domain's own read gate, where the reads are served | `refusePackageRequest` |
209209
| 55 | Package domain capability gates bypassed | runtime | Get: package management and package-inventory reads without the capability | `requireManageMetadata`, `requireReadCapability` |
@@ -645,6 +645,7 @@ and CI refuses one that differs from what the tree produces.
645645
| `packages/rest/src/rest-server.ts#mayReadAuthoringTrail` | 1 | 8b |
646646
| `packages/rest/src/rest-server.ts#metaSaveVerdict` | 1 | 50 |
647647
| `packages/rest/src/rest-server.ts#walledCatalogRefusal` | 1 | 55b |
648+
| `packages/runtime/src/action-dispatch.ts#dispatchActionRequest` | 1 | 52 |
648649
| `packages/runtime/src/action-execution.ts#actionPermissionError` | 1 | 49 |
649650
| `packages/runtime/src/action-execution.ts#callData` | 1 | 48 |
650651
| `packages/runtime/src/action-execution.ts#refuseUnexposedDataAction` | 1 | 48 |

‎content/docs/ui/actions.mdx‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,61 @@ Only headless-callable types appear (`script` with body or handler, `flow`);
679679
enforced per invocation. Details: [Actions as Tools](/docs/ai/actions-as-tools)
680680
and [Connect an MCP Client](/docs/ai/connect-mcp).
681681

682+
## Call it from your own host code
683+
684+
A host that runs actions from its own door, outside REST and MCP (an
685+
in-product AI tool, a job runner), calls `dispatchAction` from
686+
`@objectstack/runtime` instead of re-implementing the door's checks. It runs
687+
the same admission and dispatch as `POST /api/v1/actions/...` and answers what
688+
that door answers for the same call: the sign-in floor, `requiredPermissions`,
689+
the packaged-action switch, the type check, the param contract, the subject-row
690+
load, then the handler, flow or forward.
691+
692+
```typescript
693+
import { dispatchAction } from '@objectstack/runtime';
694+
695+
const answer = await dispatchAction(kernel, {
696+
executionContext, // the caller, as your door authenticated it
697+
environmentId, // optional; the kernel's default environment when absent
698+
objectName: 'crm_lead', // omit for a global (object-less) action
699+
actionName: 'convert',
700+
recordId,
701+
params: { owner: 'u_42' },
702+
posture: 'ai', // your AI tool's door: see below
703+
confirm: humanApproved, // only read under `posture: 'ai'`
704+
credentialHeaders, // optional: the caller's own credentials (e.g. `authorization`, `cookie`)
705+
});
706+
if (answer.status !== 200) throw answer.body.error; // the REST envelope's error
707+
```
708+
709+
Pick the **posture** by who drives your door:
710+
711+
| `posture` | Rules | Use it for |
712+
|:---|:---|:---|
713+
| `'rest'` (default) | Exactly the REST door's. | A door a person drives, or your own server code. |
714+
| `'ai'` | The REST door's, plus the three the MCP `run_action` tool adds: a `sys_*` action needs its own `ai.exposed`, every action needs `ai.exposed: true`, and an action with `ai.requiresConfirmation` is refused **428** `ACTION_CONFIRMATION_REQUIRED` until the call carries `confirm: true`. A script action with no handler binding is also refused. | **A host's in-product AI tool** — an agent picks the action, so it takes the AI door's rules. |
715+
716+
`posture` is `'rest'`, `'ai'` or absent (`'rest'`); any other value is
717+
refused **400** `VALIDATION_FAILED` before anything runs, so a misspelt
718+
posture cannot quietly drop the AI rules.
719+
720+
`credentialHeaders` are the caller's own credential headers, read the way the
721+
REST door reads its request's: a same-origin `type: 'api'` action forwards
722+
with them, and its target authorizes the caller itself. Omit them and such an
723+
action forwards with none. `environmentId` names the environment the action
724+
runs in; without it the kernel's default environment is used.
725+
726+
`namespace` addresses an installed package's action the way the
727+
`/api/v1/actions/:namespace/:object/:action` path does (`_env` names the
728+
environment's own). A host call writes the usual invocation audit row,
729+
without a `surface`.
730+
731+
The MCP `run_action` tool runs this same sequence under `'ai'`, so its
732+
refusals carry the REST door's status and code: a name nothing declares is
733+
**404** `RESOURCE_NOT_FOUND`, a flow action with no automation service is
734+
**503**, a caller without the action's capability is **403**, and an object
735+
whose package is disabled is **404** `OBJECT_PACKAGE_DISABLED`.
736+
682737
## Troubleshooting
683738

684739
| Symptom | Cause → fix |

‎docs/qa/platform-checklist/areas/api-backend.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,7 @@
17841784
"first-boot-cold-start"
17851785
],
17861786
"source": [
1787-
"packages/runtime/src/domains/actions.ts#record (the REST door's ordered gates: ADR-0066 D4 capability gate → activation consult → type branch → ADR-0104 param contract → best-effort record load)",
1787+
"packages/runtime/src/action-dispatch.ts#admitResolvedAction (the ordered gates the REST door, MCP run_action and dispatchAction share since #31923: ADR-0066 D4 capability gate → activation consult → type branch → ADR-0104 param contract → best-effort record load)",
17881788
"packages/runtime/src/action-execution.ts#disabledActionRefusal (disabledActionRefusal — ACTION_DISABLED_CODE/STATUS 409, the shared consult both doors call; invokeBusinessAction — the MCP door, whose AI-exposure + capability gates run ahead of the consult)",
17891789
"packages/objectql/src/engine.ts#isActionEnabled (isActionEnabled / describeDisabledAction / hydrateActionActivations / setActionActive — projection over the durable ledger, row-first then projection)",
17901790
"packages/spec/src/api/error-code-ledger.zod.ts#ACTION_DISABLED (ACTION_DISABLED registered — the *_DISABLED family)",

0 commit comments

Comments
 (0)