Skip to content

Commit 0f7389c

Browse files
fix(runtime)!: an action the metadata does not show a caller is one that caller cannot run, on every run door (ADR-0106 D1) (#32110)
Clause-②: no (narrowing) — every door that runs an action by name in a caller's context (`POST /api/v1/actions/...`, bare and addressed, MCP `run_action`, a host's `dispatchAction`, and the action that admits an MCP `resume_run`) now runs for a caller only an action the `/meta` action projection serves that caller, and answers any other as it answers a name nothing declares. ADR-0106 D1 already promises that a field the caller cannot read does not exist for that caller, so no stated contract is narrowed; what narrows is the run a caller with a `readable: false` field holds. No answer member is added and no code joins the registered vocabulary, but these doors now also answer `503 FIELD_VISIBILITY_UNRESOLVED`, which none of them answered before. Metadata-protocol: none Skills-docs: no move — `skills/**` teaches the run doors only for actions a caller is shown; `content/docs/ai/connect-mcp.mdx` states the rule. ## 维护者速读 - **改了什么**:按名称执行动作的每个门(REST `POST /actions` 的裸路径与带命名空间的地址、MCP `run_action`、宿主 `dispatchAction`、`resume_run` 的准入动作,以及 `run_action` 对系统对象的预筛)在读取动作声明的任何门之前,先用 `/meta` 动作投影的同一判定该调用者能否看到这个动作(动作在任何非展示文字的位置提到调用者不可读的字段即被隐去:参数的 `field`/`name`/默认值/`visible`、动作自身的 `visible`、声明式更新 `patch` 的键等);看不到的动作,在门已解析出唯一声明之后,按该门对"不存在的名字"的回答逐字节作答。 - **为什么改**:ADR-0106 D1 要求调用者不可读的字段在任何平面上都不存在;`/meta` 与 `list_actions` 已经隐去参数绑定了不可读字段的动作,执行门按维护者裁决(记录 6755714726)采用同一判定。 - **风险与回滚**:对带 `readable: false` 字段的调用者是收窄(标题带 `!`):持有该动作但读不到它提到的某个字段的调用者不再能执行它,包括写入只写字段(例如设置密钥)的动作,不论经参数还是 `patch`;迁移方式是授予读权限,或改成处理器动作并让内联参数名不同于字段名(changeset 写明,有测试按字面执行)。字段可见性无法评估或对象定义读取失败时回答 `503 FIELD_VISIBILITY_UNRESOLVED`,什么都不执行。系统上下文、D4 豁免者、无 security 服务或关闭掩码的部署逐字节不变。回滚即 revert 本 PR。 - **先看**:`packages/runtime/src/action-dispatch.ts`(准入序列里新的可见性判定,位于 D4 能力门之前)、`packages/runtime/src/action-run-visibility.ts`(只把门手里的对象与掩码交给 `/meta` 的投影函数)、`packages/runtime/src/domains/mcp.ts`(`run_action` 预筛与 `resume_run`)。 - **两分钟验证**:`pnpm --filter @objectstack/runtime exec vitest run src/domains/mcp-object-schema-mask.test.ts` —— 预期全部通过;其中 run-door 一组断言:被隐去的动作在 REST、MCP 与宿主门上的回答,与未知名称的回答逐字节相同。 - **需要你做的**:无,席位落地。 ## What changes - **The rule.** An action is run for a caller only where the `/meta` action projection serves it to that caller. The judgement is `projectMetaActionForCaller` (`@objectstack/rest`), the function the `/meta` action reads and MCP `list_actions` already ask, asked against the object the door runs the action under, over the `/meta` object door's own masker. `action-run-visibility.ts` only hands it those two inputs; it adds no rule. That projection withholds an action that mentions, in any non-prose position, a field the caller cannot read on that object: a param's `field` or `name`, a param's `defaultValue` or `visible`, the action's own `visible`, a key of a declarative update's `patch`, or any other non-prose value; a string literal equal to the field's name counts. A param's `field` under `objectOverride` is judged on the object it names. - **Where.** Once, in the admitted sequence every run door shares (`action-dispatch.ts`): right after the ADR-0110 D3 trichotomy, before the AI-door rules, the ADR-0066 D4 capability gate, the activation consult, the type checks and the ADR-0104 param contract. So a withheld action discloses no gate, no switch and no param shape, and reads no record. The MCP bridge asks the same question where it admits an action outside that sequence: `run_action`'s scoped `sys_*` pre-screen (`capabilityRefusal` answers nothing for a withheld action) and `resume_run` (a withheld candidate admits nothing and is no refusal). `list_actions` now derives the object it judges by the same function the run doors use. - **The answer.** Once the door has resolved one declaration for the name, a withheld action is answered with the door's own unknown-name answer, built by the same function. Answers given while the name is still being resolved (a name more than one package holds is one) come before this question and are unchanged. The unknown-name answers are the bare `/actions` arm's undeclared `404`, the addressed arm's `404` for its namespace or the environment (`addressedActionNotFoundError`, now shared by the resolver and this answer), `run_action`'s not-found refusal, and for `resume_run` the refusal a run no flow action could have started receives. - **Refusal.** Where the caller's field visibility cannot be evaluated, the definition of the action's object cannot be read (a read that throws is a fault, never "no object"), or the projection would leave that object with no field: `503 FIELD_VISIBILITY_UNRESOLVED`, fail-closed, as the `/meta` object door refuses the read. - **Unchanged.** The system context, a D4-exempt caller (`manage_metadata`), a deployment with no `security` service or with the mask switched off, and every caller for an action that mentions no field that caller cannot read. ## Tests - `src/action-run-visibility.test.ts` (new): the run-door judgement against the `/meta` object door's and action door's own verdicts, case by case — 7 callers (a field-restricted member, staff, a caller denied every field, a security outage, an undetermined field universe, the system context, a D4-exempt author) × embedded, standalone and object-less actions of 11 shapes: the param bindings, plus a `patch` key, an action `visible` predicate, an inline param named like the field, a literal default, and the changeset's migration rewrite; the ruled verdicts; an object-less action run under a routed object judged on that object; and a system-context CONTROL that never asks the security service. - `src/domains/mcp-object-schema-mask.test.ts`, new top-level describe over the real security layer: REST `/actions`, MCP `run_action` and host `dispatchAction` (both postures) answer a withheld action byte-identical to an unknown name for every bag shape, and write nothing; a capability-gated withheld action is answered as unknown, never as its gate's refusal, and the scoped pre-screen names no gate; the `503` on both doors, for a caller denied every field and for a security service that throws; CONTROLs: an action the member is shown runs (REST and MCP, rows written), a shown caller still gets the located param `400`, and the system context and a D4-exempt author are answered as a deployment with the mask switched off. The changeset's migration followed literally (a handler action with an inline param not named like the field) runs for the member on both doors; the same rewrite with the param named like the field stays withheld. A params-less action whose `patch` writes the field is withheld. - `src/domains/actions-addressed-route.test.ts`: the addressed REST path and a namespaced `run_action` answer a withheld action byte-identical to a name the namespace does not declare; CONTROL runs. A run whose action-object definition read throws is refused `503 FIELD_VISIBILITY_UNRESOLVED` and runs nothing; CONTROL: with no security service no definition is read and nothing is refused. - `src/mcp-resume-run.test.ts`: a run whose admitting action the caller can no longer see is refused exactly as a run on a deployment declaring no action for its flow, and stays parked; the `503`; CONTROL resumes. ## Acceptance notes - An object-less action run under a routed object is judged on that object, the one its params resolve against at run time; the `/meta` action read judges an object-less entry by its `objectOverride` params alone. Kept by decision and pinned in `action-run-visibility.test.ts`. - The error-code ledger's comment listing this package's `FIELD_VISIBILITY_UNRESOLVED` emitters names the MCP schema reads, not the run doors; the code is registered for `@objectstack/runtime`, so no gate reads that comment. Left for a spec-lane edit. ## Verification Patch round readings, under the shared verify lock. The PR head is `9688f8fb4f`. <details><summary>Pins</summary> At `9688f8fb4f`: `pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/action-run-visibility.test.ts src/domains/mcp-object-schema-mask.test.ts src/domains/actions-addressed-route.test.ts src/mcp-resume-run.test.ts` ``` Test Files 4 passed (4) Tests 307 passed (307) ``` </details> <details><summary>One-shot ablations</summary> - The admission check (first round, at `a898febdf4`): the run doors' masker made to answer a passthrough posture for every caller. 9 red, then restored. - A failing definition read (this round, at `0b28d8e5e3`): `ablation-replace.mjs` made the read answer "no object" instead of a fault (anchor hit once). `actions-addressed-route.test.ts` went red on the `503` pin (plus the control as first written, which `9688f8fb4f` rewrote), then restored: `git diff HEAD` empty, blob equal to HEAD. </details> <details><summary>Runtime suite, typecheck and dogfood battery</summary> - `pnpm --filter @objectstack/runtime typecheck` at `0b28d8e5e3` — exit 0 (`tsc --noEmit` and `check:test-typecheck`). `9688f8fb4f` changes one test file only. - `pnpm --filter @objectstack/runtime test` at `0b28d8e5e3`: 576 of 577 files and 9578 tests passed, 19 skipped. The one red was the failing-read control as first written. `9688f8fb4f` rewrites it, and the pin files above pass at that head. - Dogfood battery (first round, at `a898febdf4`): 446 files passed (3 skipped), 3695 tests passed (42 skipped). This round's code change is in `action-dispatch.ts` only. </details> <details><summary>Derived gates</summary> At `9688f8fb4f`, `node scripts/pm/dispatch-gates.mjs --commands` derived 101 families; all were run and reconciled with `--ran` (exit codes recorded): 98 exit 0, 3 NOT MEASURED. `check:skill-examples` and `check:dual-build-cjs-loads` refused on build output this tree had not built. `check:type-check-debt` never got a turn on the shared lock. CI builds and runs all three. `test:repo` is CI's. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYn5CmmdShCJifm6WYj)_ <!-- signed: security#2 · os-justin · session_01QSeKYn5CmmdShCJifm6WYj --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent bca2a51 commit 0f7389c

12 files changed

Lines changed: 1028 additions & 38 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/runtime': patch
3+
---
4+
5+
fix(runtime)!: an action the metadata does not show a caller is one that caller cannot run, on every run door (ADR-0106 D1)
6+
7+
Clause-②: no (narrowing) — every door that runs an action by name in a caller's context (`POST /api/v1/actions/...`, bare and addressed, MCP `run_action`, a host's `dispatchAction`, and the action that admits an MCP `resume_run`) now runs for a caller only an action the `/meta` action projection serves that caller, and answers any other as it answers a name nothing declares. ADR-0106 D1 already promises that a field the caller cannot read does not exist for that caller, so no stated contract is narrowed; what narrows is the run a caller with a `readable: false` field holds. No answer member is added and no code joins the registered vocabulary, but these doors now also answer `503 FIELD_VISIBILITY_UNRESOLVED`, which none of them answered before.
8+
Metadata-protocol: none
9+
Skills-docs: no move — `skills/**` teaches the run doors only for actions a caller is shown; `content/docs/ai/connect-mcp.mdx` states the rule.
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema and no stored shape changes: the run doors judge a caller by the projection the metadata doors already apply. There is nothing for a migration to rewrite and no tombstone. -->
12+
13+
**BREAKING** for a caller with a `readable: false` field, on `POST /api/v1/actions/...`, on `dispatchAction`, and on MCP `run_action` and `resume_run` over HTTP (`/api/v1/mcp`).
14+
15+
- **The rule.** An action is run for a caller only where the `/meta` action projection serves it to that caller: the same judgement, asked through `projectMetaActionForCaller` (`@objectstack/rest`), against the object the door runs the action under. The projection withholds an action that mentions, in any position that is not display prose, a field the caller cannot read on that object: a param's `field` or `name`, a param's `defaultValue` or `visible` predicate, the action's own `visible` predicate, a key of a declarative update's `patch`, or any other non-prose value of the action. A string literal equal to the field's name counts as a mention. A param's `field` under `objectOverride` is judged on the object it names. Labels, descriptions and other display prose are not read.
16+
- **The answer.** Once the door has resolved one declaration for the name, a withheld action is answered byte for byte as the same door answers a name nothing declares. Answers the door gives while it is still resolving the name (a name more than one package holds is one) come before this question and are unchanged. The unknown-name answers are the bare `/actions` arm's `404` (and `dispatchAction`'s), the addressed arm's `404` for its namespace or the environment, `run_action`'s not-found refusal, and for `resume_run` the refusal a run no flow action could have started receives. The question is asked before every gate that reads the action's declaration on the caller's behalf (its capability gate, its activation switch, its param contract), so nothing is read or run.
17+
- **Declared narrowing.** A caller who holds the action, and its capability, but cannot read a field the action mentions can no longer run it. That includes an action that writes a field the caller may write but not read, such as one that sets a secret, whether through a param or through `patch`. To keep such a run, either grant the caller read on every field the action mentions, or rewrite the action so that no non-prose position spells that field's name as a whole word. A declarative update cannot write a field without naming it, so move the write into a handler: `type: 'script'`, a `target` handler that writes the field, and an inline param whose `name` is not the field's (`new_amount`, not `budget`). A param named like the field is a mention, and keeps the action withheld.
18+
- **Refusal.** Where the caller's field visibility cannot be evaluated, the definition of the action's object cannot be read, or the projection would leave that object with no field, the run is refused as the `/meta` object door refuses the read: `FIELD_VISIBILITY_UNRESOLVED` / 503, fail-closed. Nothing runs.
19+
- **Unchanged.** The system context, a D4-exempt caller (`manage_metadata`), and a deployment with no `security` service or with the mask switched off run every action as before; so does every caller for an action that mentions no field that caller cannot read.

‎content/docs/ai/connect-mcp.mdx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,10 @@ drive this MCP server. Same word, different layer.
435435
(one whose param binds a field the caller cannot read, judged on the object
436436
the param names, so an object-less action too) is not listed, and a
437437
listed action's params carry no label, help text or options of such a
438-
field. Sparse results or denied
438+
field. Nor can the caller run it: `run_action` and `POST /api/v1/actions/...`
439+
answer it as an action that does not exist, and `resume_run` refuses a run
440+
it would admit as it refuses a run no flow action could have started.
441+
Sparse results or denied
439442
writes usually mean governance is *working*, not that the connection is
440443
broken.
441444
- **OAuth scopes narrow the toolset.** Tokens carry `data:read`,

‎packages/runtime/src/action-dispatch.ts‎

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ import { objectValueFailure } from './object-value-shape.js';
6666
import { apiErrorResponse } from './error-envelope.js';
6767
import { HttpDispatcher, type HttpProtocolContext, type HttpDispatcherResult } from './http-dispatcher.js';
6868
import type { DomainHandlerDeps } from './domain-handler-registry.js';
69+
// [ADR-0106 D1] The run doors' visibility question: the `/meta` projection's.
70+
import { actionRunFieldVisibilityRefusal, actionRunMasker, projectActionForCaller } from './action-run-visibility.js';
6971

7072
/**
7173
* Which door's rules an action call is admitted under — see the module
@@ -137,11 +139,64 @@ export interface ResolvedActionCall {
137139
recordIdFromPath?: string;
138140
/** The AI-door confirmation member, read under the `ai` posture only. */
139141
confirmation?: AIActionConfirmation;
142+
/**
143+
* [ADR-0106 D1] This door's answer for a name nothing declares, where it
144+
* is not the sequence's own undeclared `404` ({@link undeclaredActionRefusal}):
145+
* an addressed call's resolver refuses a miss by name in its scope
146+
* ({@link addressedUnknownNameRefusal}), and the MCP bridge's call naming
147+
* no object has its own. A declared action the caller is not shown is
148+
* answered with it, so the door's answers cannot tell the two apart.
149+
*/
150+
unknownName?: ActionRefusal;
140151
/** The engine the gates and the script arm read (`executeAction`). */
141152
ql: any;
142153
wiring: ActionDispatchWiring;
143154
}
144155

156+
/** A thrown `404` refusal (`code` + `status` on an `Error`), as the {@link ActionRefusal} a door renders. */
157+
export function refusalOfThrown(err: Error & { code: string; status: number }): ActionRefusal {
158+
return { message: err.message, status: err.status, details: { code: err.code } };
159+
}
160+
161+
/**
162+
* [ADR-0106 D1] The answer an addressed call (ADR-0150 D5) gets for a name its
163+
* scope declares none of — what its resolver throws — as a refusal, for
164+
* {@link ResolvedActionCall.unknownName}.
165+
*/
166+
export function addressedUnknownNameRefusal(
167+
actionName: string,
168+
objectName: string | undefined,
169+
qualifier: actionExec.ActionAddressQualifier,
170+
): ActionRefusal {
171+
return refusalOfThrown(actionExec.addressedActionNotFoundError(actionName, objectName, actionExec.actionAddressScope(qualifier)));
172+
}
173+
174+
/**
175+
* [ADR-0106 D6 tier 3] A definition read the visibility question could not
176+
* make: answered as the field-visibility fault, fail-closed.
177+
*/
178+
class ActionDefinitionReadFault extends Error {
179+
constructor(readonly objectName: string, readonly reason: unknown) {
180+
super(`The definition of object '${objectName}' could not be read.`);
181+
}
182+
}
183+
184+
/**
185+
* [ADR-0110 D3] The sequence's answer for a name its resolution found no
186+
* declaration for — and, [ADR-0106 D1], for an action the caller is not shown,
187+
* where the door states no answer of its own.
188+
*/
189+
function undeclaredActionRefusal(actionName: string, objectName: string): ActionRefusal {
190+
return {
191+
message:
192+
`Action '${actionName}' on '${objectName}' has no declaration — ` +
193+
`add \`defineAction({ name: '${actionName}', … })\`, or register the handler under a ` +
194+
`declared action's \`target\`. Undeclared handlers cannot be permission-gated ` +
195+
`(ADR-0110 D3); startup logs every one of them under [action-governance].`,
196+
status: 404,
197+
};
198+
}
199+
145200
/** The facts of an admitted call that a door's invocation row records. */
146201
export interface AdmittedActionCall {
147202
actionDef: any;
@@ -241,18 +296,50 @@ async function admitResolvedAction(
241296
// contract, no AI tool) yet would execute TRUSTED. Refused, with the fix.
242297
// There is no opt-out: a flag that runs an ungoverned handler IS the
243298
// fail-open this ruling closes.
244-
if (!actionDef) {
245-
return refuse({
246-
message:
247-
`Action '${actionName}' on '${objectName}' has no declaration — ` +
248-
`add \`defineAction({ name: '${actionName}', … })\`, or register the handler under a ` +
249-
`declared action's \`target\`. Undeclared handlers cannot be permission-gated ` +
250-
`(ADR-0110 D3); startup logs every one of them under [action-governance].`,
251-
status: 404,
252-
});
253-
}
299+
if (!actionDef) return refuse(undeclaredActionRefusal(actionName, objectName));
254300

255301
// ── 1/3: declared → gate against it ──
302+
303+
// [ADR-0106 D1] AN ACTION THE CALLER IS NOT SHOWN, THE CALLER CANNOT RUN.
304+
// "Not shown" is the `/meta` projection's verdict, asked through the same
305+
// function (`action-run-visibility.ts`) against the object this call runs
306+
// the action under. Asked FIRST among the gates that read the declaration
307+
// on the caller's behalf — the AI-door rules, D4's capability gate, the
308+
// activation consult, the type checks, the param contract — and answered
309+
// exactly as this door answers a name nothing declares, so no answer tells
310+
// a withheld action from an unknown name and nothing about its shape is
311+
// read. A field visibility that cannot be evaluated refuses the run
312+
// (ADR-0106 D6 tier 3, `503 FIELD_VISIBILITY_UNRESOLVED`, as `/meta`
313+
// refuses the read). A `passthrough` posture — the system context, a
314+
// D4-exempt caller, no security service, the mask switched off — runs as
315+
// before.
316+
//
317+
// A definition read that THROWS is a fault, never "no object": judged with
318+
// no own object, the action's mentions of that object's fields would go
319+
// unjudged, so a failed read must not open the run.
320+
let visibility: Awaited<ReturnType<typeof projectActionForCaller>>;
321+
try {
322+
visibility = await projectActionForCaller(actionRunMasker(deps, requestContext), {
323+
action: actionDef,
324+
objectName,
325+
obj: actionSchema,
326+
readObject: (other) => {
327+
try {
328+
return (typeof ql?.getSchema === 'function' ? ql.getSchema(other) : undefined) ?? ql?.registry?.getObject?.(other);
329+
} catch (cause) {
330+
throw new ActionDefinitionReadFault(other, cause);
331+
}
332+
},
333+
});
334+
} catch (error) {
335+
if (!(error instanceof ActionDefinitionReadFault)) throw error;
336+
visibility = { kind: 'fault', object: error.objectName };
337+
}
338+
if (visibility.kind === 'fault') {
339+
const fault = actionRunFieldVisibilityRefusal(visibility.object);
340+
return refuse({ message: fault.message, status: fault.status, details: { code: fault.code } });
341+
}
342+
if (visibility.kind === 'withhold') return refuse(call.unknownName ?? undeclaredActionRefusal(actionName, objectName));
256343
if (posture === 'ai') {
257344
// Fail-closed on system-object actions, PER ACTION (#27681): a `sys_*`
258345
// action passes only on its author's `ai.exposed` opt-in.
@@ -820,6 +907,7 @@ export async function dispatchActionRequest(deps: DomainHandlerDeps, request: Ac
820907
objectName,
821908
actionName,
822909
declaration: resolution.declaration,
910+
...(qualifier ? { unknownName: addressedUnknownNameRefusal(actionName, objectName, qualifier) } : {}),
823911
body: {
824912
...(request.recordId !== undefined ? { recordId: request.recordId } : {}),
825913
...(request.params !== undefined ? { params: request.params } : {}),

‎packages/runtime/src/action-execution.ts‎

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ import { actionInvocationBranch, actionInvocationFailure, actionInvocationTarget
8989
import type { HttpProtocolContext } from './http-dispatcher.js';
9090
// The ONE admitted sequence every action door shares; `invokeBusinessAction`
9191
// below is its MCP door (posture `ai`).
92-
import { refuseDispatchToDisabledObject, runResolvedAction, type ActionRefusal } from './action-dispatch.js';
92+
import { addressedUnknownNameRefusal, refusalOfThrown, refuseDispatchToDisabledObject, runResolvedAction, type ActionRefusal } from './action-dispatch.js';
9393
import { admittingCredentialKind, type AdmittingCredentialKind } from './security/admitting-credential.js';
9494
import {
9595
GLOBAL_ACTION_OBJECT_KEY,
@@ -4514,9 +4514,7 @@ export async function invokeBusinessAction(deps: ActionExecutionDeps,
45144514
if (!resolved && !askedObject) {
45154515
// No object named: nothing for the shared undeclared answer to name.
45164516
// Refused `404` as the REST door refuses a name nothing declares.
4517-
throw Object.assign(new Error(`Action '${name}' not found`), {
4518-
code: standardErrorCodeForHttpStatus(404), status: 404,
4519-
});
4517+
throw objectlessNameNotFoundError(name);
45204518
}
45214519
// [ADR-0150 D4] Set only for a qualified call: the resolved holder's
45224520
// package, whose handler the dispatch runs (the engine's package key).
@@ -4560,6 +4558,12 @@ export async function invokeBusinessAction(deps: ActionExecutionDeps,
45604558
objectName,
45614559
actionName: name,
45624560
declaration: { action, obj, ...(packageId !== undefined ? { packageId } : {}) },
4561+
// [ADR-0106 D1] This door's answer for a name nothing declares, where
4562+
// it is not the shared undeclared `404`: an action the caller is not
4563+
// shown is answered with it.
4564+
...(qualifier
4565+
? { unknownName: addressedUnknownNameRefusal(name, input?.objectName, qualifier) }
4566+
: askedObject ? {} : { unknownName: refusalOfThrown(objectlessNameNotFoundError(name)) }),
45634567
body: { params, ...(recordId !== undefined ? { recordId } : {}) },
45644568
confirmation: input,
45654569
ql: engine,
@@ -4627,6 +4631,17 @@ export async function invokeBusinessAction(deps: ActionExecutionDeps,
46274631
throw err;
46284632
}
46294633

4634+
/**
4635+
* The MCP `run_action` door's `404` for a name nothing declares, on a call
4636+
* naming no object — and, [ADR-0106 D1], for an action the caller is not
4637+
* shown, on such a call ({@link invokeBusinessAction}).
4638+
*/
4639+
function objectlessNameNotFoundError(name: string): Error & { code: string; status: number } {
4640+
return Object.assign(new Error(`Action '${name}' not found`), {
4641+
code: standardErrorCodeForHttpStatus(404), status: 404,
4642+
});
4643+
}
4644+
46304645
/**
46314646
* The MCP bridge's throw for a refusal of the shared sequence: an `Error`
46324647
* carrying the ADR-0112 envelope's `code` + `status`, and the refusal's
@@ -4796,7 +4811,7 @@ function resolveQualifiedActionDeclaration(
47964811
);
47974812
}
47984813
const inNamespace = decls.filter((d) => d.action?.name === name && d.packageId !== undefined && owners.has(d.packageId));
4799-
return pickActionHolder(addressedActionHits(inNamespace, name, objectName, `namespace '${namespace}'`), name, true);
4814+
return pickActionHolder(addressedActionHits(inNamespace, name, objectName, actionAddressScope(qualifier)), name, true);
48004815
}
48014816

48024817
/**
@@ -4811,7 +4826,27 @@ function resolveEnvironmentActionDeclaration(
48114826
objectName: string | undefined,
48124827
): { action: any; objectName: string; obj: any; packageId?: string } {
48134828
const own = decls.filter((d) => d.action?.name === name && d.packageId === undefined);
4814-
return pickActionHolder(addressedActionHits(own, name, objectName, 'the environment'), name, false);
4829+
return pickActionHolder(addressedActionHits(own, name, objectName, actionAddressScope({ environment: true })), name, false);
4830+
}
4831+
4832+
/** [ADR-0150 D5] The scope an addressed call names, as its refusals word it. */
4833+
export function actionAddressScope(qualifier: ActionAddressQualifier): string {
4834+
return 'environment' in qualifier ? 'the environment' : `namespace '${qualifier.namespace}'`;
4835+
}
4836+
4837+
/**
4838+
* [ADR-0150 D5] The `404` an addressed call answers for a name its scope
4839+
* (`where`, {@link actionAddressScope}) declares none of — and, [ADR-0106 D1],
4840+
* for an action the caller is not shown, which is answered as one
4841+
* (`action-dispatch.ts`).
4842+
*/
4843+
export function addressedActionNotFoundError(name: string, objectName: string | undefined, where: string): Error & { code: string; status: number } {
4844+
return Object.assign(
4845+
new Error(objectName
4846+
? `Action '${name}' not found on object '${objectName}' in ${where}`
4847+
: `Action '${name}' not found in ${where}`),
4848+
{ code: standardErrorCodeForHttpStatus(404), status: 404 },
4849+
);
48154850
}
48164851

48174852
/**
@@ -4845,14 +4880,7 @@ function addressedActionHits(
48454880
);
48464881
}
48474882
}
4848-
if (hits.length === 0) {
4849-
throw Object.assign(
4850-
new Error(objectName
4851-
? `Action '${name}' not found on object '${objectName}' in ${where}`
4852-
: `Action '${name}' not found in ${where}`),
4853-
{ code: standardErrorCodeForHttpStatus(404), status: 404 },
4854-
);
4855-
}
4883+
if (hits.length === 0) throw addressedActionNotFoundError(name, objectName, where);
48564884
return hits;
48574885
}
48584886

0 commit comments

Comments
 (0)