Skip to content

Commit 17561e0

Browse files
committed
fix(verify): a caught outbound stop does not hide a later failure; a child flow's stop is named
Claude-Session: https://claude.ai/code/session_01JQwxbYRqkDAGuse5Wqbohi Co-authored-by: Claude <noreply@anthropic.com>
1 parent f1b5662 commit 17561e0

2 files changed

Lines changed: 207 additions & 23 deletions

File tree

‎packages/verify/src/flow-run.test.ts‎

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
* datasource's driver is called: the recording driver below sees no write;
1818
* - an outbound node is not executed: the run stops there with the node
1919
* named, and the local server below receives no request;
20+
* - a stop the run goes on past (a try region's catch, a parallel branch)
21+
* does not hide a later real failure: that node is the first failure;
22+
* - a stop inside a child flow is named at the child's node, not reported
23+
* as the calling `subflow` node's failure;
2024
* - a schedule the deployment's scheduled-work switch keeps unarmed is not a
2125
* defect: it is reported as not armed and still run with no caller;
2226
* - an API-triggered flow gets its body as `record` as well as `params`, and
@@ -252,6 +256,97 @@ const outbound: Flow = {
252256
],
253257
} as Flow;
254258

259+
/** A Ledger write with no name: the required field refuses it at run time. */
260+
const failingWrite = (id: string) => ({ id, type: 'create_record', label: id, config: { objectName: LEDGER, fields: {} } });
261+
const httpCall = (id: string) => ({ id, type: 'http', label: id, config: { url: OUTBOUND_URL, method: 'GET' } });
262+
263+
/** start → a try region around an `http` call, caught → a write that really fails → end. */
264+
const CAUGHT = 'fr_caught';
265+
const caught: Flow = {
266+
name: CAUGHT,
267+
label: CAUGHT,
268+
type: 'autolaunched',
269+
status: 'active',
270+
runAs: 'system',
271+
nodes: [
272+
{ id: 'start', type: 'start', label: 'Start' },
273+
{
274+
id: 'guard',
275+
type: 'try_catch',
276+
label: 'Guard',
277+
config: {
278+
try: { nodes: [httpCall('caught_call')] },
279+
catch: { nodes: [{ id: 'call_failed', type: 'assignment', label: 'Call failed' }] },
280+
},
281+
},
282+
failingWrite('boom'),
283+
{ id: 'end', type: 'end', label: 'End' },
284+
],
285+
edges: [
286+
{ id: 'e1', source: 'start', target: 'guard' },
287+
{ id: 'e2', source: 'guard', target: 'boom' },
288+
{ id: 'e3', source: 'boom', target: 'end' },
289+
],
290+
} as Flow;
291+
292+
/** start → one branch calls out, the other branch's write really fails → end. */
293+
const FORKED = 'fr_forked';
294+
const forked: Flow = {
295+
name: FORKED,
296+
label: FORKED,
297+
type: 'autolaunched',
298+
status: 'active',
299+
runAs: 'system',
300+
nodes: [
301+
{ id: 'start', type: 'start', label: 'Start' },
302+
{
303+
id: 'fan',
304+
type: 'parallel',
305+
label: 'Fan out',
306+
config: { branches: [{ name: 'call', nodes: [httpCall('fork_call')] }, { name: 'write', nodes: [failingWrite('fork_boom')] }] },
307+
},
308+
{ id: 'end', type: 'end', label: 'End' },
309+
],
310+
edges: [
311+
{ id: 'e1', source: 'start', target: 'fan' },
312+
{ id: 'e2', source: 'fan', target: 'end' },
313+
],
314+
} as Flow;
315+
316+
/** A child flow that calls out, and a parent that calls it and then writes. */
317+
const CHILD = 'fr_child';
318+
const child: Flow = {
319+
name: CHILD,
320+
label: CHILD,
321+
type: 'autolaunched',
322+
status: 'active',
323+
runAs: 'system',
324+
nodes: [{ id: 'start', type: 'start', label: 'Start' }, httpCall('child_call'), { id: 'end', type: 'end', label: 'End' }],
325+
edges: [
326+
{ id: 'e1', source: 'start', target: 'child_call' },
327+
{ id: 'e2', source: 'child_call', target: 'end' },
328+
],
329+
} as Flow;
330+
const PARENT = 'fr_parent';
331+
const parent: Flow = {
332+
name: PARENT,
333+
label: PARENT,
334+
type: 'autolaunched',
335+
status: 'active',
336+
runAs: 'system',
337+
nodes: [
338+
{ id: 'start', type: 'start', label: 'Start' },
339+
{ id: 'call_child', type: 'subflow', label: 'Call child', config: { flowName: CHILD } },
340+
ledgerNode('after_child', "'after the child'"),
341+
{ id: 'end', type: 'end', label: 'End' },
342+
],
343+
edges: [
344+
{ id: 'e1', source: 'start', target: 'call_child' },
345+
{ id: 'e2', source: 'call_child', target: 'after_child' },
346+
{ id: 'e3', source: 'after_child', target: 'end' },
347+
],
348+
} as Flow;
349+
255350
/** A nightly schedule that writes one Ledger row. */
256351
const NIGHTLY = 'fr_nightly';
257352
const nightly: Flow = {
@@ -370,6 +465,10 @@ const fixtureStack = defineStack({
370465
noExecutor,
371466
confined,
372467
outbound,
468+
caught,
469+
forked,
470+
child,
471+
parent,
373472
nightly,
374473
hook,
375474
renewal,
@@ -464,6 +563,7 @@ describe('runFlowProof — the local flow run', () => {
464563
expect(report.confinement.outbound).toContain('http');
465564
expect(report.verdict, formatFlowRunReport(report)).toBe('stopped');
466565
expect(report.firstFailure).toMatchObject({ kind: 'outbound_not_run', nodeId: 'call', nodeType: 'http' });
566+
expect(report.outboundStops).toEqual([{ nodeId: 'call', nodeType: 'http' }]);
467567
// The run log is the engine's own: the start ran, the call is the failing step, nothing after it ran.
468568
expect(report.steps.map((s) => [s.nodeId, s.status])).toEqual([
469569
['start', 'success'],
@@ -474,6 +574,39 @@ describe('runFlowProof — the local flow run', () => {
474574
expect(report.summary.hardFailures).toBe(0);
475575
});
476576

577+
it('a stop a try region catches does not hide the later node that really fails', async () => {
578+
const mark = outboundHits.length;
579+
const report = await runFlowProof(stack, fixtureStack, { flow: CAUGHT });
580+
expect(outboundHits.slice(mark)).toEqual([]);
581+
expect(report.verdict, formatFlowRunReport(report)).toBe('failed');
582+
expect(report.firstFailure).toMatchObject({ kind: 'node_failed', nodeId: 'boom', nodeType: 'create_record' });
583+
expect(report.outboundStops).toEqual([{ nodeId: 'caught_call', nodeType: 'http' }]);
584+
expect(report.notes.some((n) => n.includes("'caught_call' (http)") && n.includes('went on past'))).toBe(true);
585+
expect(report.summary.hardFailures).toBe(1);
586+
});
587+
588+
it('a stopped parallel branch does not hide the other branch that really fails', async () => {
589+
const mark = outboundHits.length;
590+
const report = await runFlowProof(stack, fixtureStack, { flow: FORKED });
591+
expect(outboundHits.slice(mark)).toEqual([]);
592+
expect(report.verdict, formatFlowRunReport(report)).toBe('failed');
593+
expect(report.firstFailure).toMatchObject({ kind: 'node_failed', nodeId: 'fork_boom' });
594+
expect(report.outboundStops).toEqual([{ nodeId: 'fork_call', nodeType: 'http' }]);
595+
expect(report.summary.hardFailures).toBe(1);
596+
});
597+
598+
it("a stop inside a child flow is named at the child's node, not as the subflow node's failure", async () => {
599+
const mark = outboundHits.length;
600+
const report = await runFlowProof(stack, fixtureStack, { flow: PARENT });
601+
expect(outboundHits.slice(mark)).toEqual([]);
602+
expect(report.verdict, formatFlowRunReport(report)).toBe('stopped');
603+
expect(report.firstFailure).toMatchObject({ kind: 'outbound_not_run', nodeId: 'child_call', nodeType: 'http' });
604+
expect(report.steps.find((s) => s.nodeId === 'call_child')?.status).toBe('failure');
605+
expect(report.outboundStops).toEqual([{ nodeId: 'child_call', nodeType: 'http' }]);
606+
expect(await stack.rows(LEDGER, { name: 'after the child' })).toEqual([]);
607+
expect(report.summary.hardFailures).toBe(0);
608+
});
609+
477610
it('a schedule the scheduled-work switch keeps unarmed is reported as not armed, and still run with no caller', async () => {
478611
const report = await runFlowProof(stack, fixtureStack, { flow: NIGHTLY });
479612
expect(report.trigger).toMatchObject({ type: 'schedule', bound: false, cause: 'deployment_policy' });

‎packages/verify/src/flow-run.ts‎

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,31 @@
6767
//
6868
// ## Outbound nodes are not executed
6969
//
70-
// A node that calls out of the process (`http`, `connector_action`,
71-
// `notify`, `script`) would reach real systems with the project's own
72-
// credentials. Before the run starts, this family replaces each of those
73-
// executors the boot registered, on this stack's engine only, with a
74-
// stand-in that executes nothing and fails the node with a guard-class
75-
// result: the run stops at the first one (a guard result never follows a
76-
// `fault` edge), and the report names it with kind `outbound_not_run`. The
77-
// run log stays the engine's own: every node before it ran for real. A
78-
// `try_catch` region catches a guard result like any other failure, so an
79-
// outbound node inside one hands the run to the catch region, and the report
80-
// says so. Running outbound nodes locally is not offered.
70+
// Four node types call out of the process: `http`, `connector_action` (and
71+
// every connector a plugin contributes, which runs behind it), `notify` and
72+
// `script`. Run for real they would reach real systems with the project's own
73+
// credentials. Before the run starts, this family replaces each of those four
74+
// executors the boot registered, on this stack's engine only, with a stand-in
75+
// that executes nothing and fails the node with a guard-class result: a guard
76+
// result never follows a `fault` edge. A plugin's own node type that calls out
77+
// under another name is not stood in, and runs for real.
78+
//
79+
// How a stop is reported:
80+
// - Each step is classified. A stop is the stopped node's own step, or a
81+
// step whose failure carries the stand-in's sentence: a container around
82+
// it, or a `subflow` / `map` node whose child run was stopped (the child's
83+
// error text reaches the parent's step, but not its guard class, so a
84+
// `fault` edge on the calling node is still followed).
85+
// - The first failure is the first failing step that is not a stop. Only
86+
// when no other step failed and the run failed is the stop why it ended:
87+
// then the verdict is `stopped` and the first failure is `outbound_not_run`
88+
// naming the outbound node (the child's node, for a child flow).
89+
// - A stop the run went on past (a `try_catch` region's catch, or a fault
90+
// edge on a calling node) is a note: what came after reads a call that
91+
// never happened.
92+
// - Every stood-in node the run reached is listed in `outboundStops`.
93+
// The run log stays the engine's own. Running outbound nodes locally is not
94+
// offered.
8195

8296
import { isServiceNotRegisteredError } from '@objectstack/core';
8397
import { collectFlowGraphs } from '@objectstack/spec/automation';
@@ -195,6 +209,8 @@ export interface FlowRunReport {
195209
steps: FlowRunStep[];
196210
/** Every node whose type no executor runs, reached or not. */
197211
missingExecutors: Array<{ nodeId: string; nodeType: string; region?: string }>;
212+
/** Every outbound node the run reached and did not execute, in a child flow too, in the order reached. */
213+
outboundStops: Array<{ nodeId: string; nodeType: string }>;
198214
firstFailure?: FlowRunFailure;
199215
/** What the run wrote: every write the engine received while it was open, the triggering write excluded. */
200216
writes: FlowRunWrite[];
@@ -254,6 +270,13 @@ interface ConfinedRefusal {
254270
operation: ObservedWrite['operation'];
255271
}
256272

273+
/**
274+
* How a failing step's message is recognised as the outbound stand-in's stop:
275+
* the node's own step, a container's, or a `subflow` / `map` node's, whose
276+
* error text carries the child's. Captures the stopped node's id and type.
277+
*/
278+
const OUTBOUND_SENTENCE = /verify --flow does not execute outbound nodes: '([^']+)' \(([^)]+)\)/;
279+
257280
/** How a failing step's message is recognised as the confinement's refusal (the engine wraps the node's code). */
258281
const CONFINEMENT_SENTENCE = /a flow run writes to the ephemeral stack only/;
259282

@@ -450,6 +473,7 @@ export async function runFlowProof(stack: VerifyStack, config: any, request: Flo
450473
start: 'none',
451474
steps: [],
452475
missingExecutors: [],
476+
outboundStops: [],
453477
writes: [],
454478
confinement: { datasource: '', refused: 0, outbound: [] },
455479
notes: [],
@@ -691,34 +715,61 @@ export async function runFlowProof(stack: VerifyStack, config: any, request: Flo
691715
];
692716
report.confinement.refused = refused.length;
693717

718+
report.outboundStops = stopped.map((o) => ({ ...o }));
719+
694720
if (run) {
695721
report.runId = run.id;
696722
report.steps = (run.steps ?? []).map(stepOf);
697723
report.verdict = VERDICT_OF_STATUS[run.status] ?? 'failed';
698-
const failing = report.steps.find((s) => s.status === 'failure');
724+
// A stand-in stop is classified per step: the stopped node's own step, or a
725+
// step whose failure carries the stand-in's sentence (a container, or a
726+
// `subflow` / `map` node whose child run was stopped). The first failure is
727+
// the first failing step that is NOT a stop; a stop is why the run ended
728+
// only when no other step failed.
729+
const isStop = (step: FlowRunStep): boolean =>
730+
stopped.some((o) => o.nodeId === step.nodeId && o.nodeType === step.nodeType) ||
731+
OUTBOUND_SENTENCE.test(step.error?.message ?? '');
732+
const failingSteps = report.steps.filter((s) => s.status === 'failure');
733+
const failing = failingSteps.find((s) => !isStop(s));
734+
const stopStep = failingSteps.find(isStop);
699735
if (failing) {
700736
const confinedWrite = refused.length > 0 && CONFINEMENT_SENTENCE.test(failing.error?.message ?? '');
701737
const missing = report.missingExecutors.some((m) => m.nodeId === failing.nodeId);
702-
const outbound = stopped.some((o) => o.nodeId === failing.nodeId && o.nodeType === failing.nodeType);
703-
if (outbound) {
704-
if (report.verdict === 'failed') report.verdict = 'stopped';
705-
report.notes.push(
706-
`the run reached outbound node '${failing.nodeId}' (${failing.nodeType}), which verify --flow does not execute` +
707-
(report.verdict === 'stopped'
708-
? ': it stopped there, and no node after it is proven'
709-
: `; a try region caught the stop, so the run went on as it would after a failed call`),
710-
);
711-
}
712738
report.firstFailure = {
713-
kind: outbound ? 'outbound_not_run' : confinedWrite ? 'confined_write' : missing ? 'no_executor' : 'node_failed',
739+
kind: confinedWrite ? 'confined_write' : missing ? 'no_executor' : 'node_failed',
714740
nodeId: failing.nodeId,
715741
nodeType: failing.nodeType,
716742
...(failing.error?.code ? { code: failing.error.code } : {}),
717743
message: failing.error?.message ?? `node '${failing.nodeId}' failed`,
718744
};
745+
} else if (stopStep && report.verdict === 'failed') {
746+
// The stop itself ended the run: name the outbound node, which for a
747+
// child flow's node is the one its sentence names, not the calling node.
748+
const named = OUTBOUND_SENTENCE.exec(stopStep.error?.message ?? '');
749+
const nodeId = named?.[1] ?? stopStep.nodeId;
750+
const nodeType = named?.[2] ?? stopStep.nodeType;
751+
report.verdict = 'stopped';
752+
report.firstFailure = {
753+
kind: 'outbound_not_run',
754+
nodeId,
755+
nodeType,
756+
...(stopStep.error?.code ? { code: stopStep.error.code } : {}),
757+
message: stopStep.error?.message ?? `outbound node '${nodeId}' was not executed`,
758+
};
759+
report.notes.push(
760+
`the run ended at outbound node '${nodeId}' (${nodeType}), which verify --flow does not execute` +
761+
(nodeId !== stopStep.nodeId ? `, reached through '${stopStep.nodeId}' (${stopStep.nodeType})` : '') +
762+
': no node after it is proven',
763+
);
719764
} else if (report.verdict === 'failed') {
720765
report.firstFailure = { kind: 'run_failed', message: run.error ?? `run ${run.id} failed with no failing step in its log` };
721766
}
767+
if (report.outboundStops.length > 0 && report.verdict !== 'stopped') {
768+
const names = report.outboundStops.map((o) => `'${o.nodeId}' (${o.nodeType})`).join(', ');
769+
report.notes.push(
770+
`outbound node(s) ${names} were not executed; the run went on past the stop (a try region's catch, or a fault edge on a calling subflow or map node, handled it as a failed call), so what came after reads a call that never happened`,
771+
);
772+
}
722773
if (report.verdict === 'paused') {
723774
const last = report.steps[report.steps.length - 1];
724775
report.notes.push(`the run paused${last ? ` after node '${last.nodeId}' (${last.nodeType})` : ''}; that is normal for a screen, wait or approval`);

0 commit comments

Comments
 (0)