Skip to content

Commit 06b5669

Browse files
fix(runtime,service-automation)!: the flow doors judge the served holders, so a disabled holder's slot answers no bare name (ADR-0150 D3) (#33646)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D3DpgJLtDkE1fR76z3bz5Xm)_ Fixes #33386 Clause-②: yes (narrowing) — widened: a bare flow or connector name an enabled and a disabled package hold, read with no package or from a caller whose closure holds both, is served the enabled holder's slot or instance where it was refused naming both. Narrowed: the disabled holder's own callers, a caller reaching the name only through it, its address and its runs find no flow; refusals name only the packages that serve the name. With no holder of the name disabled, every answer is unchanged. Metadata-protocol: none ## 维护者速读 - 改了什么:一个流程名(或连接器名)被两个包持有、其中一个包被停用时,`/automation` 的按名门(裸名、命名空间地址、`_env`)、连接器连接门、流程动作/端点、启动准入的记录读取走查、MCP 恢复门,以及引擎的裸入口(`execute` / `getFlow` / `toggleFlow`)和运行中的子流程调用,改为只按"仍在服务的持有包"判断:剩一个就走它自己的槽位,剩两个以上 409 只点名在服务的包,一个不剩就是"没有该流程"。停用包自己的调用方拿不到流程,也绝不会被换成别的包的流程。 - 为什么改:座席裁决 6884403301(含 9 条修正)与 Q2 裁决 6888807772;此前这些门按 R4-G 保持 main 的答案(把停用包也算作持有者)。形状与邮件模板发送(#33361)相同。 - 风险与回滚:收窄一侧:停用包自己的流程动作和子流程调用、只经停用包可达的闭包调用方、指向停用包的地址、停用包槽位里的运行(含 MCP 恢复),都不再拿到流程。持久坐标(槽位键、运行键、调度键、凭据作用域、子流程守卫的武装判定)仍按全部持有者判断,停用是可逆的,不移动任何键,无需迁移。定义写入(PUT/DELETE/克隆)在指向停用包、`_env` 或第三命名空间的地址上,409 只点名在服务的包,两个都停用时地址答 404;在服务包自己的地址上仍点名全部持有者。停用包的触发器仍会触发它的槽位(与 main 相同),延后到 #33748。回滚即还原本 PR。 - 先看:`packages/services/service-automation/src/engine.ts` 的 `resolveFlowKey` / `servedBareFlowKey`(引擎裸入口与子流程调用);`packages/runtime/src/flow-slot-view.ts` 的 `servedFlowResolution` 与 `absentFlowView`(修正 4:停用包自己的调用方);`packages/runtime/src/domains/automation-address.ts` 的 `bareNameAdmission` 与 `admitAutomationAddress`。 - 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run src/flow-caller-package.test.ts src/domains/automation-addressed-route.test.ts`,预期全部通过;其中 `[#33386]` 两个 describe 按两种注册顺序逐行断言下表。 - 需要你做的:无,席位落地。 ## What changes A flow name two packages hold has one engine slot per holder (ADR-0150 D4/D9, #31696), and a connector name one instance per holder (#31699). Every door that reads such a name now judges the **served** holders (a disabled package holds no name, ADR-0150 D3), under seat ruling 6884403301 and its nine amendments, and the Q2 ruling 6888807772 for the connector address: - `packages/runtime/src/domains/automation-address.ts`: `bareNameAdmission` (new) judges a bare by-name door. It answers the one served holder's slot, or a 409 naming the served holders, or nothing (the bare path, which answers its own 404). `admitAutomationAddress` judges the qualifier over the served holders. The slot is still chosen when the name is held by two or more packages over every holder, because the slots are keyed that way (amendment 7). `bareNameRefusal` (over every holder) is unchanged and still read by the MCP resume door to tell a run row's slot. - `packages/runtime/src/domains/automation.ts`: the admission arm serves a bare name's single served holder from its slot (`flowSlotView`) or instance (`ConnectorConnectionRequest.package`), the same way its address is served. A bare flow name on an engine with no slot entries keeps the bare service, whose bare entries judge the served holders themselves. - `packages/runtime/src/flow-slot-view.ts`: `flowServiceForCaller`, `flowWalkReads` (`rootPackage`, `callee`) and `flowHolderForCaller` judge a name two packages hold over the served holders. A caller whose own holding is the disabled one gets no flow (`absentFlowView`, new), never a closure holder's (amendment 4). `runSlotPackage` no longer answers a key's own package when that package is not among the holders the caller judges by (amendment 3). `endpointPackageOf` stays judged over every holder: it names the package an endpoint belongs to, and the flow is then resolved for that package. - `packages/services/service-automation/src/engine.ts`: `resolveFlowKey` judges a name two slots hold over the served holders (`servedCaller`). One served holder gives its slot, two or more are refused naming them, and none is `absent` (no flow). `execute`, `getFlow` and `toggleFlow` read it (`servedBareFlowKey`, amendment 9). The removal and history entries (`unregisterFlow`, `withdrawFlow`, `rollbackFlow`, `getFlowVersionHistory`) keep `bareFlowKey`, over every holder. The subflow guards' recorded arming verdicts (`flowCallKey`) ask `{ durable: true }`, over every holder, as before. - `packages/services/service-automation/src/plugin.ts`: `flowNameResolver` takes `servedCaller`. A caller whose own holding answers, inside a disabled package, gets `not-found`. Without that option the resolver answers as before, so the activation ledger's `stillHolds` still finds a disabled package's own flow. ### Clause-② table CRM and HR each hold the flow `convert` (one engine slot each) and the connector `mail` (one instance each). OPS depends on CRM, BOTH depends on both, NONE on neither. Every row is pinned in both registration orders, and with HR disabled too (symmetric). With nothing disabled, every row answers as `main` does (the CONTROLs). | Row | Door / caller | State | FROM (`main`) | TO | Arm | Ruling | |:---|:---|:---|:---|:---|:---|:---| | F1 | bare name, no package: `/automation/convert` read, trigger, toggle, runs; `/automation/trigger/convert`; engine `execute` / `getFlow` / `toggleFlow`; a flow action with no package | CRM disabled | 409 naming CRM and HR | HR's slot | widening | (2), am. 1, 9 | | F2 | a caller whose closure holds both (BOTH's action, a subflow call from BOTH's flow, the walk's callee) | CRM disabled | 409 `ambiguous-in-closure` naming both | HR's slot | widening | am. 5 | | F3 | CRM's own caller (its flow action, a subflow call from CRM's flow, the walk's callee) | CRM disabled | CRM's slot ran | no flow (not found), never HR's | narrowing | am. 4 | | F4 | a caller reaching the name only through CRM (OPS) | CRM disabled | CRM's slot ran | 409 `outside-closure` naming HR | narrowing | am. 4, 6 | | F5 | a caller reaching neither (NONE) | CRM disabled | 409 naming both | 409 naming HR | names fewer | am. 6 | | F6 | address naming CRM: `/automation/crm/convert/…`, `/automation/trigger/crm/convert` | CRM disabled | CRM's slot | 409 `not-held-by-qualifier` naming HR | narrowing | am. 2 | | F7 | address naming HR | CRM disabled | HR's slot | HR's slot | none | am. 1 | | F8 | `/automation/_env/convert/…`, a third namespace | CRM disabled | 409 naming both | 409 naming HR | names fewer | am. 6 | | F9 | bare run door (`/automation/convert/runs/:runId[/…]`), a run filed under CRM's slot key | CRM disabled | served from CRM's slot (the run's own) | answered as a run nobody holds; no verb called | narrowing | am. 3 | | F10 | bare run door, a run of HR's slot; HR's address | CRM disabled | served | served (HR's slot) | none | am. 3, 8 | | F11 | MCP `resume_run` of a run filed under CRM's slot key, through CRM's or HR's flow action | CRM disabled | CRM's own action resumed it | refused (403), stays parked | narrowing | am. 3, 4 | | F12 | start admission's walk: the started flow's package (`rootPackage`) for the bare name | CRM disabled | `null` | HR | widening (the slot that executes) | am. 8 | | F13 | every caller, every door, the engine's bare entries | both disabled | 409 naming both, or a slot ran | no flow; an address answers 404; the bare name and `_env` take the bare path, which answers not found | narrowing | (1) | | F14 | durable coordinates: slot keys (`flowSlotKey`), run keys, `flowDispatchHolder`, the credential channel's `at()` / `isShared`, the subflow guards' verdicts, `bareNameRefusal` | any | judged over every holder | unchanged | none | am. 7 | | F15 | definition writes (`PUT` / `DELETE /automation/:ns/convert`, `POST …/convert/clone`) at an address naming CRM, at `_env`, at a third namespace | CRM disabled | 409 naming CRM and HR | 409 naming HR | names fewer | am. 2, 6 | | F15b | the same writes at HR's address | CRM disabled | 409 naming CRM and HR | unchanged | none | am. 7 | | F15c | the same writes at CRM's or HR's address | both disabled | 409 naming both | 404 | narrowing | (1) | | F16 | MCP `resume_run` of HR's parked run through a package-less flow action, or through BOTH's (depends on CRM and HR) | CRM disabled | refused (403) | resumed, once | widening | am. 1, 5 | | C1 | `/automation/connectors/crm/mail/connection` (names the disabled holder) | CRM disabled | the service answered 404 | 409 `not-held-by-qualifier` naming HR; the service is not asked | refusal shape | Q2 (1) | | C2 | `/automation/connectors/hr/mail/connection` (names the served holder) | CRM disabled | HR's instance (`package: HR`) | unchanged | none | Q2 (1), (2) | | C3 | `/automation/connectors/mail/connection` (bare) | CRM disabled | 409 naming both | HR's instance (`package: HR`) | widening | Q2 (1) | | C4 | `/automation/connectors/_env/mail/connection`, a third namespace | CRM disabled | 409 naming both | 409 naming HR | names fewer | Q2 (1) | | C5 | every connector address; the bare name and `_env` | both disabled | the slot (then the service's 404), or 409 naming both | an address answers 404; the bare name and `_env` reach the service with no package | narrowing | Q2 (1) | **Q2 condition 2 (legacy package-less row).** C2 was checked against a legacy connection row that names no package (`connector-connection-door.test.ts`, the case "a package-less row a second (disabled) holder makes no one package's"). Through the served holder's package, the service answers that state with the same 409 ("stored-references bind") as it answers the bare read, and the row stays. The address names the served holder's slot before and after this PR, so C2 does not move. The new case pins that answer, and it is the answer C3 now hands the bare door in that state (before: the door's own 409 naming both). Condition 3: the service's address case for the disabled holder (404) is kept as it is. A name one package holds, or none, is judged as before (CONTROLs). First-party count: no first-party composition ships a flow or connector name two packages hold and disables one of them. **Deferred:** amendment 3's trigger binding (a runtime-disabled holder's trigger still fires its slot, as on main) → #33748. **No migration.** No schema key, stored row, slot key, run key or dispatch key changes, so there is nothing to rewrite: the answers that move follow a reversible package state. The changeset says the same in visible text. ## Tests - `packages/runtime/src/flow-caller-package.test.ts`: the R4-G parity describe, whose premise this card reverses, is replaced by `the #31696 flow doors judge the served holders (ADR-0150 D3, #33386)`. It runs over a real `SchemaRegistry` (`disablePackage`, the served filter), with an engine double whose bare entries judge the served holders. Per registration order it has a CONTROL with nothing disabled, CRM disabled and HR disabled (each a full answer table over six callers, four namespaces and `_env`: rows F1 to F8 and F12 to F14), both disabled (F13), one disabled holder (CONTROL), and no holder (CONTROL). - `packages/runtime/src/domains/automation-addressed-route.test.ts`: `[#33386] the by-name doors judge the served holders…`, through the real `HttpDispatcher` over a real `SchemaRegistry`, in both orders. It covers the flow rows F1, F6, F7 and F8, the definition writes F15 to F15c, and the connector rows C1 to C5. - `packages/runtime/src/domains/automation-run-doors-per-slot.test.ts`: `[#33386] the run doors while a holder is disabled` covers rows F9 and F10 at all five run doors, with both disabled. - `packages/runtime/src/mcp-resume-run.test.ts`: rows F11 and F16, and the CONTROL (HR's run through HR's action). - `packages/services/service-automation/src/flow-slots-per-package.test.ts`: the engine's R4-G parity describe is replaced by `[#33386] a run of a name two slots hold judges the served holders`. It runs on the real engine and the real `flowNameResolver` over a real `SchemaRegistry`, with a runtime disable (both slots armed) and a boot disable (one armed), in both orders. It covers F1 to F5, the slot keys and dispatch key unmoved (F14), and both disabled (`execute` / `getFlow` / `toggleFlow`: not found). - `packages/services/service-automation/src/connector-connection-door.test.ts`: the Q2 condition 2 case (above). - Refusals are asserted by envelope (`code` `RESOURCE_CONFLICT`, status 409) and candidates. ## Acceptance notes - **The definition writes (amendments 2, 6, 7).** `PUT` / `DELETE /automation/:ns/:name` and the clone, at the served holder's own address, keep their 409 naming every holder (F15b). At an address naming the disabled holder, at `_env` or at a third namespace, the address admission now refuses them 409 naming the served holder only (F15), and with both holders disabled an address answers 404 (F15c). An earlier draft of this note and of the changeset said every such write keeps its 409 naming every holder; that was wrong and is corrected. A bare definition write (`PUT /automation/convert`) is refused by the metadata store over its stored rows (`flowWriteRefusal`), which this PR does not touch; it is not pinned here. - **Deferred: amendment 3's trigger binding.** A runtime-disabled holder's trigger still fires its own slot (the engine's `triggerRun` executes the armed slot key with no served check), as on `main`; nothing is substituted. Deferred by the seat to #33748. - **Not moved: the anonymous inbound hook** (`inboundHookSlot`, `/automation/hooks/:name`). Its bare form for a name two slots hold stays refused, and its log names every holder. The ruling's nine amendments do not name it. It is an anonymous door whose refusal is logged, not answered. A design question, raised in the report. - **Not moved: `endpointPackageOf`.** An endpoint's own package is read over every holder of its `api` name, and the endpoint's flow is then resolved for that package (served, F3/F4). An `api` name two packages hold, one disabled, still names no package there. Raised in the report. - **Not moved: a name one package holds, disabled.** Read from the code, not pinned here: the bare doors and the engine's bare entries still serve the one disabled holder's flow (a not-shared name is outside R4-G; its address already answers 404, pinned). Raised in the report as a separate question. - The subflow guards (`flowCallKey`: arming verdicts recorded at registration) keep reading over every holder. A disable re-judges nothing, so a served reading there would record a verdict the next enable contradicts (AGENTS.md, startup registry reads). ## Verification **At head `99fca269`** (review#3 should-fixes, on top of a merge of `origin/main` at `9bb45bb9`). Since `4a3db01c` only tests and text changed: `.changeset/33386-flow-doors-served-holders.md` (+6/-1), `automation-addressed-route.test.ts` (+31/-2: one pin, F15 to F15c, and a body argument for its call helper), `mcp-resume-run.test.ts` (+19: F16). No source file changed, so the dependents and the dogfood battery were not re-run. - `pnpm --filter @objectstack/runtime test`: Test Files 603 passed (603), Tests 10902 passed, 19 skipped (10921). VERDICT command-exit 0. - `pnpm --filter @objectstack/service-automation test`: Test Files 282 passed (282), Tests 3977 passed (3977). VERDICT command-exit 0. - `pnpm --filter @objectstack/service-automation --filter @objectstack/runtime typecheck`: VERDICT command-exit 0 (both `check:test-typecheck: OK`). - `check-adr-0087-registration --base origin/main`, `check-changeset-no-major`, `check-empty-changeset`, `check-changeset-fixed`, `check-nul-bytes`, `eslint --no-inline-config` on the two touched tests: each exit 0. The readings below are at `4a3db01c` (after merging `origin/main` at `dd291b83`), unless named. **Status: done.** All nine amendments of ruling 6884403301 and the three Q2 conditions are implemented and pinned, except amendment 3's trigger binding, deferred to #33748 (table rows above; amendment 9's engine bare entries `execute` / `getFlow` / `toggleFlow` move in this PR). Not done: see the last list. <details><summary>Tests (lock VERDICT per step, every step exit 0)</summary> - `pnpm --filter @objectstack/runtime test`: Test Files 603 passed (603), Tests 10857 passed, 19 skipped (10876). - `pnpm --filter @objectstack/service-automation test`: Test Files 282 passed (282), Tests 3977 passed (3977). - `pnpm --filter @objectstack/service-automation --filter @objectstack/runtime typecheck`: exit 0 (both `check:test-typecheck: OK`). - `src/mcp-resume-run.test.ts`: 45 passed. - Direct dependents of runtime and service-automation, `test`: hono 258, example-crm 51, connector-mcp 119, connector-openapi 111, connector-rest 57, connector-slack 10, plugin-dev 89, cloud-connection 1211, trigger-record-change 122, trigger-schedule 256, client 812, plugin-approvals 1652, example-todo 249, example-showcase 545, http-conformance 292, verify 437: all passed. `@objectstack/cli` unit layer: Test Files 421 passed (421), Tests 5979 passed (integration layer declared to CI). `objectstack-blank`: NOT MEASURED, reason: not a workspace project (the filter matches nothing). - Full dogfood battery (owed by the narrowing arm), `pnpm --filter @objectstack/dogfood test` at `4a3db01c`: Test Files 467 passed, 3 skipped (470); Tests 3958 passed, 42 skipped (4000). - `eslint --no-inline-config` on the touched files: exit 0. </details> <details><summary>Ablations (each through `scripts/ablation-replace.mjs`, restored to the HEAD blob; `git diff HEAD` empty after)</summary> Run at `e4729b39` (pre-merge; the four source files are identical at the head): - A1, the engine's `resolveFlowKey` asks over every holder (`{ includeDisabledPackages: true }` for the run): `flow-slots-per-package.test.ts` 10 of 51 red. - A2, `admitAutomationAddress` judges a shared name over every holder: runtime 3 files, 22 of 158 red. - A3, `servedFlowResolution` without the disabled-own-caller branch (amendment 4): 6 of 158 red. - A4, the plugin resolver's `servedCaller` branch disabled: `flow-slots-per-package.test.ts` 6 of 51 red. - A5, `bareNameAdmission` reads the served resolution over every holder: 22 of 158 red. </details> <details><summary>Gates</summary> - Derived local families (`dispatch-gates.mjs --commands`, 74 at `4a3db01c`): 71 exit 0. `check-adr-0087-registration --base origin/main` exit 0 (`not-required (no-migration-prescription)` read). `node scripts/check-plugin-teardown-shape.mjs --self-test`: NOT MEASURED, exit 3 PREREQUISITE (the shallow clone cannot reach its pinned positive control). `pnpm check:dual-build-cjs-loads`: NOT MEASURED, it reads every package's `dist/`; CI runs it. `pnpm check:type-check-debt`: exit 0 at `e4729b39`; NOT MEASURED at `4a3db01c` (its closure build lost the lock to the dogfood run, then the re-run was stopped at hand-over). - The CI families: in progress at hand-over; the seat reads the PR's check-runs. </details> ### Not done - `check:type-check-debt` re-run at the head (exit 0 at `e4729b39`; NOT MEASURED since). The CI families at `99fca269`: the seat reads the PR's check-runs. - Amendment 3's trigger binding: deferred to #33748 (see above). - The PR body is still the draft's: this text is for the seat to post (the dev does not PATCH a PR body). - Raised for decision (not changed here): the anonymous inbound hook's bare refusal, `endpointPackageOf` for an `api` name two packages hold, and a one-holder disabled name at the bare doors (Acceptance notes). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016WV4cx5ZPCyTk8ckTsx4ut <!-- signed: domain:server#5 · os-elon-musk · session_016WV4cx5ZPCyTk8ckTsx4ut --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 12a0f09 commit 06b5669

12 files changed

Lines changed: 752 additions & 155 deletions
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
'@objectstack/runtime': patch
3+
'@objectstack/service-automation': patch
4+
---
5+
6+
fix(runtime,service-automation)!: the flow doors and the connector address judge the served holders of a name two packages hold, so a disabled holder's slot answers no bare name (ADR-0150 D3, #33386)
7+
8+
Clause-②: yes (narrowing)
9+
Metadata-protocol: none
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export changes shape. The moved answers are door and run reads under a reversible package state: no stored row, slot key, run key or dispatch key changes, so there is nothing for a migration to rewrite and no tombstone. -->
12+
13+
**BREAKING** for a caller of a flow or connector name that two packages hold while one of them is disabled. A disabled package holds no name (ADR-0150 D3). Until now the `/automation` by-name doors, the flow action and endpoint, the start admission's record-read walk and the engine's bare entries still counted a disabled holder for such a name. They now count only the packages that serve it. With no holder disabled, every answer is unchanged. Measured over a real `SchemaRegistry` (its `disablePackage`), in both registration orders. Packages CRM and HR each hold the flow `convert` and the connector `mail`, one engine slot or instance each, and CRM is disabled:
14+
15+
- A bare name with no package (`POST /automation/convert/trigger`, `GET /automation/convert`, the run doors, `GET /automation/connectors/mail/connection`, the engine's `execute`, `getFlow` and `toggleFlow`) was refused 409 naming CRM and HR. It is now served from HR's slot or instance.
16+
- A flow action, a subflow call or a walk read from a package whose closure holds both was refused 409 naming both. It now reaches HR's flow (widening).
17+
- CRM's own flow action, or a subflow call from CRM's own flow, ran CRM's flow. It now gets no flow (not found), and never HR's.
18+
- A package that reaches the name only through CRM ran CRM's flow. It is now refused 409 `outside-closure` naming HR. A package that reaches neither holder is refused naming HR only (before: both).
19+
- An address naming CRM (`/automation/crm/convert/…`, `/automation/trigger/crm/convert`) ran CRM's slot. It is now refused 409 `not-held-by-qualifier` naming HR. `/automation/connectors/crm/mail/connection` reached the service, which answered 404; it is now refused 409 naming HR, and the service is not asked.
20+
- `_env` or another namespace (`/automation/_env/convert/…`, `/automation/connectors/ops/mail/connection`) was refused 409 naming both. It is now refused naming HR only.
21+
- The definition writes (`PUT`, `DELETE`, clone) at an address naming CRM, at `_env` or at a third namespace were refused 409 naming both. They are now refused 409 naming HR only. With both disabled, such a write at an address answers 404.
22+
- With CRM and HR both disabled, no door and no run reaches a flow. An address answers 404. The bare name and `_env` answer as for a flow the engine does not hold.
23+
24+
**Not moved.** HR's own address and HR's own callers answer as before. The durable coordinates stay judged over every holder, served or not: the engine's slot keys, a run's key, the schedule dispatch key (`flowDispatchHolder`), the credential channel's scoping, the subflow guards' arming verdicts, and which slot a run row is filed under. A disable is reversible, so it re-points no slot. A run filed under CRM's slot key is no served holder's: the run doors answer it as a run nobody holds, and it is never read or acted on as HR's. A definition write (`PUT`, `DELETE`, clone) at HR's own address keeps its 409 naming every holder; a bare definition write is refused by the metadata store over its stored rows, as before. A name only one package holds is judged as before.
25+
26+
**Deferred:** amendment 3's trigger binding (a runtime-disabled holder's trigger still fires its slot, as on main) → #33748.
27+
28+
**No migration.** No schema key, stored row, slot key, run key or dispatch key changes, so there is nothing to rewrite: the answers that move follow a reversible package state.
29+
30+
The fix for a caller: re-enable the package, or address the served holder by its namespace.

‎packages/runtime/src/domains/automation-address.ts‎

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,27 @@
7373
* {@link bareNameRefusal} is the same resolution for a bare address: a bare
7474
* name the resolver refuses is answered `409` naming every candidate (D5), on
7575
* the doors whose own answer was no such `409`.
76+
*
77+
* [ADR-0150 D3, #33386; seat ruling 6884403301] A name two or more packages
78+
* hold, one of them disabled, is judged over the SERVED holders at the doors
79+
* (a disabled package holds no name), the shape the email send took
80+
* (plugin-email `template-loader.ts`):
81+
*
82+
* - a bare name ({@link bareNameAdmission}): one served holder is that
83+
* holder's slot, two or more are refused naming the served holders only,
84+
* and none is no item (the door's own `404`). A slot is `(package, name)`
85+
* and is never re-pointed: a disable only moves which slot the bare name
86+
* reaches;
87+
* - an address naming the disabled holder's namespace is never another
88+
* package's item: `not-held-by-qualifier` naming the served holders, or
89+
* `404` when none remains; `_env` and any other namespace name the served
90+
* holders only.
91+
*
92+
* The durable coordinates stay judged over EVERY holder (amendment 7): the
93+
* engine's slot keys, a run's key, and {@link bareNameRefusal}, which the MCP
94+
* resume door reads to tell a run row's slot. So does the refusal a slot
95+
* carries for the doors that cannot serve from the slot (the definition
96+
* writes): a write targets the name every holder holds.
7697
*/
7798

7899
import {
@@ -259,6 +280,33 @@ export function bareNameRefusal(
259280
return resolution.status === 'refused' ? resolution : undefined;
260281
}
261282

283+
/**
284+
* [ADR-0150 D3, #33386] A BARE by-name door's admission (see the module note):
285+
* the bare name's `409` naming the served holders when two or more serve it,
286+
* the slot of its one served holder when the name is held by two or more
287+
* packages over every holder (each holder's item is then its own slot), and
288+
* `undefined` otherwise — the bare path, as before, which answers its own
289+
* `404` when no served holder remains. A name held by one package or none is
290+
* judged as {@link bareNameRefusal} judges it, unchanged. Read-only.
291+
*/
292+
export function bareNameAdmission(
293+
registry: AutomationAddressRegistry | undefined,
294+
type: 'flow' | 'connector',
295+
name: string,
296+
): AutomationAddressRefusal | AutomationAddressSlot | undefined {
297+
if (!registry || !canResolve(registry)) return undefined;
298+
const every = resolvePackageScopedName(registry, { type, name, callerPackageId: null, includeDisabledPackages: true });
299+
if (every.status !== 'refused' || holdersOf(registry, type, name, { includeDisabledPackages: true }).length < 2) {
300+
return every.status === 'refused' ? { status: 409, refusal: every } : undefined;
301+
}
302+
const served = resolvePackageScopedName(registry, { type, name, callerPackageId: null });
303+
if (served.status === 'refused') return { status: 409, refusal: served };
304+
if (served.status === 'resolved' && served.holder.kind === 'package') {
305+
return { status: 'slot', packageId: served.holder.packageId, refusal: every };
306+
}
307+
return undefined;
308+
}
309+
262310
/**
263311
* Judge an addressed path's qualifier (see the module note). `undefined`
264312
* admits it: the path is then served as its bare path, whose item is the
@@ -279,14 +327,16 @@ export function admitAutomationAddress(
279327
? undefined
280328
: { status: 404, message: `${noun} '${name}' not found in namespace '${qualifier.namespace}'` };
281329
}
282-
// [#32183, R4-G] A name two or more packages hold over every holder (the
283-
// state #31696 opened for a flow, each holder's flow in its own engine
284-
// slot) is judged over every holder, a disabled package's included, so a
285-
// disable moves no address of it (`main`'s answer). A one-holder name is
286-
// judged over the served holders, as every by-name door is.
330+
// [ADR-0150 D3, #33386] Judged over the served holders, as every by-name
331+
// door is: a disabled package holds no name, so an address naming it is
332+
// never another package's item, and a refusal names the served holders
333+
// only (seat ruling 6884403301, amendments 2 and 6). A name two or more
334+
// packages hold over EVERY holder (the state #31696 opened, each holder's
335+
// item in its own engine slot) is still served from the addressed
336+
// holder's slot: the slots are keyed over every holder (amendment 7).
287337
const everyHolder = holdersOf(registry, type, name, { includeDisabledPackages: true });
288338
const shared = everyHolder.length > 1;
289-
const holders = shared ? everyHolder : holdersOf(registry, type, name);
339+
const holders = holdersOf(registry, type, name);
290340
let holder: PackageScopedHolder;
291341
if (qualifier.kind === 'environment') {
292342
if (registry.getEnvironmentScopedItem(type, name) !== undefined || holders.length === 0) return undefined;
@@ -313,7 +363,9 @@ export function admitAutomationAddress(
313363
// [#31696] A flow name two packages hold: each holder's flow is its own
314364
// slot, and the address names one holder of it. [ADR-0150 D9, #31699]
315365
// So is a connector name: each holder's instance is its own, and the
316-
// connection door connects the addressed one.
366+
// connection door connects the addressed one. [#33386] The addressed
367+
// holder is a served one (above); the slot's refusal, for the doors
368+
// that cannot serve from it, stays the name's over every holder.
317369
return (type === 'flow' || type === 'connector') && holder.kind === 'package'
318370
? { status: 'slot', packageId: holder.packageId, refusal: bare }
319371
: { status: 409, refusal: bare };

‎packages/runtime/src/domains/automation-addressed-route.test.ts‎

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { describe, it, expect, vi } from 'vitest';
2121
import '@objectstack/metadata';
2222

2323
import { HttpDispatcher } from '../http-dispatcher.js';
24+
import { SchemaRegistry } from '@objectstack/objectql';
2425

2526
const CRM = 'com.crm.pkg';
2627
const HR = 'com.hr.pkg';
@@ -492,3 +493,146 @@ describe('/automation/connectors/:ns/:name/connection — a connector instance b
492493
expect(automation.getConnectorConnection).not.toHaveBeenCalled();
493494
});
494495
});
496+
497+
/**
498+
* [ADR-0150 D3, #33386; seat rulings 6884403301 and Q2 6888807772] A name two
499+
* packages hold, one of them disabled, through the real dispatcher over a real
500+
* `SchemaRegistry` (its `disablePackage`, its served filter), in both
501+
* registration orders. The doors judge the SERVED holders: the bare name is the
502+
* one served holder's slot or instance; an address naming the disabled holder
503+
* is refused naming the served holder only; `_env` and a third namespace name
504+
* the served holder only; with both disabled, nothing is reached.
505+
*/
506+
describe('[#33386] the by-name doors judge the served holders of a name two packages hold', () => {
507+
const OPS = 'com.ops.pkg';
508+
const ORDERS = [[CRM, HR], [HR, CRM]];
509+
510+
function registryOf(order: readonly string[], disabled: readonly string[]) {
511+
const registry = new SchemaRegistry();
512+
registry.logLevel = 'silent';
513+
for (const [id, namespace] of [[CRM, 'crm'], [HR, 'hr'], [OPS, 'ops']]) {
514+
registry.installPackage({ id, name: id, version: '1.0.0', type: 'app', namespace } as never, 'code');
515+
}
516+
for (const holder of order) {
517+
registry.registerItem('flow', { name: 'convert', _packageId: holder }, 'name' as never, holder);
518+
registry.registerItem('connector', { name: 'mail', _packageId: holder }, 'name' as never, holder);
519+
}
520+
for (const id of disabled) registry.disablePackage(id);
521+
return registry;
522+
}
523+
524+
function dispatcherOver(registry: SchemaRegistry) {
525+
const slotOf = (pkg: string | null, name: string) => (name === 'convert' && pkg !== null && [CRM, HR].includes(pkg) ? `${pkg}/convert` : undefined);
526+
const automation = {
527+
handlerReady: true,
528+
getFlow: vi.fn(async () => null),
529+
execute: vi.fn(async (name: string) => ({ success: false, error: `Flow '${name}' not found` })),
530+
toggleFlow: vi.fn(async () => {}),
531+
listRunsPage: vi.fn(async () => ({ runs: [] as unknown[], hasMore: false })),
532+
getConnectorConnection: vi.fn(async (request: { connector: string }) => ({ connector: request.connector, status: 'not_connected' })),
533+
getActionDescriptors: vi.fn(() => []),
534+
getFlowRuntimeStates: vi.fn(() => []),
535+
flowSlotKey: vi.fn(slotOf),
536+
getFlowSlot: vi.fn((pkg: string | null, name: string) => (slotOf(pkg, name) ? { name, label: `${pkg} flow` } : null)),
537+
executeSlot: vi.fn(async (pkg: string | null) => ({ success: true, output: { ran: pkg } })),
538+
toggleFlowSlot: vi.fn(async () => {}),
539+
};
540+
const services: Record<string, unknown> = { automation, objectql: { registry } };
541+
const resolve = (name: string) => services[name];
542+
const kernel: any = { getService: resolve, getServiceAsync: async (name: string) => resolve(name), context: { getService: resolve } };
543+
const dispatcher = new HttpDispatcher(kernel);
544+
const call = async (path: string, method: string, body: unknown = {}) => {
545+
const answered = await dispatcher.handleAutomation(path, method, body, { request: {}, executionContext: ADMIN } as any, {});
546+
return { status: answered.response?.status ?? 200, body: answered.response?.body as any };
547+
};
548+
return { call, automation };
549+
}
550+
551+
const packagesOf = (a: { body?: any }) => (candidatesOf(a) ?? []).map((c: { packageId?: string }) => c.packageId);
552+
553+
describe.each(ORDERS.map((order) => [order.join(' then '), order] as const))('registered %s', (_o, order) => {
554+
it('CONTROL — nothing disabled: the bare doors refuse naming both; each address is its own slot or instance', async () => {
555+
const { call, automation } = dispatcherOver(registryOf(order, []));
556+
const bare = await call('/convert/trigger', 'POST');
557+
expect([bare.status, packagesOf(bare)]).toEqual([409, [...order]]);
558+
const mail = await call('/connectors/mail/connection', 'GET');
559+
expect([mail.status, packagesOf(mail)]).toEqual([409, [...order]]);
560+
expect((await call('/crm/convert/trigger', 'POST')).status).toBe(200);
561+
expect(automation.executeSlot.mock.calls.map((c) => c[0])).toEqual([CRM]);
562+
expect((await call('/connectors/hr/mail/connection', 'GET')).status).toBe(200);
563+
expect(automation.getConnectorConnection.mock.calls.at(-1)?.[0]).toMatchObject({ connector: 'mail', package: HR });
564+
});
565+
566+
it('CRM disabled — flow: the bare door runs HR\'s slot (FROM 409 naming both); CRM\'s address is refused naming HR (FROM CRM\'s slot ran); HR\'s address is HR\'s slot', async () => {
567+
const { call, automation } = dispatcherOver(registryOf(order, [CRM]));
568+
expect((await call('/convert/trigger', 'POST')).status).toBe(200);
569+
expect(automation.executeSlot.mock.calls.map((c) => c[0])).toEqual([HR]);
570+
const off = await call('/crm/convert/trigger', 'POST');
571+
expect([off.status, codeOf(off), packagesOf(off)]).toEqual([409, 'RESOURCE_CONFLICT', [HR]]);
572+
expect((await call('/hr/convert/trigger', 'POST')).status).toBe(200);
573+
for (const path of ['/_env/convert/trigger', '/ops/convert/trigger']) {
574+
const other = await call(path, 'POST');
575+
expect([path, other.status, packagesOf(other)]).toEqual([path, 409, [HR]]);
576+
}
577+
expect(automation.executeSlot.mock.calls.map((c) => c[0])).toEqual([HR, HR]);
578+
expect(automation.execute).not.toHaveBeenCalled();
579+
});
580+
581+
it('CRM disabled — connector (Q2 rows): the address naming CRM is refused naming HR (FROM 404 from the service); HR\'s address and the bare name connect HR\'s instance (bare FROM 409 naming both); `_env` and a third namespace name HR only (FROM naming both)', async () => {
582+
const { call, automation } = dispatcherOver(registryOf(order, [CRM]));
583+
const off = await call('/connectors/crm/mail/connection', 'GET');
584+
expect([off.status, codeOf(off), packagesOf(off)]).toEqual([409, 'RESOURCE_CONFLICT', [HR]]);
585+
expect(automation.getConnectorConnection).not.toHaveBeenCalled();
586+
for (const path of ['/connectors/hr/mail/connection', '/connectors/mail/connection']) {
587+
expect((await call(path, 'GET')).status, path).toBe(200);
588+
expect(automation.getConnectorConnection.mock.calls.at(-1)?.[0], path).toMatchObject({ connector: 'mail', package: HR });
589+
}
590+
for (const path of ['/connectors/_env/mail/connection', '/connectors/ops/mail/connection']) {
591+
const other = await call(path, 'GET');
592+
expect([path, other.status, packagesOf(other)]).toEqual([path, 409, [HR]]);
593+
}
594+
expect(automation.getConnectorConnection).toHaveBeenCalledTimes(2);
595+
});
596+
597+
it('the definition writes (PUT, DELETE, clone) under a disable: an address naming CRM, `_env` or a third namespace is refused naming HR only (FROM: naming both); HR\'s address still names both; both disabled, an address answers 404 (FROM: 409)', async () => {
598+
const writes = (prefix: string) => [
599+
[`${prefix}/convert`, 'PUT', { name: 'convert', type: 'autolaunched' }],
600+
[`${prefix}/convert`, 'DELETE', {}],
601+
[`${prefix}/convert/clone`, 'POST', { name: 'convert_copy' }],
602+
] as const;
603+
const oneOff = dispatcherOver(registryOf(order, [CRM]));
604+
for (const prefix of ['/crm', '/_env', '/ops']) {
605+
for (const [path, method, body] of writes(prefix)) {
606+
const answer = await oneOff.call(path, method, body);
607+
expect([path, method, answer.status, codeOf(answer), packagesOf(answer)]).toEqual([path, method, 409, 'RESOURCE_CONFLICT', [HR]]);
608+
}
609+
}
610+
// Not moved: HR's own address keeps the 409 naming every holder.
611+
for (const prefix of ['/hr']) {
612+
for (const [path, method, body] of writes(prefix)) {
613+
const answer = await oneOff.call(path, method, body);
614+
expect([path, method, answer.status, packagesOf(answer).sort()]).toEqual([path, method, 409, [CRM, HR].sort()]);
615+
}
616+
}
617+
const bothOff = dispatcherOver(registryOf(order, [CRM, HR]));
618+
for (const prefix of ['/crm', '/hr']) {
619+
for (const [path, method, body] of writes(prefix)) {
620+
expect([path, method, (await bothOff.call(path, method, body)).status]).toEqual([path, method, 404]);
621+
}
622+
}
623+
for (const h of [oneOff, bothOff]) expect(h.automation.executeSlot).not.toHaveBeenCalled();
624+
});
625+
626+
it('both disabled: no address reaches a flow or an instance (404); the bare door and `_env` reach no slot, and the service answers them with no package', async () => {
627+
const { call, automation } = dispatcherOver(registryOf(order, [CRM, HR]));
628+
for (const path of ['/crm/convert/trigger', '/hr/convert/trigger']) expect((await call(path, 'POST')).status, path).toBe(404);
629+
for (const path of ['/connectors/crm/mail/connection', '/connectors/hr/mail/connection']) expect((await call(path, 'GET')).status, path).toBe(404);
630+
expect((await call('/convert/trigger', 'POST')).status).toBe(404);
631+
expect(automation.executeSlot).not.toHaveBeenCalled();
632+
for (const path of ['/connectors/mail/connection', '/connectors/_env/mail/connection']) {
633+
await call(path, 'GET');
634+
expect(automation.getConnectorConnection.mock.calls.at(-1)?.[0], path).not.toHaveProperty('package');
635+
}
636+
});
637+
});
638+
});

0 commit comments

Comments
 (0)