Skip to content

Commit 1f28031

Browse files
committed
fix(lint)!: refuse a flow node no edge path from the start node reaches
A run starts at the start node and follows edges, so a top-level node no edge path reaches never executes, while the flow parses, registers and reports itself as configured. lintFlowPatterns now reports it as `flow-node-unreachable` (severity error), which gates os validate/build/lint and the flow publish doors; a draft save still stores, with the finding in its diagnostics. Every edge type counts as a path. boundary_event nodes and the nodes only they lead to are exempt (reached by attachment), and region bodies are not judged (single-entry DAGs). A flow with no start node or a dangling edge is left to the flow parse. It is lint rather than a FlowSchema rule because the save door parses every save, drafts included, and the Studio designer's node delete can leave a successor unwired. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5oEQNYg7j3ueo5t6pV
1 parent 12d73bf commit 1f28031

6 files changed

Lines changed: 290 additions & 6 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'@objectstack/lint': minor
3+
---
4+
5+
fix(lint)!: a flow node no edge path from the start node reaches is refused at build and publish (`flow-node-unreachable`), because a run never executes it
6+
7+
Clause-②: yes (narrowing) — `os validate`, `os build`, `os lint` and the flow save and publish doors refuse a flow they accepted before; `@objectstack/lint` also exports the rule id `FLOW_NODE_UNREACHABLE`, and `RULE_EXPLANATIONS` gains its entry.
8+
Metadata-protocol: narrowed
9+
Skills-docs: none — `skills/**` and `content/docs/**` teach only wired top-level flows; the edgeless examples in `content/docs/automation/flows.mdx` are region bodies, which this rule does not judge. The reasoning ships as the `os explain flow-node-unreachable` entry.
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed or renamed: FlowSchema keeps its shape and meaning, and lint now refuses a graph whose node no edge from the start node reaches. Such a node never ran (a run starts at the start node and follows edges), so there is no rewrite that keeps what the author meant: the author wires the node in or deletes it, and the finding says which node. -->
12+
13+
**BREAKING** accept-set narrowing in `os validate` / `os build` / `os lint` and at the flow publish doors (`PUT /api/v1/meta/flow/NAME` live save, the per-item and package publish; Studio, REST and MCP authors), through the gating `lintFlowPatterns` rule.
14+
15+
- **Before.** A flow whose top-level node had no edge path from the start node (`nodes: [start, stamp, end]`, `edges: [start → end]`) parsed, built, saved, published and registered, and reported itself as configured. The engine starts a run at the start node and follows edges, so `stamp` never ran, and nothing said so.
16+
- **Now.** `flow-node-unreachable` (severity `error`) names each such node: `flow 'NAME' · node 'ID' (TYPE)`, why it never runs, and the fix. A draft save still stores, with the finding in its `_diagnostics`, so a designer that deletes a node and leaves its successor unwired can keep saving; the publish refuses it.
17+
- **What counts as reaching a node.** Every edge type: default, conditional, fault and back. A `boundary_event` node, and the nodes only it leads to, are not judged (they are reached by attachment, not by an edge).
18+
- **Not judged.** Nodes inside a region body (a region is a single-entry acyclic graph that the region validator already holds, so all of it is reached); a flow with no start node; a flow with an edge whose endpoint names no node (the flow parse refuses that first).
19+
- **Why lint and not the flow parse.** The metadata save door parses `FlowSchema` on every save, drafts included, and the Studio designer's node delete can leave a successor unwired. A parse rule would refuse that draft save outright.
20+
21+
**What an author does.** Nothing for a flow whose nodes are all wired from the start node. For a refused node: add an edge into it from a node that runs, or delete the node. A refused node never ran, so neither choice changes what the flow did.

‎packages/lint/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,7 @@ export {
10421042
FLOW_DEFAULT_EDGE_WITH_CONDITION,
10431043
FLOW_MULTIPLE_DEFAULT_EDGES,
10441044
FLOW_INERT_NODE_CONDITION,
1045+
FLOW_NODE_UNREACHABLE,
10451046
FLOW_MULTI_WRITE_UNFILTERED,
10461047
FLOW_LOOP_BODY_UNCONTAINED,
10471048
FLOW_TRY_CATCH_WITHOUT_CATCH,

‎packages/lint/src/lint-flow-patterns.test.ts‎

Lines changed: 139 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
FLOW_DEFAULT_EDGE_WITH_CONDITION,
3434
FLOW_MULTIPLE_DEFAULT_EDGES,
3535
FLOW_INERT_NODE_CONDITION,
36+
FLOW_NODE_UNREACHABLE,
3637
FLOW_MULTI_WRITE_UNFILTERED,
3738
FLOW_LOOP_BODY_UNCONTAINED,
3839
FLOW_TRY_CATCH_WITHOUT_CATCH,
@@ -91,7 +92,7 @@ const filterFlow = (filter: unknown) => ({
9192
{ id: 'start', type: 'start', config: { triggerType: 'schedule', schedule: 'cron:0 9 * * *' } },
9293
{ id: 'query', type: 'get_record', config: { objectName: 'contract', filter } },
9394
],
94-
edges: [],
95+
edges: [{ id: 'e1', source: 'start', target: 'query' }],
9596
}],
9697
});
9798

@@ -220,7 +221,7 @@ describe('lintFlowPatterns — phantom aggregation capability (#1870)', () => {
220221
{ id: 'start', type: 'start', config: {} },
221222
{ id: 'sum', type: 'script', config },
222223
],
223-
edges: [],
224+
edges: [{ id: 'e1', source: 'start', target: 'sum' }],
224225
}],
225226
});
226227

@@ -250,7 +251,7 @@ const nodeFlow = (config: Record<string, unknown>) => ({
250251
{ id: 'start', type: 'start', config: {} },
251252
{ id: 'create', type: 'create_record', config },
252253
],
253-
edges: [],
254+
edges: [{ id: 'e1', source: 'start', target: 'create' }],
254255
}],
255256
});
256257
const rules = (s: any) => lintFlowPatterns(s).map((f) => f.rule);
@@ -351,6 +352,7 @@ describe('lintFlowPatterns — approval revise loop (ADR-0044)', () => {
351352
const edges = [
352353
{ source: 'start', target: 'mgr' },
353354
{ source: 'mgr', target: 'ok', label: 'approve' },
355+
{ source: 'mgr', target: 'no', label: 'reject' },
354356
{ source: 'mgr', target: 'wait', label: 'revise' },
355357
];
356358
const fnds = lintFlowPatterns(approvalFlow(edges));
@@ -370,7 +372,11 @@ describe('lintFlowPatterns — approval revise loop (ADR-0044)', () => {
370372
{ source: 'mgr', target: 'ok', label: 'approve' },
371373
{ source: 'mgr', target: 'no', label: 'reject' },
372374
];
373-
expect(lintFlowPatterns(approvalFlow(edges))).toEqual([]);
375+
// No revise edge, so no revise node either: one left in place with no edge
376+
// into it would draw `flow-node-unreachable` (it could never run).
377+
const stack = approvalFlow(edges) as any;
378+
stack.flows[0].nodes = stack.flows[0].nodes.filter((n: any) => n.id !== 'wait');
379+
expect(lintFlowPatterns(stack)).toEqual([]);
374380
});
375381

376382
// #3823 — the shape ADR-0044 D3 prescribed until its 2026-07-28 amendment.
@@ -416,7 +422,7 @@ describe('lintFlowPatterns — user-less runAs unscoped (#1888 / ADR-0049 / ADR-
416422
{ id: 'start', type: 'start', config: opts.startConfig ?? { triggerType: 'schedule', cron: '0 8 * * *' } },
417423
{ id: 'op', type: opts.nodeType ?? 'create_record', config: { objectName: 'thing', fields: { a: 1 } } },
418424
],
419-
edges: [],
425+
edges: [{ id: 'e1', source: 'start', target: 'op' }],
420426
}],
421427
});
422428

@@ -528,7 +534,7 @@ describe('lintFlowPatterns — user-less runAs unscoped (#1888 / ADR-0049 / ADR-
528534
{ id: 'start', type: 'start', config: { schedule: { type: 'interval', intervalMs: 60000 } } },
529535
{ id: 'notify', type: 'notify', config: { topic: 'x' } },
530536
],
531-
edges: [],
537+
edges: [{ id: 'e1', source: 'start', target: 'notify' }],
532538
}],
533539
})).toHaveLength(0);
534540
});
@@ -3710,3 +3716,130 @@ describe('[#22161] one-line fix — the twelve flow anti-pattern ids', () => {
37103716
}
37113717
});
37123718
});
3719+
3720+
describe('lintFlowPatterns — a node no edge path from start reaches (flow-node-unreachable)', () => {
3721+
type Edge = { id: string; source: string; target: string; type?: string; condition?: string };
3722+
const reachFlow = (nodes: Array<Record<string, unknown>>, edges: Edge[]) => ({
3723+
flows: [{ name: 'orphan', type: 'autolaunched', nodes, edges }],
3724+
});
3725+
const START = { id: 'start', type: 'start', label: 'Start' };
3726+
const END = { id: 'end', type: 'end', label: 'End' };
3727+
const unreachable = (stack: unknown) =>
3728+
lintFlowPatterns(stack as never).filter((f) => f.rule === FLOW_NODE_UNREACHABLE);
3729+
3730+
it('refuses an action node no edge reaches, as an error that names it, why it never runs and the fix', () => {
3731+
const found = unreachable(reachFlow(
3732+
[START, { id: 'stamp', type: 'assignment', label: 'Stamp' }, END],
3733+
[{ id: 'e1', source: 'start', target: 'end' }],
3734+
));
3735+
expect(found).toHaveLength(1);
3736+
expect(found[0]).toMatchObject({ rule: FLOW_NODE_UNREACHABLE, severity: 'error' });
3737+
expect(found[0].where).toBe("flow 'orphan' · node 'stamp' (assignment)");
3738+
expect(found[0].message).toMatch(/no edge path leads to this node from the start node 'start', so it never runs/);
3739+
expect(found[0].hint).toMatch(/Add an edge into it from a node that runs, or delete the node/);
3740+
});
3741+
3742+
it('refuses a node whose only in-edge comes from another unreached node (one finding each)', () => {
3743+
const found = unreachable(reachFlow(
3744+
[START, { id: 'a', type: 'assignment' }, { id: 'b', type: 'assignment' }, END],
3745+
[{ id: 'e1', source: 'start', target: 'end' }, { id: 'e2', source: 'a', target: 'b' }],
3746+
));
3747+
expect(found.map((f) => f.where)).toEqual([
3748+
"flow 'orphan' · node 'a' (assignment)",
3749+
"flow 'orphan' · node 'b' (assignment)",
3750+
]);
3751+
});
3752+
3753+
it('refuses a cycle cut off from start', () => {
3754+
const found = unreachable(reachFlow(
3755+
[START, { id: 'a', type: 'assignment' }, { id: 'b', type: 'assignment' }, END],
3756+
[
3757+
{ id: 'e1', source: 'start', target: 'end' },
3758+
{ id: 'e2', source: 'a', target: 'b' },
3759+
{ id: 'e3', source: 'b', target: 'a', type: 'back' },
3760+
],
3761+
));
3762+
expect(found).toHaveLength(2);
3763+
});
3764+
3765+
describe('does NOT flag (controls)', () => {
3766+
it('a node reached over a conditional, fault or back edge (every edge type counts)', () => {
3767+
expect(unreachable(reachFlow(
3768+
[
3769+
START,
3770+
{ id: 'call', type: 'http', config: { url: 'https://example.test' } },
3771+
{ id: 'big', type: 'assignment' },
3772+
{ id: 'recover', type: 'assignment' },
3773+
END,
3774+
],
3775+
[
3776+
{ id: 'e1', source: 'start', target: 'call' },
3777+
{ id: 'e2', source: 'call', target: 'big', type: 'conditional', condition: 'true' },
3778+
{ id: 'e3', source: 'call', target: 'recover', type: 'fault' },
3779+
{ id: 'e4', source: 'big', target: 'end' },
3780+
{ id: 'e5', source: 'recover', target: 'end' },
3781+
],
3782+
))).toEqual([]);
3783+
});
3784+
3785+
it('a boundary_event node and the nodes only it leads to (reached by attachment, not by an edge)', () => {
3786+
expect(unreachable(reachFlow(
3787+
[
3788+
START,
3789+
{ id: 'task', type: 'wait', waitEventConfig: { eventType: 'timer', timerDuration: 'PT1H' } },
3790+
{ id: 'timeout', type: 'boundary_event', config: { attachedToNodeId: 'task' } },
3791+
{ id: 'escalate', type: 'assignment' },
3792+
END,
3793+
],
3794+
[
3795+
{ id: 'e1', source: 'start', target: 'task' },
3796+
{ id: 'e2', source: 'task', target: 'end' },
3797+
{ id: 'e3', source: 'timeout', target: 'escalate' },
3798+
],
3799+
))).toEqual([]);
3800+
});
3801+
3802+
it('a flow with no start node (a different defect, judged elsewhere)', () => {
3803+
expect(unreachable(reachFlow(
3804+
[{ id: 'a', type: 'assignment' }, END],
3805+
[],
3806+
))).toEqual([]);
3807+
});
3808+
3809+
it('a flow with a dangling edge (the flow parse refuses that first; reachability is not guessed)', () => {
3810+
expect(unreachable(reachFlow(
3811+
[START, { id: 'a', type: 'assignment' }, END],
3812+
[{ id: 'e1', source: 'start', target: 'end' }, { id: 'e2', source: 'ghost', target: 'a' }],
3813+
))).toEqual([]);
3814+
});
3815+
3816+
it('nodes inside a region body (a region is a single-entry DAG, so every node in it is reached)', () => {
3817+
expect(unreachable(reachFlow(
3818+
[
3819+
START,
3820+
{
3821+
id: 'each', type: 'loop',
3822+
config: {
3823+
collection: '{records}', iteratorVariable: 'r',
3824+
body: {
3825+
nodes: [{ id: 'x', type: 'assignment' }, { id: 'y', type: 'assignment' }],
3826+
edges: [{ id: 'b1', source: 'x', target: 'y' }],
3827+
},
3828+
},
3829+
},
3830+
END,
3831+
],
3832+
[{ id: 'e1', source: 'start', target: 'each' }, { id: 'e2', source: 'each', target: 'end' }],
3833+
))).toEqual([]);
3834+
});
3835+
});
3836+
3837+
it('is in the gating flow rule, so its error reaches os lint/build and the save and publish doors', () => {
3838+
const rule = AUTHORING_RULES.find((r) => r.name === 'lintFlowPatterns');
3839+
expect(rule, 'the authoring rule that runs lintFlowPatterns').toBeDefined();
3840+
expect(rule!.tier).toBe('gating');
3841+
expect(rule!.runtimeTypes).toContain('flow');
3842+
const served = rule!.run(reachFlow([START, { id: 'stamp', type: 'assignment' }, END], [{ id: 'e1', source: 'start', target: 'end' }]) as never);
3843+
expect(served).toContainEqual(expect.objectContaining({ rule: FLOW_NODE_UNREACHABLE, severity: 'error' }));
3844+
});
3845+
});

‎packages/lint/src/lint-flow-patterns.ts‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ export const FLOW_DEFAULT_EDGE_WITH_CONDITION = 'flow-default-edge-with-conditio
238238
export const FLOW_MULTIPLE_DEFAULT_EDGES = 'flow-multiple-default-edges';
239239
/** #4414 — `config.condition` on a node whose executor never reads it. */
240240
export const FLOW_INERT_NODE_CONDITION = 'flow-inert-node-condition';
241+
/**
242+
* A top-level node no edge path from the start node reaches: it never runs.
243+
* See {@link scanUnreachableNodes}.
244+
*/
245+
export const FLOW_NODE_UNREACHABLE = 'flow-node-unreachable';
241246
/**
242247
* #15429 — a `decision` `config.mode` the spec refuses: a value outside
243248
* `'exclusive' | 'inclusive'`, or a legal `mode` beside a non-empty
@@ -1862,6 +1867,83 @@ function scanTryCatchWithoutCatch(
18621867
* never throws. A finding marked `severity: 'error'` fails the build, and since
18631868
* #5383 it can be raised by a node inside a `loop` body too.
18641869
*/
1870+
/**
1871+
* {@link FLOW_NODE_UNREACHABLE}: a top-level node no edge path from the start
1872+
* node reaches, one `error` finding per node.
1873+
*
1874+
* The engine runs a flow from its first `start` node and follows out-edges from
1875+
* there (`service-automation`'s `executeNode` → `traverseNext`); nothing else
1876+
* schedules a top-level node. So a node no path reaches (an edge forgotten while
1877+
* wiring, a node left behind when its in-edges were deleted) registers,
1878+
* publishes, reports itself configured and never runs: inert on every run,
1879+
* which is this module's bar for `error`.
1880+
*
1881+
* Why lint and not the flow parse: the save door parses `FlowSchema` on every
1882+
* save, a draft included, and the Studio designer produces this shape mid-edit
1883+
* (removing a node that has more or fewer than one in-edge and out-edge drops
1884+
* its edges without bridging them, which leaves its successors unwired). A
1885+
* parse refusal would refuse that draft. As a finding here it fails `os lint` /
1886+
* `os build`, and on the runtime authoring gate (`runtimeTypes: ['flow']`) a
1887+
* live save and a publish, while a draft is kept with it in `_diagnostics`.
1888+
*
1889+
* Scope, declared rather than discovered:
1890+
*
1891+
* - The top-level graph only (see the call site).
1892+
* - A flow with no `start` node is not judged: nothing is reached from
1893+
* nothing, and the engine refuses to run it (`FLOW_NO_START_NODE`).
1894+
* - Every edge counts, whatever its `type` or `condition`: a `fault` edge or a
1895+
* conditional edge is a path the engine can take.
1896+
* - A flow with an edge whose endpoint names no top-level node is not judged:
1897+
* the flow parse refuses that edge, and the node it was meant to reach would
1898+
* be reported a second time, for the same fault, under a cure (add an edge)
1899+
* that is not the one to apply.
1900+
* - A `boundary_event` is exempt, and so is a node reached only through one: it
1901+
* is attached to its host by `boundaryConfig.attachedToNodeId`, not entered by
1902+
* an edge, and its own contract owns its refusal.
1903+
*/
1904+
function scanUnreachableNodes(
1905+
flowName: string,
1906+
nodes: AnyRec[],
1907+
edges: AnyRec[],
1908+
findings: FlowLintFinding[],
1909+
): void {
1910+
const start = nodes.find((n) => n.type === 'start');
1911+
if (!start || typeof start.id !== 'string') return;
1912+
const ids = new Set(nodes.map((n) => n.id).filter((id): id is string => typeof id === 'string'));
1913+
const outgoing = new Map<string, string[]>();
1914+
for (const e of edges) {
1915+
if (typeof e.source !== 'string' || typeof e.target !== 'string') return;
1916+
if (!ids.has(e.source) || !ids.has(e.target)) return;
1917+
const targets = outgoing.get(e.source) ?? [];
1918+
targets.push(e.target);
1919+
outgoing.set(e.source, targets);
1920+
}
1921+
const reached = new Set<string>();
1922+
const visit = (from: readonly string[]): void => {
1923+
const queue = [...from];
1924+
while (queue.length > 0) {
1925+
const id = queue.shift()!;
1926+
if (reached.has(id)) continue;
1927+
reached.add(id);
1928+
queue.push(...(outgoing.get(id) ?? []));
1929+
}
1930+
};
1931+
visit([start.id]);
1932+
visit(nodes.filter((n) => n.type === 'boundary_event' && typeof n.id === 'string').map((n) => n.id as string));
1933+
for (const node of nodes) {
1934+
if (typeof node.id !== 'string' || reached.has(node.id)) continue;
1935+
findings.push({
1936+
where: `flow '${flowName}' · node '${node.id}' (${String(node.type)})`,
1937+
message:
1938+
`no edge path leads to this node from the start node '${start.id}', so it never runs: a run starts ` +
1939+
`at the start node and follows edges, and the flow still registers and reports itself as configured.`,
1940+
hint: `Add an edge into it from a node that runs, or delete the node.`,
1941+
rule: FLOW_NODE_UNREACHABLE,
1942+
severity: 'error',
1943+
});
1944+
}
1945+
}
1946+
18651947
export function lintFlowPatterns(stack: AnyRec): FlowLintFinding[] {
18661948
const findings: FlowLintFinding[] = [];
18671949
for (const flow of recordsOf(stack.flows)) {
@@ -1967,6 +2049,12 @@ export function lintFlowPatterns(stack: AnyRec): FlowLintFinding[] {
19672049
}
19682050
}
19692051

2052+
// (a5) A top-level node no edge path from the start node reaches never runs.
2053+
// Flow-level for the reason the trigger rules are: a run enters the
2054+
// top-level graph at its start node, and a region body is already
2055+
// single-entry (ADR-0031), so nothing one level down can be unreached.
2056+
scanUnreachableNodes(flowName, nodes, edges, findings);
2057+
19702058
// (b)–(e) #5383 — every graph in the flow, not just the top-level one: its
19712059
// own `nodes`/`edges` plus each nested ADR-0031 region, each scanned
19722060
// against ITS OWN edge list. `scope` is empty for the flow's own graph,

0 commit comments

Comments
 (0)