Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .changeset/38876-branch-suspending-subflow-arming.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
'@objectstack/spec': minor
'@objectstack/service-automation': minor
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

fix(automation)!: a triggered flow whose fan-out or earlier branch reaches a subflow or map whose child can suspend is not armed

Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: none — no page under `skills/**` teaches the fan-out or sequential pause shapes or the region decline this sits beside (git grep `suspending_subflow_in_region`, `fans out`: 0 hits); `content/docs/automation/flows.mdx` names the new cause

**BREAKING** for a flow author: FROM a trigger-declaring flow arming when, on its top-level graph or that of any flow its top-level calls reach (at any depth), a `subflow` or `map` node whose child flow can suspend (the child reaches an `approval`, `approval_revise`, `screen` or `wait` from its start, or calls a flow that does) sits beside another pausing branch of one fan-out, or on a conditioned or `isDefault` branch the engine takes before another out-edge of the same node, TO that flow registered and saved but NOT armed: `GET /api/v1/automation/_status` reads `bound: false` with the new `unboundCause` `suspending_subflow_on_branch` and a reason naming the branching node, the call, the child and where it suspends, and the engine logs one `warn`. The one-line fix: chain the call and the other pausing step onto one branch, or make the call's branch the last one its node takes, or republish the child without a node that suspends; the flow arms the moment the shape is gone.

Why. A run parks at one place and resumes from it, never back at the node that branched, so such a run loses a branch. The engine already fails it at run time by name, but only after the child's request opened, which is then left pending. The engine holds the child flow, so the arming gate now asks the flow parse's own fan-out and sequential readings with a call whose child can suspend counted as a pausing node, and declines the flow before any run opens a request. The flow parse is unchanged: it still cannot see a call's child (another record), so the flow still registers.

`@objectstack/spec`: `FLOW_UNBOUND_CAUSES` gains `suspending_subflow_on_branch` (a closed vocabulary: a consumer that switches over it exhaustively gains a case). `concurrentPauseRefusals` and `sequentialPauseRefusals` are now exported from `@objectstack/spec/automation`, and take a list of node types (what the flow parse hands) or a predicate over a node (`FlowPauseReading`); each refusal also carries `shape`, `nodeId`, `branches` and, for the sequential reading, `untaken`. The parse's verdicts and messages do not move.

`@objectstack/service-automation`: the arming gate's new branch half sits after the region half (a call inside a region body keeps `suspending_subflow_in_region`) and is asked again whenever a flow its calls reach is registered, as the other halves are, so an armed flow is un-armed when a child it calls is registered or republished with a step that suspends. For a `decision` that declares conditions but no fallback edge, the reason names the fix that keeps the routing: mark one branch edge `isDefault: true`. The reading goes down the call chain (maintainer ruling 7360068553): a reusable child flow that holds the shape, with no trigger of its own, declines the triggered flow that calls it, and the reason names the child and the calls that lead to it. Measured before: such a parent armed, and a concurrent shape in the child answered `paused` and then failed the parent even with a `fault` edge on its call node. The region half stays one level deep (its failure is synchronous and routable). Met only by the run-time branch refusal: a run started without a trigger (this is the arming gate); the shape held in a flow reached only through calls inside region bodies (the branch reading follows top-level calls, and a region-body call whose child can suspend is itself declined at arming by the region half); and a pausing node type a plugin registers.

`@object-ui/app-shell`, `@object-ui/i18n`: the flow run note has a plain-words line for the new unbound cause `suspending_subflow_on_branch` (English and Chinese): a subflow that calls a flow that can pause sits on a branch beside another pausing step, or before other branches of the same step, so the flow does not start until those steps are chained onto one branch or that branch is taken last.

No conversion rewrites the shape (which rewrite the author meant is not recorded); the ADR-0087 semantic entry `flow-branch-suspending-subflow-not-armed` carries it to the upgrade guide.

<!-- adr-0087: registered flow-branch-suspending-subflow-not-armed -->
22 changes: 22 additions & 0 deletions content/docs/automation/flows.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,28 @@ ones above: chain the steps onto one branch, make the branch that pauses the
last one the node takes, or republish the child flow without a step that
pauses.

**Declined at activation when the child is already registered.** When a
flow's trigger activates it, the engine asks the same two questions with a
`subflow` or `map` whose child flow it holds counted as a step that pauses (a
child reaching an `approval`, `approval_revise`, `screen` or `wait` from its
start, or calling a flow that does), of the flow itself and of every flow its
calls reach, at any depth: a reusable child that holds the shape declines the
triggered flow that calls it, even though the child has no trigger. A flow of either shape still registers and
saves, but its trigger is not armed: `GET /api/v1/automation/_status` reads
`bound: false` with `unboundCause: suspending_subflow_on_branch` and a reason
naming the branching node, the call and where its child pauses (and, when the
shape is in a called flow, that flow and the calls that lead to it), and the engine
logs one `warn`. For a `decision` that declares conditions but no fallback edge,
the reason says so and names the fix that keeps the routing: mark one branch
edge `isDefault: true`. The question is asked again whenever a flow its calls
reach is registered: the flow arms the moment the shape or the child changes,
and an armed flow is un-armed when a child or grandchild it calls is registered,
or republished, with a step that pauses. Only the run-time error above meets a
run started without a trigger. A call inside a region body keeps its own cause,
`suspending_subflow_in_region`, judged one level deep: a region failure is
always immediate and an error-handler edge can route it, while a branch failure
in a child can arrive after the parent has paused, where nothing routes it.

### Batch approval — a `map` node, one item at a time

"Sign off **every** task in the release, in turn" is a **`map` node**: it runs a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1534,4 +1534,68 @@ describe('[#38876] a branch whose subflow child parks, where the run cannot park
expect((await automation.getRun(parentRunId))?.status).toBe('completed');
expect(await ranNodes(automation, parentRunId)).not.toContain('s_sync');
});
/**
* The ARMING door (maintainer ruling 「38876 选 A」, record 7336647907): the
* same shapes, record-triggered, are declined when the trigger activates
* them and the child they call is already registered and can park, so no
* run opens a request the refusal above would strand. The engine asks the
* spec's fan-out / sequential readings (`flow-concurrent-pause.ts`) with a
* call whose child can park counted as a pausing node. Each flow here still
* registers; it is left unarmed with `unboundCause`
* `suspending_subflow_on_branch`. The run-time refusal above stays the door
* for a child that registers, or starts to park, after the caller armed.
*/
describe('[#38876] the arming door: the same shapes are declined at trigger activation when the child in hand parks', () => {
const triggered = <F extends { nodes: Array<Record<string, unknown>> }>(flow: F): F => ({
...flow,
nodes: flow.nodes.map((n) => (n.id === 'start'
? { ...n, config: { objectName: 'crm_contract', triggerType: 'record-after-create' } }
: n)),
});
const arming = (...flows: any[]) => {
const { automation } = bootEngine();
const bound = new Set<string>();
automation.registerTrigger({
type: 'record_change',
start(binding: { flowName: string }) { bound.add(binding.flowName); },
stop(flowName: string) { bound.delete(flowName); },
} as any);
for (const flow of flows) automation.registerFlow(flow.name, flow);
const row = (name: string) => automation.getFlowRuntimeStates().find((s) => s.name === name);
return { bound, row };
};
const SHAPES: Array<[string, () => any]> = [
['CONCURRENT, an approval beside a subflow', () => fanOutToApprovalAndCall('arm_fan_out_subflow')],
['CONCURRENT, an approval beside a map', () => fanOutToApprovalAndCall('arm_fan_out_map', 'map')],
['CONCURRENT, two subflows', () => fanOutToTwoCalls('arm_fan_out_two_calls')],
['SEQUENTIAL, a conditioned edge into the subflow before a conditioned sibling', () => callBeforeConditionedSibling('arm_sequential_conditioned')],
['SEQUENTIAL, an isDefault edge into the subflow beside an unconditional sibling', () => defaultCallBesideUnconditional('arm_sequential_default')],
];

it.each(SHAPES)('%s: registered, not armed, `suspending_subflow_on_branch`', (_shape, make) => {
const flow = triggered(make());
const { bound, row } = arming(PARKING_CHILD, WAITING_CHILD, flow);
expect(bound.has(flow.name)).toBe(false);
expect(row(flow.name)).toMatchObject({ enabled: true, bound: false, unboundCause: 'suspending_subflow_on_branch' });
expect(row(flow.name)?.reason).toContain("calls child flow 'branch_");
});

it.each(SHAPES)('CONTROL, %s, with no child registered: armed (the run-time door stays)', (_shape, make) => {
const flow = triggered(make());
const { bound, row } = arming(flow);
expect(bound.has(flow.name)).toBe(true);
expect(row(flow.name)?.unboundCause).toBeUndefined();
});

it.each(SHAPES)('CONTROL, %s, whose children run straight through: armed', (_shape, make) => {
const flow = triggered(make());
const through = (name: string) => ({
name, label: name, type: 'autolaunched',
nodes: [{ id: 'start', type: 'start', label: 'Start' }, { id: 'ok', type: 'end', label: 'Ok' }],
edges: [{ id: 't1', source: 'start', target: 'ok' }],
});
const { bound } = arming(through(PARKING_CHILD.name), through(WAITING_CHILD.name), flow);
expect(bound.has(flow.name)).toBe(true);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* `isFlowEnabled`, `describeDisabledFlow`, `subflowTargets`,
* `resolvedFlowCallKey`, `declineOntoDisabledSubflows`,
* `declineOntoSuspendingSubflowNotice`, `declineOntoRegionSuspendingCall`,
* `declineOntoBranchSuspendingCall` (#38876, added here),
* `declineOntoSubflowRetriedCallout`, `toggleFlow`, `toggleFlowSlot`,
* `getFlowVersionHistory`, `rollbackFlow`
* moved out of `engine.ts` whole.
Expand Down Expand Up @@ -39,6 +40,7 @@ import { describeDisabledFlow, subflowTargets } from './subflow-guards.js';
import { describeSubflowNoticeTrap, subflowNoticeTrap } from './subflow-notice-guard.js';
import { isSlotKeySpelling, unfiledFlowKey } from './flow-slots.js';
import { describeRegionSuspendingCall, regionSuspendingCall } from './subflow-region-guard.js';
import { branchSuspendingCall, describeBranchSuspendingCall } from './subflow-branch-guard.js';
import { describeSubflowRetriedCallout, subflowRetriedCallout } from './subflow-retry-guard.js';
import type { AutomationEngine } from './engine.js';

Expand All @@ -65,6 +67,7 @@ export interface EnablementHost {
readonly resolveFlowKey: AutomationEngine['resolveFlowKey'];
readonly resolvedFlowCallKey: AutomationEngine['resolvedFlowCallKey'];
readonly servedBareFlowKey: AutomationEngine['servedBareFlowKey'];
readonly subflowBranchDeclinedFlows: AutomationEngine['subflowBranchDeclinedFlows'];
readonly subflowDeclinedFlows: AutomationEngine['subflowDeclinedFlows'];
readonly subflowNoticeDeclinedFlows: AutomationEngine['subflowNoticeDeclinedFlows'];
readonly subflowRegionDeclinedFlows: AutomationEngine['subflowRegionDeclinedFlows'];
Expand Down Expand Up @@ -322,6 +325,48 @@ export class EnablementFacet {
return true;
}

/**
* [#38876] The arming gate's branch half, asked by
* {@link activateFlowTrigger} of an enabled flow it is about to arm: does a
* top-level `subflow` / `map` node whose child flow can suspend sit on a
* branch that loses work when it parks ({@link branchSuspendingCall}: the
* spec's fan-out and sequential pause readings, `flow-concurrent-pause.ts`,
* asked with that call counted as a pausing node)? A run parks at one place
* and resumes from it, so such a run would be failed by the branch refusal
* (`branch-suspension-refusal.ts`) the first time the child suspends, after
* its requests opened. Then it is declined: recorded on
* {@link subflowBranchDeclinedFlows} for `/_status` and the binding audit,
* and said once as a `warn` naming the branching node, the call node and
* where the child suspends.
*
* Any flow, packaged or authored here, as the region half; ⛔ a decline,
* never a refusal, for that half's reasons (the child may register after
* this flow). #4632 verdict: FUNCTIONAL, `warn`. Said once per decline
* reason.
*
* @returns `true` when the flow is declined and must not be armed.
*/
static declineOntoBranchSuspendingCall(this: Pick<EnablementHost, 'flowCallKey' | 'flows' | 'logger' | 'subflowBranchDeclinedFlows'>, flowName: string, triggerType: string): boolean {
const trap = branchSuspendingCall(this.flows, flowName, this.flowCallKey);
if (!trap) {
this.subflowBranchDeclinedFlows.delete(flowName);
return false;
}
const why = describeBranchSuspendingCall(trap);
const reason =
`not armed — ${why}, and it is armed; it is also armed once '${trap.child}' is republished without a ` +
`node that suspends`;
const previous = this.subflowBranchDeclinedFlows.get(flowName);
this.subflowBranchDeclinedFlows.set(flowName, reason);
if (previous === reason) return true;
this.logger.warn(
`Flow '${flowName}' is registered but NOT armed on trigger '${triggerType}' — ${why}. It is armed the ` +
`moment the branches of '${trap.holder}' change, or '${trap.child}' is republished without a node ` +
`that suspends.`,
);
return true;
}

/**
* The arming gate's subflow-retry half, asked by
* {@link activateFlowTrigger} of an enabled flow it is about to arm: does
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface ExtensionsHost {
readonly connectorProviders: AutomationEngine['connectorProviders'];
readonly connectors: AutomationEngine['connectors'];
readonly credentialHandleProviders: AutomationEngine['credentialHandleProviders'];
readonly declineOntoBranchSuspendingCall: AutomationEngine['declineOntoBranchSuspendingCall'];
readonly declineOntoDisabledSubflows: AutomationEngine['declineOntoDisabledSubflows'];
readonly declineOntoRegionSuspendingCall: AutomationEngine['declineOntoRegionSuspendingCall'];
readonly declineOntoSubflowRetriedCallout: AutomationEngine['declineOntoSubflowRetriedCallout'];
Expand Down Expand Up @@ -143,7 +144,7 @@ export class ExtensionsFacet {
* binding, or when no trigger is registered for its type yet —
* {@link registerTrigger} re-attempts activation when one arrives.
*/
static activateFlowTrigger(this: Pick<ExtensionsHost, 'boundFlowTriggers' | 'declineOntoDisabledSubflows' | 'declineOntoRegionSuspendingCall' | 'declineOntoSubflowRetriedCallout' | 'declineOntoSuspendingSubflowNotice' | 'flowRefusals' | 'flowSlotName' | 'isFlowEnabled' | 'logger' | 'loneSharedFlowKey' | 'policyDisabledFlows' | 'readScheduledWorkPolicy' | 'resolveTriggerBinding' | 'sharedSlotTriggerWarned' | 'triggerRun' | 'triggers'>, flowName: string): void {
static activateFlowTrigger(this: Pick<ExtensionsHost, 'boundFlowTriggers' | 'declineOntoBranchSuspendingCall' | 'declineOntoDisabledSubflows' | 'declineOntoRegionSuspendingCall' | 'declineOntoSubflowRetriedCallout' | 'declineOntoSuspendingSubflowNotice' | 'flowRefusals' | 'flowSlotName' | 'isFlowEnabled' | 'logger' | 'loneSharedFlowKey' | 'policyDisabledFlows' | 'readScheduledWorkPolicy' | 'resolveTriggerBinding' | 'sharedSlotTriggerWarned' | 'triggerRun' | 'triggers'>, flowName: string): void {
if (this.boundFlowTriggers.has(flowName)) return;
// [ADR-0126 §7.2] THE enablement gate for arming — here, at the one
// point every arming path crosses, and not in its callers. A flow
Expand Down Expand Up @@ -301,6 +302,14 @@ export class ExtensionsFacet {
// records in the same order, so a record an earlier half's decline
// left unasked is never the one reported.
if (this.declineOntoRegionSuspendingCall(flowName, resolved.triggerType)) return;
// [#38876] The branch half, a decline for the same reasons: a
// top-level `subflow` / `map` whose child suspends, on a fan-out beside
// another pausing branch or on a branch taken before later edges, loses
// work when it parks; the run-time door (`branch-suspension-refusal.ts`)
// fails such a run after its requests opened. The spec's pause readings,
// asked with the child in hand. After the region half, and
// {@link describeUnboundReason} reads its record after the region's.
if (this.declineOntoBranchSuspendingCall(flowName, resolved.triggerType)) return;
// The subflow-retry half, a decline for the same reasons: an
// after-record-change run waits for its `subflow` / `map` children, so
// an inline outbound call a child retries holds the save through the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export interface FlowSlotsHost {
readonly subflowDeclinedFlows: AutomationEngine['subflowDeclinedFlows'];
readonly subflowNoticeDeclinedFlows: AutomationEngine['subflowNoticeDeclinedFlows'];
readonly subflowRegionDeclinedFlows: AutomationEngine['subflowRegionDeclinedFlows'];
readonly subflowBranchDeclinedFlows: AutomationEngine['subflowBranchDeclinedFlows'];
readonly subflowRetryDeclinedFlows: AutomationEngine['subflowRetryDeclinedFlows'];
readonly suspendedRuns: AutomationEngine['suspendedRuns'];
}
Expand Down Expand Up @@ -264,7 +265,7 @@ export class FlowSlotsFacet {
* under the old key first and armed under the new one after, through the
* one arming gate.
*/
static moveFlowRecords(this: Pick<FlowSlotsHost, 'activateFlowTrigger' | 'deactivateFlowTrigger' | 'executionLogs' | 'flowShadowing' | 'flowStatusDisabled' | 'flowVersionHistory' | 'flows' | 'movedFlowKeys' | 'policyDisabledFlows' | 'sharedSlotTriggerWarned' | 'subflowDeclinedFlows' | 'subflowNoticeDeclinedFlows' | 'subflowRegionDeclinedFlows' | 'subflowRetryDeclinedFlows' | 'suspendedRuns'>, moved: readonly FlowKeyMove[]): void {
static moveFlowRecords(this: Pick<FlowSlotsHost, 'activateFlowTrigger' | 'deactivateFlowTrigger' | 'executionLogs' | 'flowShadowing' | 'flowStatusDisabled' | 'flowVersionHistory' | 'flows' | 'movedFlowKeys' | 'policyDisabledFlows' | 'sharedSlotTriggerWarned' | 'subflowDeclinedFlows' | 'subflowNoticeDeclinedFlows' | 'subflowRegionDeclinedFlows' | 'subflowBranchDeclinedFlows' | 'subflowRetryDeclinedFlows' | 'suspendedRuns'>, moved: readonly FlowKeyMove[]): void {
if (moved.length === 0) return;
for (const { from } of moved) {
this.deactivateFlowTrigger(from);
Expand All @@ -281,6 +282,7 @@ export class FlowSlotsFacet {
this.subflowDeclinedFlows,
this.subflowNoticeDeclinedFlows,
this.subflowRegionDeclinedFlows,
this.subflowBranchDeclinedFlows,
this.subflowRetryDeclinedFlows,
];
for (const { from, to } of moved) {
Expand Down
Loading
Loading