Skip to content
Draft
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
28 changes: 28 additions & 0 deletions .changeset/35143-subflow-target-publish-gate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
'@objectstack/lint': minor
'@objectstack/metadata-protocol': minor
'@objectstack/spec': patch
---

fix(lint)!: the publish gate refuses a subflow or map step that calls a flow the deployment does not hold

Clause-②: yes (narrowing)
Metadata-protocol: narrowed

<!-- adr-0087: not-required (already-registered publish-refuses-flows-that-save-and-do-not-run) the same subflow-target rule at one more door; this change extends that entry's text from a CLI warning to an error at the runtime publish gate, judged against every flow the deployment holds -->

**BREAKING** accept-set narrowing, shipped as `minor`: an active publish of a flow whose `subflow` or `map` step names a flow that no part of the deployment holds was accepted before and is refused now (`422 INVALID_METADATA`, rule `flow-subflow-unknown`), with the fix named. The schema is unchanged, stored flows are not rewritten or refused at boot, and drafts are not gated.

A `subflow` or `map` step runs the flow its `config.flowName` names. When the engine holds no flow of that name, the step fails on every run (`Flow 'X' not found`). `flow-subflow-unknown` reported this only as a CLI warning, because the publish gate judged one flow at a time and could not tell a call to another stored flow from a call to a missing one.

- **The refusal.** On a flow publish the host now states the names of every flow the deployment holds: every installed package's flows (a disabled package's included), the stored flow rows in every state (a draft counts), the flows the same publish batch carries, and every flow the automation engine holds (a flow registered straight into the engine has no metadata row). A call naming none of them, and not the written flow itself, is an `error` at the publish gate.
- **No verdict.** When the host cannot read one of those sources (no automation service, a failed store read, said once at `warn`), or the set is empty, the gate does not judge the call.
- **Not judged.** Whether the engine's package-scoped name resolution (ADR-0150 D3) lets the calling flow reach the called one: the set is the whole deployment, never narrowed to the written package's dependency closure.
- **The CLI.** `os validate` / `lint` / `compile` / `build` still report `flow-subflow-unknown` as a warning: the stack is one app, and another installed package may ship the called flow.
- **Exports.** `validateFlowSubflowTargets` takes an optional second argument (`FlowSubflowTargetOptions`, `deploymentFlowNames`); `AuthoringRuleContext` gains `deploymentFlowNames`; `runRuntimeAuthoringRules` and `evaluateRuntimeAuthoringGate` take an optional `deploymentFlowNames`. All optional; an omitted value keeps the earlier behaviour.

FROM → TO:

- `{ type: 'subflow', config: { flowName: 'notfy_owner' } }` (no such flow) → `{ type: 'subflow', config: { flowName: 'notify_owner' } }`

One-line fix: name a flow the deployment holds, or save the called flow first (a draft is enough) and publish the caller after it.
37 changes: 28 additions & 9 deletions packages/lint/src/authoring-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,18 @@ export interface AuthoringRuleContext {
* contradict (AGENTS.md "Startup registry reads").
*/
flowNodeTypeVocabulary?: ReadonlySet<string>;
/**
* The names of every flow the deployment holds: every installed package's
* flows, the stored flow rows in every state (drafts included), the flows
* the written item's publish batch carries, and every flow the automation
* engine holds. Set only by the runtime publish gate, and only when its host
* could read all of them; ABSENT on the three CLI commands, whose stack is
* one app. Read by `validateFlowSubflowTargets` only: present and non-empty,
* a `subflow` / `map` call naming none of them is refused; absent or empty
* at the runtime gate, that rule judges nothing there (the written flow
* alone is no universe).
*/
deploymentFlowNames?: ReadonlySet<string>;
}

export interface AuthoringRule {
Expand Down Expand Up @@ -1728,20 +1740,27 @@ export const AUTHORING_RULES: readonly AuthoringRule[] = [
// GET → edit → PUT passes, and a secretless `api` flow is refused at `/meta`
// with this id instead of being stored for the engine to refuse at
// registration.
// #35143 — a `subflow` / `map` node calling a flow this stack does not
// define. CLI only: the runtime gate's flow snapshot holds just the written
// flow, so every call to another stored flow would read as unknown there.
// Advisory, with the sibling unknown-object hedge: another installed package
// may ship the called flow.
// #35143 — a `subflow` / `map` node calling a flow that does not exist.
// One verdict per door (the rule's docblock): on the CLI a `warning`, since
// another installed package may ship the called flow; at the runtime publish
// gate an `error`, judged against the deployment's flow names the host
// states (`deploymentFlowNames`), because the gate's own flow snapshot holds
// just the written flow. With no stated names, or none, the runtime gate's
// pass judges nothing: a call to another stored flow cannot be told from a
// call to a missing one there.
{
name: 'validateFlowSubflowTargets',
tier: 'advisory',
tier: 'gating',
input: 'normalized',
commands: ALL,
source: 'packages/lint/src/validate-flow-trigger-readiness.ts',
surfaces: CLI_ONLY,
surfaceReason: RUNTIME_NEEDS_FULL_SNAPSHOT,
run: (stack) => validateFlowSubflowTargets(stack),
surfaces: CLI_AND_RUNTIME,
runtimeTypes: ['flow'],
run: (stack, ctx) => {
if (ctx.runtimeWriteType === undefined) return validateFlowSubflowTargets(stack);
if (ctx.deploymentFlowNames === undefined || ctx.deploymentFlowNames.size === 0) return [];
return validateFlowSubflowTargets(stack, { deploymentFlowNames: ctx.deploymentFlowNames });
},
},
{
name: 'validateFlowApiTriggerSecret',
Expand Down
56 changes: 52 additions & 4 deletions packages/lint/src/flow-publish-checks-second-batch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,59 @@ describe('flow-subflow-unknown', () => {
).toEqual([]);
});

it('runs on the CLI commands and not on the runtime publish gate', () => {
it('stays a warning on the CLI commands', () => {
const cli = runAuthoringRules('validate', { normalized: stack(calling('missing_child')) } as never);
expect(rulesOf(cli)).toContain(FLOW_SUBFLOW_UNKNOWN);
const verdict = runRuntimeAuthoringRules({ type: 'flow', item: calling('missing_child'), context: { objects: [DEAL] } });
expect(rulesOf([...verdict.errors, ...verdict.advisories])).not.toContain(FLOW_SUBFLOW_UNKNOWN);
expect(cli.filter((f) => f.rule === FLOW_SUBFLOW_UNKNOWN).map((f) => f.severity)).toEqual(['warning']);
});

const publish = (item: AnyRec, deploymentFlowNames?: readonly string[]) =>
runRuntimeAuthoringRules({
type: 'flow',
item,
context: { objects: [DEAL] },
...(deploymentFlowNames !== undefined ? { deploymentFlowNames } : {}),
});

it('the runtime publish gate refuses a call to a flow the deployment does not hold', () => {
const verdict = publish(calling('missing_child'), ['child', 'other']);
const refused = verdict.errors.filter((f) => f.rule === FLOW_SUBFLOW_UNKNOWN);
expect(refused).toHaveLength(1);
expect(refused[0]).toMatchObject({ severity: 'error', path: 'flows[0].nodes[1].config.flowName' });
expect(refused[0].message).toContain("calls flow 'missing_child', but no flow of this deployment");
expect(verdict.rulesRun).toContain('validateFlowSubflowTargets');
});

it('refuses a map call nested in a loop body too', () => {
const nested = flow('parent', {}, [
{
id: 'each',
type: 'loop',
label: 'Each',
config: {
collection: { dialect: 'cel', source: '[1]' },
iteratorVariable: 'i',
body: {
nodes: [{ id: 'fan', type: 'map', label: 'Fan', config: { collection: '{{items}}', flowName: 'nope' } }],
edges: [],
},
},
},
]);
const direct = validateFlowSubflowTargets(stack(nested), { deploymentFlowNames: new Set(['child']) });
expect(direct.map((f) => [f.rule, f.severity, f.path])).toEqual([
[FLOW_SUBFLOW_UNKNOWN, 'error', 'flows[0].nodes[1].config.body.nodes[0].config.flowName'],
]);
});

it('the runtime publish gate lets a call through to a flow the deployment holds, or to the written flow itself', () => {
expect(rulesOf(publish(calling('child'), ['child']).errors)).not.toContain(FLOW_SUBFLOW_UNKNOWN);
expect(rulesOf(publish(calling('parent'), ['child']).errors)).not.toContain(FLOW_SUBFLOW_UNKNOWN);
});

it('the runtime publish gate judges nothing with no stated flow names, or an empty set', () => {
for (const verdict of [publish(calling('missing_child')), publish(calling('missing_child'), [])]) {
expect(rulesOf([...verdict.errors, ...verdict.advisories])).not.toContain(FLOW_SUBFLOW_UNKNOWN);
}
});
});

Expand Down
1 change: 1 addition & 0 deletions packages/lint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export {
} from './validate-flow-trigger-readiness.js';
export type {
FlowTriggerReadinessFinding,
FlowSubflowTargetOptions,
FlowTriggerReadinessSeverity,
} from './validate-flow-trigger-readiness.js';

Expand Down
8 changes: 5 additions & 3 deletions packages/lint/src/rule-explanations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7175,9 +7175,11 @@ const FLOW_SUBFLOW_UNKNOWN_EXPLANATION: RuleExplanation = {
paragraphs: [
'A `subflow` or `map` step runs another flow by the name in `config.flowName`. When no flow has that ' +
'name, the step fails on every run, and every run of the calling flow fails with it.',
'A warning, and on the CLI only. Another installed package may ship the called flow, which this stack ' +
'cannot see. And the runtime publish gate judges one flow per write, so a call to another stored flow ' +
'could not be told from a call to a missing one there.',
'On the CLI it is a warning: another installed package may ship the called flow, which this stack ' +
'cannot see. At publish it is an error, judged against every flow the deployment holds: every ' +
'installed package\'s flows, the stored flows in every state (a draft counts), the flows published in ' +
'the same batch, and the flows the automation engine holds. Save the called flow first, then publish ' +
'the one that calls it.',
],
};

Expand Down
14 changes: 14 additions & 0 deletions packages/lint/src/runtime-gate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,15 @@ export function runRuntimeAuthoringRules(args: {
* same value in every pass. Omitted, a flow node's type is not judged.
*/
flowNodeTypeVocabulary?: readonly string[];
/**
* On a `flow` write: the names of every flow the deployment holds, as the
* host read them (every installed package's flows, the stored flow rows in
* every state, the batch's own flow drafts, the automation engine's flows).
* Handed to the rules as `AuthoringRuleContext.deploymentFlowNames`, the
* same value in every pass, so it moves no baseline. Omitted, or empty, a
* `subflow` / `map` call to another flow is not judged at this door.
*/
deploymentFlowNames?: readonly string[];
}): RuntimeGateResult {
const rules = runtimeAuthoringRulesFor(args.type);
const empty: RuntimeGateResult = { errors: [], advisories: [], rulesRun: [] };
Expand Down Expand Up @@ -1539,6 +1548,11 @@ export function runRuntimeAuthoringRules(args: {
...(args.flowNodeTypeVocabulary !== undefined && args.flowNodeTypeVocabulary.length > 0
? { flowNodeTypeVocabulary: new Set(args.flowNodeTypeVocabulary) }
: {}),
// The deployment's flow names, stated by the host on a flow write; the
// same value in every pass, so it moves no baseline.
...(args.deploymentFlowNames !== undefined && args.deploymentFlowNames.length > 0
? { deploymentFlowNames: new Set(args.deploymentFlowNames) }
: {}),
};
const added = addedFindings(rules, snapshots, ctx, args.type, args.item);

Expand Down
66 changes: 57 additions & 9 deletions packages/lint/src/validate-flow-trigger-readiness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1920,21 +1920,52 @@ function signatureUnusableFinding(
* the engine to run that flow by name, and the engine finds none, so the step
* fails every run (`subflow 'X' failed`).
*
* Its OWN exported rule, run on the CLI only, for the reason
* `flow-trigger-unknown-object` carries a hedge plus one more: the runtime
* publish gate judges a flow write over a snapshot whose `flows` holds only
* the written item, so a call to any other stored flow would read as unknown
* there. On the CLI the stack is one app; a flow another installed package
* ships is a legitimate target, so the finding is advisory, as that sibling's
* is without a stated closure.
* Its OWN exported rule, with one verdict per door, decided by #5762's
* question (is what this rule reads enough to know?):
*
* - On the CLI the stack is one app. A flow another installed package ships
* is a legitimate target the stack cannot see, so the finding is a
* `warning`, as `flow-trigger-unknown-object`'s is without a stated closure.
* - At the runtime publish gate the snapshot's `flows` holds only the written
* item, so that snapshot alone cannot judge a call. The host states the
* names of every flow the deployment holds instead
* (`deploymentFlowNames`: every installed package's flows, the stored rows
* in every state, drafts included, this publish batch's own drafts, and
* every flow the automation engine holds). A name in none of those is a
* flow the engine cannot find, so every run of the step fails: `error`.
* The set is the whole deployment, never narrowed to the written package's
* closure, so a call this rule lets through may still be one the engine's
* package-scoped name resolution refuses (ADR-0150 D3); this rule does not
* judge that. A draft counts as held, so two new flows that call each
* other can be published one at a time.
* - At the runtime gate with no stated names, or an empty set, it judges
* nothing: no deployment state was handed over, and the written flow
* alone is no universe (the #24668 reading of an empty set with no
* closure).
*/
export const FLOW_SUBFLOW_UNKNOWN = 'flow-subflow-unknown';

export function validateFlowSubflowTargets(stack: AnyRec): FlowTriggerReadinessFinding[] {
export interface FlowSubflowTargetOptions {
/**
* The names of every flow the deployment holds, as the runtime publish
* gate's host states them (`AuthoringRuleContext.deploymentFlowNames`).
* Present and non-empty, a call that names none of them, nor a flow of
* this stack, is an `error`. Absent, the CLI's `warning` verdict applies.
*/
readonly deploymentFlowNames?: ReadonlySet<string>;
}

export function validateFlowSubflowTargets(
stack: AnyRec,
options: FlowSubflowTargetOptions = {},
): FlowTriggerReadinessFinding[] {
const findings: FlowTriggerReadinessFinding[] = [];
const flows = recordsOf(stack.flows);
if (flows.length === 0) return findings;
const known = new Set<string>();
const deployment = options.deploymentFlowNames !== undefined && options.deploymentFlowNames.size > 0
? options.deploymentFlowNames
: undefined;
const known = new Set<string>(deployment);
for (const flow of flows) {
const name = nonEmptyString(flow.name);
if (name) known.add(name);
Expand All @@ -1954,6 +1985,23 @@ export function validateFlowSubflowTargets(stack: AnyRec): FlowTriggerReadinessF
if (!called || known.has(called)) continue;
const nodeId = nonEmptyString(node.id) ?? String(node.type);
const nodeWhere = regionTrail ? `${regionTrail} › node "${nodeId}"` : `node "${nodeId}"`;
if (deployment) {
findings.push({
severity: 'error',
rule: FLOW_SUBFLOW_UNKNOWN,
where: `flow "${flowName}" › ${nodeWhere}`,
path: `${path}.config.flowName`,
message:
`${String(node.type)} node '${nodeId}' calls flow '${called}', but no flow of this deployment (an ` +
`installed package's, a stored flow or a draft) has that name, so the engine finds none and the ` +
`step fails on every run` +
suggestName(called, known),
hint:
`Set config.flowName to the exact name of a flow this deployment holds, or save the called flow ` +
`first (a draft is enough) and publish this one after it`,
});
continue;
}
findings.push({
severity: 'warning',
rule: FLOW_SUBFLOW_UNKNOWN,
Expand Down
Loading
Loading