Skip to content

Commit 12d73bf

Browse files
committed
revert: take the parse-level reachability rule back out (it moves to lint)
Claude-Session: https://claude.ai/code/session_01FEkQ5oEQNYg7j3ueo5t6pV Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5ccbebe commit 12d73bf

10 files changed

Lines changed: 37 additions & 238 deletions

‎packages/metadata-protocol/src/protocol.metadata-redaction.test.ts‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,7 @@ function relocate(served: any, secret?: string) {
766766
config: { triggerType: 'api', hookId: 'intake', ...(secret !== undefined ? { secret } : {}) },
767767
},
768768
],
769-
// `e2` keeps the old start node reached: a node no edge reaches is
770-
// refused at parse, which is not the refusal these tests are about.
771-
edges: [{ id: 'e1', source: 'begin_v2', target: 'finish' }, { id: 'e2', source: 'begin_v2', target: 'begin' }],
769+
edges: [{ id: 'e1', source: 'begin_v2', target: 'finish' }],
772770
};
773771
}
774772

@@ -908,8 +906,7 @@ function storedCalloutFlow() {
908906
},
909907
},
910908
],
911-
// Wired: a top-level node no edge reaches is refused at parse.
912-
edges: [{ id: 's1', source: 'begin', target: 'each' }, { id: 's2', source: 'each', target: 'fan' }],
909+
edges: [],
913910
};
914911
}
915912

@@ -1045,7 +1042,6 @@ function storedMovesFlow() {
10451042
const flow: any = storedCalloutFlow();
10461043
flow.name = 'moves';
10471044
flow.nodes.push({ id: 'call', type: 'http', label: 'Call', config: { url: 'https://c', durable: true, signingSecret: SIGNING } });
1048-
flow.edges.push({ id: 's3', source: 'fan', target: 'call' });
10491045
return flow;
10501046
}
10511047

@@ -1058,7 +1054,6 @@ function movedOutOfLoop(served: any) {
10581054
return {
10591055
...served,
10601056
nodes: [begin, { ...each, config: { ...each.config, body: { nodes: [NOOP('body_noop')], edges: [] } } }, fan, call, perRow],
1061-
edges: [...served.edges, { id: 's4', source: 'call', target: perRow.id }],
10621057
};
10631058
}
10641059

@@ -1183,7 +1178,7 @@ describe('#20590 round 2 — the relocation counts nodes, not every object carry
11831178
const stored = storedMovesFlow();
11841179
const incoming = movedWithEdgeTwin(redactMetadataItem('flow', stored));
11851180
const out: any = carryForwardRedactedValues('flow', incoming, stored);
1186-
expect(out.edges.map((e: any) => e.id)).toEqual(['s1', 's2', 's3', 's4', 'per_row']);
1181+
expect(out.edges.map((e: any) => e.id)).toEqual(['per_row']);
11871182
expect(out.nodes[4].id).toBe('per_row');
11881183
expect(out.nodes[4].config.signingSecret).toBe(SIGNING);
11891184
expect(allStrings(redactMetadataItem('flow', out))).not.toContain(SIGNING);
@@ -1202,7 +1197,7 @@ describe('#20590 round 2 — the relocation counts nodes, not every object carry
12021197
await protocol.saveMetaItem({ type: 'flow', name: 'moves', item: movedWithEdgeTwin(editable) });
12031198

12041199
const at = JSON.parse(Array.from(rows.values()).find((r) => r.name === 'moves' && r.state === 'active')!.metadata);
1205-
expect(at.edges.map((e: any) => e.id)).toEqual(['s1', 's2', 's3', 's4', 'per_row']);
1200+
expect(at.edges.map((e: any) => e.id)).toEqual(['per_row']);
12061201
expect(at.nodes[4].config.signingSecret).toBe(SIGNING);
12071202
expect(allStrings(await protocol.getMetaItem({ type: 'flow', name: 'moves' }))).not.toContain(SIGNING);
12081203
});

‎packages/metadata-protocol/src/runtime-authoring-gate.flow-region.test.ts‎

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,14 @@ const RULE = 'flow-region-shape-invalid';
2121

2222
type Rec = Record<string, unknown>;
2323

24-
/**
25-
* start → the given nodes → end, chained in order: a top-level node no edge
26-
* reaches is refused at parse, and that is not the rule these cases judge.
27-
*/
28-
const flowOf = (name: string, nodes: Rec[]) => {
29-
const ids = ['start', ...nodes.map((n) => String(n.id)), 'end'];
30-
return {
31-
name,
32-
label: name,
33-
type: 'autolaunched',
34-
nodes: [{ id: 'start', type: 'start', label: 'Start' }, ...nodes, { id: 'end', type: 'end', label: 'End' }],
35-
edges: ids.slice(1).map((target, i) => ({ id: `e${i}`, source: ids[i], target })) as Rec[],
36-
};
37-
};
24+
/** start → the given nodes (unwired) → end; region cases need no top-level edges. */
25+
const flowOf = (name: string, nodes: Rec[]) => ({
26+
name,
27+
label: name,
28+
type: 'autolaunched',
29+
nodes: [{ id: 'start', type: 'start', label: 'Start' }, ...nodes, { id: 'end', type: 'end', label: 'End' }],
30+
edges: [] as Rec[],
31+
});
3832

3933
const oneStep = (id: string) => ({ nodes: [{ id, type: 'assignment', label: id }], edges: [] });
4034

‎packages/services/service-automation/src/builtin/notify-currency-read-fault.test.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@ describe('notify — a currency hole refused after a FAILED tenant-settings read
131131

132132
it('under errorHandling retry the run succeeds once the read does, and the title formats in the default', async () => {
133133
const flow = flowWith({ errorHandling: { strategy: 'retry', maxRetries: 2, backoffMs: 1 } });
134-
// Without its fault edge the handler is reached by nothing, which the
135-
// parse refuses, so it goes with the edge.
136-
flow.edges = flow.edges.filter((e) => e.type !== 'fault' && e.source !== 'handled');
137-
flow.nodes = flow.nodes.filter((n) => n.id !== 'handled');
134+
flow.edges = flow.edges.filter((e) => e.type !== 'fault');
138135
const { engine, messaging } = engineWith(flow);
139136
let reads = 0;
140137
engine.setTenantCurrencyResolver(() => {

‎packages/services/service-automation/src/canonicalize-stored-flow.test.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,16 +246,13 @@ describe('canonicalizeStoredFlow — every site registerFlow refuses after the p
246246
engine.registerNodeExecutor(stampExecutor);
247247
return engine;
248248
};
249-
// The nodes are chained `start → … → end`: a top-level node no edge reaches
250-
// is refused at parse, and that is not the check these cases judge.
251-
const chain = (ids: string[]) => ids.slice(1).map((target, i) => ({ id: `e${i}`, source: ids[i], target }));
252249
const flowOf = (nodes: unknown[], extra: Record<string, unknown> = {}) => ({
253250
name: 'fd_stored',
254251
label: 'Stored',
255252
type: 'autolaunched',
256253
status: 'active',
257254
nodes: [{ id: 'start', type: 'start', label: 'Start' }, ...nodes, { id: 'end', type: 'end', label: 'End' }],
258-
edges: chain(['start', ...nodes.map((n) => (n as { id: string }).id), 'end']),
255+
edges: [],
259256
...extra,
260257
});
261258
const notify = (title: string) => ({

‎packages/services/service-automation/src/fault-edge-guard-containment.test.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,7 @@ describe('#3863 — a fault edge must not swallow a guard refusal', () => {
280280
it('a guard refusal without any fault edge is fatal, as before', async () => {
281281
const flow = guardedDeleteWithHandler();
282282
flow.name = 'no_handler';
283-
// Without its fault edge the handler is reached by nothing, which the
284-
// parse refuses, so it goes with the edge.
285-
flow.edges = flow.edges.filter((e) => e.type !== 'fault' && e.source !== 'handler');
286-
flow.nodes = flow.nodes.filter((n) => n.id !== 'handler');
283+
flow.edges = flow.edges.filter((e) => e.type !== 'fault');
287284
engine.registerFlow('no_handler', flow);
288285

289286
const result = await engine.execute('no_handler', {

‎packages/spec/src/automation/flow-region-pause-and-end.test.ts‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,7 @@ const pausingNode = (type: string, id = 'pauser'): FlowNode => ({
5757

5858
const step = (id: string): FlowNode => ({ id, type: 'assignment', label: id });
5959

60-
// Unless a test passes its own edges, the nodes are chained from `start` in
61-
// order: a top-level node no edge reaches is refused at parse, and that rule is
62-
// not the one these tests judge.
63-
const chainFromStart = (nodes: FlowNode[]): FlowEdge[] =>
64-
nodes.map((node, i) => ({ id: `chain_${i}`, source: i === 0 ? 'start' : nodes[i - 1].id, target: node.id }));
65-
66-
const flowWith = (nodes: FlowNode[], edges: FlowEdge[] = chainFromStart(nodes)): Flow => ({
60+
const flowWith = (nodes: FlowNode[], edges: FlowEdge[] = []): Flow => ({
6761
name: 'region_contents',
6862
label: 'Region contents',
6963
type: 'autolaunched',

‎packages/spec/src/automation/flow.test.ts‎

Lines changed: 15 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,20 +2367,12 @@ describe('FlowSchema — top-level node ids are unique', () => {
23672367
});
23682368

23692369
it('accepts the same flow once the ids are unique, keeping the nodes in authored order', () => {
2370-
// `n2` is wired in: a node no edge reaches is refused at parse.
2371-
const unique = {
2372-
...flowWith([
2373-
{ id: 'start', type: 'start', label: 'Start' },
2374-
{ id: 'n', type: 'assignment', label: 'Assign A' },
2375-
{ id: 'n2', type: 'assignment', label: 'Assign B' },
2376-
{ id: 'end', type: 'end', label: 'End' },
2377-
]),
2378-
edges: [
2379-
{ id: 'e1', source: 'start', target: 'n' },
2380-
{ id: 'e2', source: 'n', target: 'n2' },
2381-
{ id: 'e3', source: 'n2', target: 'end' },
2382-
],
2383-
};
2370+
const unique = flowWith([
2371+
{ id: 'start', type: 'start', label: 'Start' },
2372+
{ id: 'n', type: 'assignment', label: 'Assign A' },
2373+
{ id: 'n2', type: 'assignment', label: 'Assign B' },
2374+
{ id: 'end', type: 'end', label: 'End' },
2375+
]);
23842376
const result = FlowSchema.safeParse(unique);
23852377
expect(result.success).toBe(true);
23862378
if (!result.success) return;
@@ -2653,23 +2645,15 @@ describe('FlowSchema — one node-id space across the top-level nodes[] and ever
26532645
});
26542646

26552647
it('accepts a flow whose ids are unique across the whole flow, keeping every region node in authored order', () => {
2656-
// `p` is wired in: a node no edge reaches is refused at parse.
2657-
const unique = {
2658-
...flowWith([
2659-
{ id: 'start', type: 'start', label: 'Start' },
2660-
loopOver([step('sweep_first'), step('sweep_second')], [{ id: 'b1', source: 'sweep_first', target: 'sweep_second' }]),
2661-
{
2662-
id: 'p', type: 'parallel', label: 'Fan out',
2663-
config: { branches: [{ nodes: [step('left')] }, { nodes: [step('right')] }] },
2664-
},
2665-
{ id: 'end', type: 'end', label: 'End' },
2666-
]),
2667-
edges: [
2668-
{ id: 'e1', source: 'start', target: 'n' },
2669-
{ id: 'e2', source: 'n', target: 'p' },
2670-
{ id: 'e3', source: 'p', target: 'end' },
2671-
],
2672-
};
2648+
const unique = flowWith([
2649+
{ id: 'start', type: 'start', label: 'Start' },
2650+
loopOver([step('sweep_first'), step('sweep_second')], [{ id: 'b1', source: 'sweep_first', target: 'sweep_second' }]),
2651+
{
2652+
id: 'p', type: 'parallel', label: 'Fan out',
2653+
config: { branches: [{ nodes: [step('left')] }, { nodes: [step('right')] }] },
2654+
},
2655+
{ id: 'end', type: 'end', label: 'End' },
2656+
]);
26732657
const result = FlowSchema.safeParse(unique);
26742658
expect(result.success).toBe(true);
26752659
if (!result.success) return;
@@ -2868,88 +2852,3 @@ describe('FlowSchema — an edge resolves in its own graph, and is followed once
28682852
expect(defineFlow(flow).edges.map((e) => e.id)).toEqual(['e1', 'e2', 'e3']);
28692853
});
28702854
});
2871-
2872-
describe('FlowSchema — every top-level node is reachable from the start node', () => {
2873-
// A run starts at the `start` node and follows edges; nothing else schedules
2874-
// a top-level node. A node no edge path reaches parsed, published and never
2875-
// ran. Refused at `nodes[i]`, for each such node.
2876-
const start: FlowNode = { id: 'start', type: 'start', label: 'Start' };
2877-
const end: FlowNode = { id: 'end', type: 'end', label: 'End' };
2878-
const step = (id: string): FlowNode => ({ id, type: 'assignment', label: id });
2879-
const flowOf = (nodes: FlowNode[], edges: FlowEdge[]): Flow => ({
2880-
name: 'reach_flow',
2881-
label: 'Reach flow',
2882-
type: 'autolaunched',
2883-
nodes,
2884-
edges,
2885-
});
2886-
2887-
it('refuses an action node with no in-edge, anchored at the node, naming it and the start node', () => {
2888-
const result = FlowSchema.safeParse(flowOf([start, step('orphan'), end], [
2889-
{ id: 'e1', source: 'start', target: 'end' },
2890-
]));
2891-
expect(result.success).toBe(false);
2892-
if (result.success) return;
2893-
expect(result.error.issues.map((i) => [i.code, i.path])).toEqual([['custom', ['nodes', 1]]]);
2894-
const [issue] = result.error.issues;
2895-
expect(issue.message).toContain('Node `orphan` (`assignment`, `nodes[1]`) is not reachable');
2896-
expect(issue.message).toContain('from the start node `start`');
2897-
});
2898-
2899-
it('refuses every node of a disconnected chain — an in-edge from an unreachable node is no path', () => {
2900-
const result = FlowSchema.safeParse(flowOf([start, step('a'), step('b'), end], [
2901-
{ id: 'e1', source: 'start', target: 'end' },
2902-
{ id: 'e2', source: 'a', target: 'b' },
2903-
{ id: 'e3', source: 'b', target: 'end' },
2904-
]));
2905-
expect(result.success).toBe(false);
2906-
if (result.success) return;
2907-
expect(result.error.issues.map((i) => i.path)).toEqual([['nodes', 1], ['nodes', 2]]);
2908-
});
2909-
2910-
it('refuses through every door that parses a flow — defineFlow throws', () => {
2911-
expect(() => defineFlow(flowOf([start, step('orphan'), end], [
2912-
{ id: 'e1', source: 'start', target: 'end' },
2913-
]))).toThrow(/Node `orphan`/);
2914-
});
2915-
2916-
it('CONTROL — a node reached only by a `fault` edge or a conditional edge is reachable', () => {
2917-
const result = FlowSchema.safeParse(flowOf([start, step('work'), step('recover'), step('big'), end], [
2918-
{ id: 'e1', source: 'start', target: 'work' },
2919-
{ id: 'e2', source: 'work', target: 'end' },
2920-
{ id: 'e3', source: 'work', target: 'recover', type: 'fault' },
2921-
{ id: 'e4', source: 'recover', target: 'end' },
2922-
{ id: 'e5', source: 'start', target: 'big', condition: 'record.amount > 1' },
2923-
{ id: 'e6', source: 'big', target: 'end' },
2924-
]));
2925-
expect(result.success).toBe(true);
2926-
});
2927-
2928-
it('CONTROL — a `boundary_event`, and a node reached only through one, are not judged', () => {
2929-
const result = FlowSchema.safeParse(flowOf([
2930-
start,
2931-
step('work'),
2932-
{
2933-
id: 'on_error', type: 'boundary_event', label: 'On error',
2934-
boundaryConfig: { attachedToNodeId: 'work', eventType: 'error' },
2935-
},
2936-
step('recover'),
2937-
end,
2938-
], [
2939-
{ id: 'e1', source: 'start', target: 'work' },
2940-
{ id: 'e2', source: 'work', target: 'end' },
2941-
{ id: 'e3', source: 'on_error', target: 'recover' },
2942-
{ id: 'e4', source: 'recover', target: 'end' },
2943-
]));
2944-
expect(result.success).toBe(true);
2945-
});
2946-
2947-
it('CONTROL — a flow with no start node, and a graph with a dangling edge, are left to their own refusals', () => {
2948-
expect(FlowSchema.safeParse(flowOf([step('a'), end], [{ id: 'e1', source: 'a', target: 'end' }])).success)
2949-
.toBe(true);
2950-
const dangling = FlowSchema.safeParse(flowOf([start, end], [{ id: 'e1', source: 'start', target: 'node_1' }]));
2951-
expect(dangling.success).toBe(false);
2952-
if (dangling.success) return;
2953-
expect(dangling.error.issues.map((i) => i.path)).toEqual([['edges', 0, 'target']]);
2954-
});
2955-
});

‎packages/spec/src/automation/flow.zod.ts‎

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,82 +1910,8 @@ export const FlowSchema = lazySchema(() => strictObject(
19101910
});
19111911
});
19121912
}
1913-
1914-
for (const refusal of unreachableTopLevelNodeRefusals(flow.nodes, flow.edges)) {
1915-
ctx.addIssue({ code: 'custom', path: ['nodes', refusal.index], message: refusal.message });
1916-
}
19171913
}));
19181914

1919-
/**
1920-
* The top-level nodes no edge path from the `start` node reaches, each with
1921-
* the refusal an author meets at `nodes[i]`.
1922-
*
1923-
* The engine runs a flow from its first `start` node and follows out-edges
1924-
* from there (`service-automation`'s `executeNode` → `traverseNext`); nothing
1925-
* else ever schedules a top-level node. So a node no edge path reaches — an
1926-
* edge forgotten while wiring, a node left behind when its in-edge was
1927-
* deleted — parses, registers, publishes and never runs. Refused here so the
1928-
* author meets it at every door the endpoint refusal above reaches.
1929-
*
1930-
* Scope, declared rather than discovered:
1931-
*
1932-
* - The TOP-LEVEL graph only. A region body (`loop` / `try_catch` /
1933-
* `parallel`) is already single-entry and acyclic under ADR-0031
1934-
* (`analyzeRegion`), and in a DAG with one source every node is reachable
1935-
* from it, so a region cannot hold an unreachable node.
1936-
* - A flow with no `start` node is not judged: it has no run to reach anything
1937-
* from, and the engine refuses to run it (`FLOW_NO_START_NODE`).
1938-
* - Every edge counts, whatever its `type` or `condition`: a `fault` edge or a
1939-
* conditional edge is a path the engine can take.
1940-
* - A graph holding an edge whose endpoint names no top-level node is not
1941-
* judged: the endpoint rule above refuses that edge, and the node it was
1942-
* meant to reach would otherwise be reported a second time, for the same
1943-
* fault, under a cure (add an edge) that is not the one to apply.
1944-
* - A `boundary_event` is exempt, and so is a node reached only through one:
1945-
* it is attached to its host by `boundaryConfig.attachedToNodeId`, not
1946-
* entered by an edge, and its own contract owns its refusal.
1947-
*/
1948-
function unreachableTopLevelNodeRefusals(
1949-
nodes: ReadonlyArray<{ id: string; type: string }>,
1950-
edges: ReadonlyArray<{ source: string; target: string }>,
1951-
): Array<{ index: number; message: string }> {
1952-
const start = nodes.find((node) => node.type === 'start');
1953-
if (start === undefined) return [];
1954-
const ids = new Set(nodes.map((node) => node.id));
1955-
if (edges.some((edge) => !ids.has(edge.source) || !ids.has(edge.target))) return [];
1956-
const outgoing = new Map<string, string[]>();
1957-
for (const edge of edges) {
1958-
const targets = outgoing.get(edge.source) ?? [];
1959-
targets.push(edge.target);
1960-
outgoing.set(edge.source, targets);
1961-
}
1962-
const reached = new Set<string>();
1963-
const visit = (from: readonly string[]): void => {
1964-
const queue = [...from];
1965-
while (queue.length > 0) {
1966-
const id = queue.shift()!;
1967-
if (reached.has(id)) continue;
1968-
reached.add(id);
1969-
queue.push(...(outgoing.get(id) ?? []));
1970-
}
1971-
};
1972-
visit([start.id]);
1973-
visit(nodes.filter((node) => node.type === 'boundary_event').map((node) => node.id));
1974-
const refusals: Array<{ index: number; message: string }> = [];
1975-
nodes.forEach((node, index) => {
1976-
if (reached.has(node.id)) return;
1977-
refusals.push({
1978-
index,
1979-
message:
1980-
`Node \`${node.id}\` (\`${node.type}\`, \`nodes[${index}]\`) is not reachable: no edge path leads to it ` +
1981-
`from the start node \`${start.id}\`. A run starts at the start node and follows edges, so this node ` +
1982-
'never runs, while the flow registers and reports itself as configured. Add an edge into it from a ' +
1983-
'node that runs, or delete the node.',
1984-
});
1985-
});
1986-
return refusals;
1987-
}
1988-
19891915
/**
19901916
* The edge list a `FlowGraph` was read from, as the author wrote it —
19911917
* `graph.path` is the key path from the flow root to the object holding it.

0 commit comments

Comments
 (0)