Skip to content

Commit 4d5cfa9

Browse files
fix(automation): status rows of a flow name two packages hold carry their package; the toggle reads back the switched slot (#38652)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9RgRdwG1S43a4gfYWB4Ytyp)_ Fixes #34891 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 管理员在自动化页面开关一个由两个已安装包同名持有的流程时,开关回显的状态从"照抄请求"变为"读回该包流程实际存储的状态";状态接口每行多带所属包。 - 属于"一个名字多个包各自持有"的包作用域收口,替管理员解决开关显示与流程实际是否运行不一致的问题。 - 若出错,影响面是这类同名流程的开关回显,流程本身的开关写入不变;可直接撤回本改动。 - 无 ## What changes - `FlowRuntimeState` (`@objectstack/spec/contracts`) gains an optional `packageId`: the package of the engine slot the row reads (ADR-0150 D4, one slot per package and name), absent for a flow no package holds. The spelling is the slot's own (`FlowSlot.packageId`, `FlowContender.packageId`, the activation ledger row's `packageId`). - `getFlowRuntimeStates` (service-automation `flow-definitions.ts`) stamps it on every row of a package-held slot, read from the engine's `flowSlotPackage(key)`. The engine wrapper's duplicated inline return type is replaced by one `FlowRuntimeStateRow` type (`FlowRuntimeState` plus the shadowing receipt), and the wrapper's host passes `flowSlotPackage`. - The toggle door (`packages/runtime/src/domains/automation.ts`) records the package of the slot it serves when the admission hands it a `flowSlotView`, and reads back the row of `(that package, name)`. The two-or-more-rows echo is gone for that case. The request is still echoed in three cases, the same three the route table, the door comment and the changeset name: a service that does not implement `getFlowRuntimeStates`; a reading that holds no row of the switched flow; and two or more rows of the name on a door serving no slot, which the composed runtime cannot reach because the bare `toggleFlow` refuses a shared name (see Acceptance notes). - Landing point is the claim's file surface. One test file outside the literal surface: the producer pins went into `packages/services/service-automation/src/flow-slots-per-package.test.ts` as a new top-level `describe`, because that file is the engine's per-slot harness and a pin for a component with a shared harness goes there. Test-only. Read first, by risk: 1. `packages/runtime/src/domains/automation.ts`, the toggle arm's read-back filter (the `flowSlotPackage` capture at the admission block and the `rows` filter). 2. `packages/services/service-automation/src/flow-definitions.ts`, `getFlowRuntimeStates` (the `packageOf` spread). 3. `packages/spec/src/contracts/automation-service.ts`, the new `packageId` member. ## Tests - Door (`automation-addressed-route.test.ts`, the co-held toggle suite): the double now reads rows the engine's way, each carrying its slot's `packageId`, and composes a status that keeps a slot off apart from the switch. New red line: the switched slot is republished `obsolete` while the switch awaits its durable write; the door answers `200 { enabled: false }`. The three existing co-held cases now pass by read-back, not by echo. - Engine (`flow-slots-per-package.test.ts`, new `describe` "the status rows carry their slot's package"): a co-held name's two rows each carry their own package and own state; a one-holder name's row carries its package and a package-less flow's row has no `packageId` key; and the race measured on the real engine: with the activation store's write held open, P2's flow republished `obsolete` mid-switch, `toggleFlowSlot` resolves, two rows of the name exist, P2's own row reads `enabled: false, status: 'obsolete'`, and `executeSlot` refuses `FLOW_DISABLED`. The race the card describes can be reached as written. - Spec type pin: `FlowRuntimeState['packageId']` is `string | undefined`. - `automation-toggle-caller.test.ts` is unchanged: the no-read echo stays pinned there. <details><summary>Ablations (each restored: blob equals HEAD, git diff HEAD empty)</summary> - Producer: deleted the `...packageOf(this.flowSlotPackage(name)),` line (`scripts/ablation-replace.mjs`, mutation landed: anchor 1 to 0). `flow-slots-per-package.test.ts -t 'status rows carry'`: `Tests 3 failed | 92 skipped (95)`, all three new engine cases red. - Door: replaced the package filter with `true` (mutation landed: anchor 1 to 0). Runtime toggle files: `Tests 1 failed | 65 passed (66)`. The red is the obsolete-republish case, answering `{"name":"convert","enabled":true}`, which is the card's defect. A first attempt used replacement text that already occurred in the file; the tool refused it and restored before running anything, so that attempt measured nothing. </details> <details><summary>Suites (head 72f56b4)</summary> - `pnpm --filter @objectstack/service-automation test`: Test Files 299 passed (299), Tests 4442 passed (4442), exit 0. - `pnpm --filter @objectstack/runtime test`: Test Files 656 passed (656), Tests 12522 passed, 25 skipped (12547), exit 0. - `pnpm --filter @objectstack/spec test`: Test Files 913 passed (913), Tests 28893 passed, 1 todo (28894), exit 0. - `turbo run typecheck` for spec, service-automation and runtime: 44 tasks successful. The runtime test layer first failed TS2307 on `@objectstack/driver-turso` in three files this diff does not touch, because that devDependency was not built in this worktree. After building it: `check:test-typecheck: OK` for both packages. </details> ## Acceptance notes - The echo that remains: a service whose reading holds NO row of the switched flow. For the engine on the co-held path that happens only if the slot is withdrawn while the switch is in flight, which is another race than this card's. That arm was already the behaviour before this change and is pinned by other suites in the same file, whose doubles read no rows. Left as it is. - A bare toggle (no slot view) still reads the name's one row. Two rows on a bare door would need an engine with a name resolver but a door with no registry. Bare `toggleFlow` refuses a shared name otherwise, so that case is not reachable in the composed runtime. - `flowRuntimeStateOf` (`packages/types/src/flow-runtime-state.ts`, the MCP definition reader's switch) still answers `undefined` on two rows of one name. It could pick by `packageId` once its callers pass the item's package. Not changed here: it is outside this card's surface, and it fails closed ("unknown is answered as absent, never as enabled"). - Other row readers are untouched, because the field is optional: `packages/client` (`getRuntimeStatus` docblock lists the optional members and does not yet name `packageId`), `packages/cli` `serve.ts`, and the Console under `ui/`. A Console status badge for a co-held name could pick its row by `(packageId, name)`. No `ui/` change is in this PR. ## Verification Two-minute check: `pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/domains/automation-addressed-route.test.ts -t 'republished'`. Expected: 1 passed. The obsolete-republish case answers `{ enabled: false }`. <details><summary>Local gates (derived from dispatch-gates --commands at 72f56b4)</summary> - 100 derived families run. `dispatch-gates --ran` with exit codes recorded: `100 derived famil(ies) accounted for — 98 run, 2 NOT-MEASURED (2 DERIVED from a recorded exit 3)`. - NOT MEASURED: `check:dual-build-cjs-loads`, reason: PREREQUISITE NOT MET, it reads every package's built output and 38 packages have no `dist/` in this worktree. `check:published-readme-exports`, reason: PREREQUISITE NOT MET, 32 packages' built type entries are missing. Both are left to CI. - Every other derived family exited 0, among them `check:api-surface`, `check:authorable-surface`, `check:docs`, `check:export-origins`, `check:engine-double-contract`, `check:nul-bytes`, `check:cross-package-test-inputs` and `check:test-source-alias`. - `overlap-check.mjs` before each push: `VERDICT clean exit 0` against origin/main and #38618, which shares `engine.ts` and merges cleanly. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmQJUGAAa5rz9Yi2DvW)_ <!-- signed: repo:objectstack#3 · os-steve · session_01ADHkmQJUGAAa5rz9Yi2DvW --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 74a15cb commit 4d5cfa9

8 files changed

Lines changed: 196 additions & 45 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/spec': patch
3+
'@objectstack/service-automation': patch
4+
'@objectstack/runtime': patch
5+
---
6+
7+
fix(automation): status rows of a flow name two packages hold carry their package, so the toggle answers the switched flow's stored state
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: none
11+
12+
`FlowRuntimeState` (`@objectstack/spec/contracts`) gains an optional `packageId`: the package of the engine slot the row reads (ADR-0150 D4, one slot per package and name), absent for a flow no package holds. `getFlowRuntimeStates()`, and so `GET /automation/_status`, now stamps it on every row of a package-held flow, so the two rows of a name two packages hold are told apart by `(packageId, name)`.
13+
14+
`POST /automation/NAME/toggle` (and its namespaced address) on such a name now answers the stored state of the slot it switched, read back from that slot's own row. It used to echo the request whenever the name had two rows, so a flow republished `obsolete` while the switch awaited its durable write was answered `enabled: true` though it does not run. The request is still echoed by a service that does not implement `getFlowRuntimeStates`, by one whose reading holds no row of the switched flow, or, on a door serving no package's slot, when two or more rows carry the name; the composed runtime never reaches that last case, because the bare `toggleFlow` refuses a name two packages hold.
15+
16+
A reader that means one package's flow of a shared name picks its row by both `packageId` and `name`; a row picked by `name` alone may be the other holder's.

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -729,10 +729,16 @@ describe('[#33905] a flow whose only holder\'s package is disabled: the bare doo
729729
* name there is the FIRST holder's, so each case switches the holder
730730
* registered SECOND, with the first one's row reading the opposite state.
731731
*
732+
* Each row carries its slot's `packageId`, so the door reads back the row of
733+
* the slot it switched: the answer is that slot's STORED state, and where the
734+
* stored state is not the request (the slot republished `obsolete` while the
735+
* switch awaits its durable write) the answer is the stored state, never the
736+
* request echoed.
737+
*
732738
* Driven through the real dispatcher over a real `SchemaRegistry`, and an
733739
* engine double that keeps each slot's state, switches it in `toggleFlowSlot`
734740
* and reads it back the engine's way (`getFlowRuntimeStates`: one row per
735-
* slot, under the bare name).
741+
* slot, under the bare name, carrying the slot's package).
736742
*/
737743
describe('[ADR-0126 §7.2] the toggle door answers the switched slot, on a name two packages hold', () => {
738744
const NAME = 'convert';
@@ -751,13 +757,16 @@ describe('[ADR-0126 §7.2] the toggle door answers the switched slot, on a name
751757
/** `slots`: each holder's slot of `NAME` and its state, in registration order. */
752758
function dispatcherOver(registry: SchemaRegistry, slots: Array<[string, boolean]>) {
753759
const state = new Map(slots);
760+
/** Slots whose definition's `status` keeps them off (`obsolete`), whatever the switch reads. */
761+
const statusOff = new Set<string>();
762+
const enabledOf = (pkg: string) => state.get(pkg) === true && !statusOff.has(pkg);
754763
const keyed = (pkg: string | null) => (pkg !== null && state.has(pkg) ? (state.size > 1 ? `${pkg}/${NAME}` : NAME) : undefined);
755764
const shared = () => Object.assign(new Error(`Flow '${NAME}' is held by several packages`), { code: 'RESOURCE_CONFLICT', status: 409 });
756765
const automation = {
757766
handlerReady: true,
758767
getFlow: vi.fn(async (name: string) => { if (name === NAME) throw shared(); return null; }),
759768
toggleFlow: vi.fn(async (name: string) => { if (name === NAME) throw shared(); }),
760-
getFlowRuntimeStates: vi.fn(() => [...state].map(([, enabled]) => ({ name: NAME, enabled, bound: enabled }))),
769+
getFlowRuntimeStates: vi.fn(() => [...state.keys()].map((pkg) => ({ name: NAME, packageId: pkg, enabled: enabledOf(pkg), bound: enabledOf(pkg) }))),
761770
flowSlotKey: vi.fn((pkg: string | null, name: string) => (name === NAME ? keyed(pkg) : undefined)),
762771
getFlowSlot: vi.fn((pkg: string | null, name: string) => (name === NAME && keyed(pkg) ? { name, label: `${pkg} flow` } : null)),
763772
executeSlot: vi.fn(async () => ({ success: true, output: {} })),
@@ -771,9 +780,33 @@ describe('[ADR-0126 §7.2] the toggle door answers the switched slot, on a name
771780
const answered = await dispatcher.handleAutomation(path, 'POST', { enabled }, { request: {}, executionContext: ADMIN } as any, {});
772781
return { status: answered.response?.status ?? 200, body: answered.response?.body as any };
773782
};
774-
return { toggle, automation, stateOf: (pkg: string) => state.get(pkg) };
783+
return { toggle, automation, stateOf: enabledOf, republishObsolete: (pkg: string) => statusOff.add(pkg) };
775784
}
776785

786+
it('red line: the switched slot republished `obsolete` while the switch awaits its durable write: 200 { enabled: false } (FROM: { enabled: true } over a flow that is off)', async () => {
787+
const { toggle, automation, stateOf, republishObsolete } = dispatcherOver(registryOf([CRM, HR]), [[CRM, true], [HR, false]]);
788+
const flip = automation.toggleFlowSlot.getMockImplementation()!;
789+
let landWrite!: () => void;
790+
const written = new Promise<void>((resolve) => { landWrite = resolve; });
791+
let switching!: () => void;
792+
const awaiting = new Promise<void>((resolve) => { switching = resolve; });
793+
// The engine's order: the durable write is awaited first, the in-process bit moves after it.
794+
automation.toggleFlowSlot.mockImplementation(async (pkg: string, name: string, enabled: boolean) => {
795+
switching();
796+
await written;
797+
await flip(pkg, name, enabled);
798+
});
799+
const pending = toggle(`/hr/${NAME}/toggle`, true);
800+
await awaiting;
801+
// The republish lands while the switch awaits: the slot's status is now `obsolete`.
802+
republishObsolete(HR);
803+
landWrite();
804+
const on = await pending;
805+
expect([on.status, on.body?.data], JSON.stringify(on.body)).toEqual([200, { name: NAME, enabled: false }]);
806+
expect(on.body?.data?.enabled).toBe(stateOf(HR));
807+
expect(stateOf(CRM)).toBe(true);
808+
});
809+
777810
it('switched ON at the second holder\'s address, the first holder off: 200 { enabled: true }, that slot\'s state (FROM: the first holder\'s false)', async () => {
778811
const { toggle, automation, stateOf } = dispatcherOver(registryOf([CRM, HR]), [[CRM, false], [HR, false]]);
779812
const on = await toggle(`/hr/${NAME}/toggle`, true);

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

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3890,10 +3890,16 @@ async function respondToRecordUpdateStarts(
38903890
* disables it → 409 `RESOURCE_CONFLICT` naming the
38913891
* status; nothing changes. 200 answers
38923892
* `{ name, enabled }` with `enabled` read back from
3893-
* `getFlowRuntimeStates` while the name has one
3894-
* row there (echoed by a service that does not
3895-
* implement that read, and for a name two packages
3896-
* hold, which reads one row per holder)
3893+
* the switched flow's `getFlowRuntimeStates` row:
3894+
* where the door serves one package's slot (a
3895+
* name two packages hold, ADR-0150 D4), the row
3896+
* of `(packageId, name)`; elsewhere the name's
3897+
* one row. Echoed only by a service that does not
3898+
* implement that read, or by a reading that holds
3899+
* no row of the switched flow, or (on a door
3900+
* serving no slot) two or more rows of the name,
3901+
* which the composed runtime never reaches: the
3902+
* bare `toggleFlow` refuses a shared name
38973903
* ⚑ authoring write — `manage_metadata` (commit 266436a7f):
38983904
* enablement is environment-wide, so an
38993905
* unentitled toggle reached every organization
@@ -4178,6 +4184,9 @@ export async function handleAutomationRequest(deps: DomainHandlerDeps, path: str
41784184
// is served from that holder's slot, as its address is (seat ruling
41794185
// 6884403301). `item` is the address's item, else the bare door's own.
41804186
let connectorPackage: string | undefined;
4187+
// [ADR-0150 D4] The package whose slot a by-name door serves, when it
4188+
// serves one (`flowSlotView`): the toggle reads back that slot's row.
4189+
let flowSlotPackage: string | undefined;
41814190
{
41824191
const door = bareByNameItem(parts, m);
41834192
const item = address.qualifier ? address.item : door;
@@ -4192,6 +4201,7 @@ export async function handleAutomationRequest(deps: DomainHandlerDeps, path: str
41924201
: undefined;
41934202
if (slotted) {
41944203
automationService = slotted;
4204+
flowSlotPackage = admission.packageId;
41954205
} else if (address.qualifier || door?.type !== 'flow') {
41964206
return { handled: true, response: automationAddressRefusalResponse(deps, { status: 409, refusal: admission.refusal }) };
41974207
}
@@ -4547,22 +4557,31 @@ export async function handleAutomationRequest(deps: DomainHandlerDeps, path: str
45474557
// not move, so "the write landed" and "the flow is on" are two
45484558
// facts. Read through `getFlowRuntimeStates`, the one reading
45494559
// `GET /_status` serves, so the two doors cannot disagree.
4550-
// That reading names the switched flow only while the name
4551-
// has ONE row. A name two packages hold reaches here too: by
4552-
// its address, or bare with one served holder left, through
4553-
// `flowSlotView`, whose `toggleFlow` switches one slot while
4554-
// the engine still reads one row per slot under the bare
4555-
// name ([ADR-0150 D4], `getFlowRuntimeStates`). A row picked
4556-
// by name there may be the other holder's, so two or more
4557-
// rows read back nothing. Then, as for a service that does
4558-
// not implement the read or holds no row of the name, the
4559-
// request is echoed, the legacy answer; for the engine's own
4560-
// service (the only one with slots) that echo is true by
4561-
// construction, since every toggle entry refuses switching
4562-
// on a flow its status keeps off.
4560+
//
4561+
// [ADR-0150 D4] The row read is the SWITCHED flow's. A name
4562+
// two packages hold reaches here too: by its address, or bare
4563+
// with one served holder left, through `flowSlotView`, whose
4564+
// `toggleFlow` switches one slot while the engine reads one
4565+
// row per slot under the bare name. Each row carries its
4566+
// slot's `packageId`, so a door serving a slot reads the row
4567+
// of `(flowSlotPackage, name)`, ⛔ never a row picked by name
4568+
// alone (it may be the other holder's). That is also what
4569+
// keeps the answer true when the slot is republished
4570+
// `obsolete` while the switch awaits its durable write: the
4571+
// row then reads off, and so does the answer. A bare door
4572+
// reads the name's one row.
4573+
//
4574+
// The request is echoed, the legacy answer, only where the
4575+
// reading cannot name the switched flow: a service that does
4576+
// not implement the read, a read that holds no row of it, or,
4577+
// on a door serving no slot, two or more rows of the name. The
4578+
// composed runtime never reaches that last case: the bare
4579+
// `toggleFlow` refuses a name two packages hold, and such a
4580+
// name reaches this door through a slot.
45634581
const svc = automationService as Pick<IAutomationService, 'getFlowRuntimeStates'>;
45644582
const rows = typeof svc.getFlowRuntimeStates === 'function'
4565-
? svc.getFlowRuntimeStates().filter((s) => s.name === name)
4583+
? svc.getFlowRuntimeStates().filter((s) => s.name === name
4584+
&& (flowSlotPackage === undefined || s.packageId === flowSlotPackage))
45664585
: [];
45674586
const state = rows.length === 1 ? rows[0] : undefined;
45684587
return { handled: true, response: deps.success({ name, enabled: state ? state.enabled : enabled }) };

‎packages/services/service-automation/src/engine.ts‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ import {
215215
withdrawFlow,
216216
hydrateFlowActivations,
217217
toggleFlow,
218+
type FlowRuntimeStateRow,
218219
} from './flow-definitions.js';
219220
// [#25222] The subflow guards' bodies: finding and describing disabled or
220221
// packaged subflows and their callers, and refusing what would reach a disabled
@@ -5978,19 +5979,13 @@ export class AutomationEngine implements IAutomationService {
59785979
* is `GET /automation/_status`, which passes these rows through verbatim and
59795980
* has no access to {@link getTriggerBindingAudit}. Same sentence, same
59805981
* eligibility, one computation — see {@link describeUnboundReason}.
5982+
*
5983+
* [ADR-0150 D4] One row per slot, under the flow's own name, carrying the
5984+
* slot's `packageId` (absent for a slot no package holds): a name two
5985+
* packages hold reads as two rows of that name, told apart by it, so the
5986+
* toggle door reads back the slot it switched.
59815987
*/
5982-
getFlowRuntimeStates(): Array<{
5983-
name: string;
5984-
enabled: boolean;
5985-
bound: boolean;
5986-
status?: string;
5987-
triggerType?: string;
5988-
object?: string;
5989-
reason?: string;
5990-
unboundCause?: FlowUnboundCause;
5991-
armedFrom?: FlowContender;
5992-
shadowed?: FlowContender[];
5993-
}> {
5988+
getFlowRuntimeStates(): FlowRuntimeStateRow[] {
59945989
// The body lives in ./flow-definitions.ts (#25222).
59955990
const host: ThisParameterType<typeof getFlowRuntimeStates> = {
59965991
flows: this.flows,
@@ -6000,6 +5995,7 @@ export class AutomationEngine implements IAutomationService {
60005995
isFlowEnabled: (...a) => this.isFlowEnabled(...a),
60015996
boundFlowTriggers: this.boundFlowTriggers,
60025997
flowSlotName: (...a) => this.flowSlotName(...a),
5998+
flowSlotPackage: (...a) => this.flowSlotPackage(...a),
60035999
};
60046000
return getFlowRuntimeStates.call(host);
60056001
}

‎packages/services/service-automation/src/flow-definitions.ts‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
import type { ConnectorProviderFactory } from '@objectstack/spec/integration';
20-
import type { AutomationContext, FlowUnboundCause } from '@objectstack/spec/contracts';
20+
import type { AutomationContext, FlowRuntimeState, FlowUnboundCause } from '@objectstack/spec/contracts';
2121
import type { MetadataActivationWriteOptions } from '@objectstack/core';
2222
import type { ConversionNotice, ConversionTodoNotice } from '@objectstack/spec';
2323
import { applyConversionsToFlow } from '@objectstack/spec';
@@ -92,6 +92,7 @@ export interface FlowDefinitionsHost {
9292
readonly parkedRunsOf: AutomationEngine['parkedRunsOf'];
9393
readonly activateFlowTrigger: AutomationEngine['activateFlowTrigger'];
9494
readonly flowSlotName: AutomationEngine['flowSlotName'];
95+
readonly flowSlotPackage: AutomationEngine['flowSlotPackage'];
9596
readonly flowSlotKeysOf: AutomationEngine['flowSlotKeysOf'];
9697
readonly isSharedFlowKey: AutomationEngine['isSharedFlowKey'];
9798
}
@@ -251,19 +252,21 @@ export function recordFlowRefusal(this: Pick<FlowDefinitionsHost, 'flows' | 'flo
251252
});
252253
}
253254

254-
/** The body of {@link AutomationEngine.getFlowRuntimeStates}, moved unedited; that method's docblock is its contract. */
255-
export function getFlowRuntimeStates(this: Pick<FlowDefinitionsHost, 'flows' | 'resolveTriggerBinding' | 'flowShadowing' | 'describeUnboundReason' | 'isFlowEnabled' | 'boundFlowTriggers' | 'flowSlotName'>): Array<{
256-
name: string;
257-
enabled: boolean;
258-
bound: boolean;
259-
status?: string;
260-
triggerType?: string;
261-
object?: string;
262-
reason?: string;
263-
unboundCause?: FlowUnboundCause;
255+
/**
256+
* One row of {@link AutomationEngine.getFlowRuntimeStates}: the contract's
257+
* `FlowRuntimeState`, plus the shadowing receipt the engine attaches (#11997).
258+
*/
259+
export type FlowRuntimeStateRow = FlowRuntimeState & {
264260
armedFrom?: FlowContender;
265261
shadowed?: FlowContender[];
266-
}> {
262+
};
263+
264+
function packageOf(packageId: string | undefined): { packageId?: string } {
265+
return packageId === undefined ? {} : { packageId };
266+
}
267+
268+
/** The body of {@link AutomationEngine.getFlowRuntimeStates}; that method's docblock is its contract. */
269+
export function getFlowRuntimeStates(this: Pick<FlowDefinitionsHost, 'flows' | 'resolveTriggerBinding' | 'flowShadowing' | 'describeUnboundReason' | 'isFlowEnabled' | 'boundFlowTriggers' | 'flowSlotName' | 'flowSlotPackage'>): FlowRuntimeStateRow[] {
267270
return [...this.flows.keys()].map((name) => {
268271
const resolved = this.resolveTriggerBinding(name);
269272
// [#11997] Attach the shadowing receipt to the row an admin already
@@ -275,6 +278,11 @@ export function getFlowRuntimeStates(this: Pick<FlowDefinitionsHost, 'flows' | '
275278
// [#31696] One row per slot, under the flow's own name: two
276279
// packages' flows of one name are two rows of that name.
277280
name: this.flowSlotName(name),
281+
// [ADR-0150 D4] The slot's package, so a reader that means one
282+
// package's flow of a name two packages hold picks its row by
283+
// `(packageId, name)`. Absent, not `undefined`-valued, on a slot
284+
// no package holds, as `reason` is below.
285+
...packageOf(this.flowSlotPackage(name)),
278286
enabled: this.isFlowEnabled(name),
279287
bound: this.boundFlowTriggers.has(name),
280288
status: (this.flows.get(name) as { status?: string } | undefined)?.status,

0 commit comments

Comments
 (0)