Skip to content

Commit 241763a

Browse files
committed
fix(cli)!: os validate and os build refuse an undeclared top-level flow cycle, with the engine's sentence
The CLI's flow walk asks findUndeclaredFlowCycle (@objectstack/metadata-core), the judge the engine's registration and the runtime publish gate call, before validateControlFlow, in the engine's order. Claude-Session: https://claude.ai/code/session_01ADHkmSGEsjUPQp4S968p2X Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5dcd9fc commit 241763a

4 files changed

Lines changed: 55 additions & 17 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/cli': patch
3+
---
4+
5+
**BREAKING** fix(cli)!: `os validate` and `os build` refuse a flow whose top-level graph closes a cycle with no `type: 'back'` edge, as the automation engine refuses it at registration
6+
7+
Clause-②: no (narrowing)
8+
Metadata-protocol: none
9+
Skills-docs: none — `skills/objectstack-automation/references/state-machines-and-approvals.md` already teaches that a cycle-closing edge MUST be typed `'back'` and that an unmarked cycle is refused; that stays true, and the CLI now refuses the same flow before it ships.
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped. The build verbs now refuse a flow body the automation engine already refused to register and the publish doors already refuse, with the engine's own sentence, so there is nothing a migration could rewrite: the author's fix is the one the refusal names. -->
12+
13+
**BREAKING** accept-set narrowing at the CLI's author-time doors (`@objectstack/cli`).
14+
15+
- **Before.** A flow whose top-level graph had a cycle with no edge typed `back` (ADR-0044), such as `start → push → check → revise → push`, passed `os validate` and `os build` with exit 0. The engine then refused to register it at boot ("Flow contains a cycle: …"), logged a warning, and ran without it.
16+
- **Now.** Both commands refuse it, exit 1, and `os build` writes no artifact. The row is `VALIDATION_ERROR`, located at the flow (`flows[N]`, or `packages[K].manifest.flows[N]` in an assembled artifact), and its message is the engine's registration refusal, word for word. The judge is `findUndeclaredFlowCycle` from `@objectstack/metadata-core`, the one the engine's registration and the runtime publish gate call, so all three refuse exactly the same graphs. Like the engine, the cycle is judged before the ADR-0031 region shape, and each flow reports its first refusal.
17+
- **Unchanged.** A cycle with any of its edges typed `back` validates and builds, as before. Cycles inside a `loop` / `parallel` / `try_catch` region are judged by the region check, as before.
18+
19+
**The remedy.** None for a flow that registers today. A flow this now refuses never ran: if the loop is intended, set `type: 'back'` on the cycle-closing edge (ADR-0044); otherwise remove or redirect that edge.

‎packages/cli/src/commands/compile.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,9 @@ export default class Compile extends Command {
846846
// `validateControlFlow`). Before this the build emitted a flow the
847847
// engine then refused at boot, logging a warning and running without
848848
// it; now the door that ships refuses it and writes no artifact. Same
849-
// two faces as the gates above.
849+
// two faces as the gates above. [#29051] The same walk first asks
850+
// the engine's top-level cycle judge (ADR-0044,
851+
// `findUndeclaredFlowCycle`), in the engine's order.
850852
const regionRefusals = findFlowRegionRefusals(result.data as Record<string, unknown>);
851853
if (regionRefusals.length > 0) {
852854
if (flags.json) {
@@ -855,10 +857,10 @@ export default class Compile extends Command {
855857
}
856858
const n = regionRefusals.length;
857859
console.log('');
858-
printError(`The automation engine would refuse to register ${n} flow${n > 1 ? 's' : ''} for a malformed region (ADR-0031)`);
860+
printError(`The automation engine would refuse to register ${n} flow${n > 1 ? 's' : ''} for an undeclared cycle (ADR-0044) or a malformed region (ADR-0031)`);
859861
printBulletList(
860862
regionRefusals.map((r) => `${r.path} [${r.code}] ${r.message}`),
861-
{ noun: 'flow region refusal(s)', remedy: JSON_FULL_LIST_REMEDY },
863+
{ noun: 'flow registration refusal(s)', remedy: JSON_FULL_LIST_REMEDY },
862864
);
863865
this.exit(1);
864866
}

‎packages/cli/src/commands/validate.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,9 @@ export default class Validate extends Command {
761761
// (`FlowSchema`, then the spec's `validateControlFlow`), so a flow
762762
// green here is one boot registers instead of logging
763763
// `[Automation] failed to register flow` and running without it; see
764-
// `utils/flow-region-shape.ts`.
764+
// `utils/flow-region-shape.ts`. [#29051] The same walk first asks
765+
// the engine's top-level cycle judge (ADR-0044,
766+
// `findUndeclaredFlowCycle`), in the engine's order.
765767
const regionRefusals = findFlowRegionRefusals(result.data as Record<string, unknown>);
766768
if (regionRefusals.length > 0) {
767769
if (flags.json) {
@@ -776,10 +778,10 @@ export default class Validate extends Command {
776778
}
777779
const n = regionRefusals.length;
778780
console.log('');
779-
printError(`The automation engine would refuse to register ${n} flow${n > 1 ? 's' : ''} for a malformed region (ADR-0031)`);
781+
printError(`The automation engine would refuse to register ${n} flow${n > 1 ? 's' : ''} for an undeclared cycle (ADR-0044) or a malformed region (ADR-0031)`);
780782
printBulletList(
781783
regionRefusals.map((r) => `${r.path} [${r.code}] ${r.message}`),
782-
{ noun: 'flow region refusal(s)', remedy: JSON_FULL_LIST_REMEDY },
784+
{ noun: 'flow registration refusal(s)', remedy: JSON_FULL_LIST_REMEDY },
783785
);
784786
this.exit(1);
785787
}

‎packages/cli/src/utils/flow-region-shape.ts‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@
2929
* gate exists to close. The row says the flow could not be judged, with the
3030
* schema's issues, and the door refuses on it like any other row.
3131
*
32-
* Not judged here: a cycle in the flow's TOP-LEVEL graph. The engine refuses it
33-
* with `detectCycles`, which lives in `@objectstack/service-automation` and is
34-
* not exported; region bodies ARE cycle-checked, by `validateControlFlow`.
32+
* [#29051] Also judged: a cycle in the flow's TOP-LEVEL graph that no
33+
* `type: 'back'` edge declares (ADR-0044). The engine asks
34+
* `findUndeclaredFlowCycle` (`@objectstack/metadata-core`) at registration,
35+
* BEFORE `validateControlFlow`, and so does this walk: the same judge, the same
36+
* order, the engine's sentence. The runtime authoring gate asks it too, so a
37+
* flow refused here is one the publish doors refuse. Region bodies are
38+
* cycle-checked by `validateControlFlow`, not by this call.
3539
*/
3640

41+
import { findUndeclaredFlowCycle } from '@objectstack/metadata-core';
3742
import { FlowSchema, validateControlFlow } from '@objectstack/spec/automation';
3843

3944
import { artifactPackages } from './artifact-packages.js';
@@ -53,7 +58,11 @@ export interface FlowRegionRefusalRow {
5358
message: string;
5459
}
5560

56-
/** Every flow of the parsed stack the engine would refuse to register for its region shape. */
61+
/**
62+
* Every flow of the parsed stack the engine would refuse to register for an
63+
* undeclared top-level cycle or for its region shape — one row per flow, the
64+
* engine's first refusal.
65+
*/
5766
export function findFlowRegionRefusals(parsed: Record<string, unknown>): FlowRegionRefusalRow[] {
5867
const entries = artifactPackages(parsed);
5968
const subjects = entries.length > 0
@@ -78,16 +87,22 @@ export function findFlowRegionRefusals(parsed: Record<string, unknown>): FlowReg
7887
});
7988
return;
8089
}
90+
const name = result.data.name;
91+
const refuse = (reason: string) => rows.push({
92+
path: `${at}flows[${i}]`,
93+
code: 'VALIDATION_ERROR',
94+
flow: name,
95+
message: `Flow '${name}' would be refused at registration: ${reason}`,
96+
});
97+
const cycle = findUndeclaredFlowCycle(result.data);
98+
if (cycle) {
99+
refuse(cycle.message);
100+
return;
101+
}
81102
try {
82103
validateControlFlow(result.data);
83104
} catch (err) {
84-
const name = result.data.name;
85-
rows.push({
86-
path: `${at}flows[${i}]`,
87-
code: 'VALIDATION_ERROR',
88-
flow: name,
89-
message: `Flow '${name}' would be refused at registration: ${err instanceof Error ? err.message : String(err)}`,
90-
});
105+
refuse(err instanceof Error ? err.message : String(err));
91106
}
92107
});
93108
}

0 commit comments

Comments
 (0)