Repository navigation
Commit 99992dd
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
File tree
- .changeset
- content/docs
- permissions
- ui
- docs/qa/platform-checklist/areas
- packages
- runtime/src
- domains
- spec/src/ai
- scripts
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
| |||
645 | 645 | | |
646 | 646 | | |
647 | 647 | | |
| 648 | + | |
648 | 649 | | |
649 | 650 | | |
650 | 651 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
679 | 679 | | |
680 | 680 | | |
681 | 681 | | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
682 | 737 | | |
683 | 738 | | |
684 | 739 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1784 | 1784 | | |
1785 | 1785 | | |
1786 | 1786 | | |
1787 | | - | |
| 1787 | + | |
1788 | 1788 | | |
1789 | 1789 | | |
1790 | 1790 | | |
| |||
0 commit comments