Skip to content

Commit a725383

Browse files
committed
feat(describe): Mode 2 — describe crossed branches faithfully by default
A merge reached by branches of two different splits has no place in a tree, so DESCRIBE walked past it and emitted the conjunction along one path: the reporter's activity ran on `not($A) or $B` and described as `$A and $B`. Phase E made an ERROR path's rejoin sayable; this says the other half with the same vocabulary, and it is the shape #923 was actually reported for. The default rendering is now faithful — every branch ends in `join <label>` and the shared part follows as `merge <label>` sections — so MDL-FLOW01's "this description is NOT equivalent and must not be re-executed" is retired for the recombinable class. That sentence was the point: it sent people to Studio Pro for an edit they could have made in MDL. Three traps, each of which produced plausible output: - A crossed merge is emitted the OPPOSITE way from an error-rejoin merge. A rejoin is DECLARED where the traversal meets it; a crossed merge is JOINED by each branch and declared once afterwards. The label alone cannot drive that, so mergeLabels carries a crossed set beside the names (a pure refactor, verified byte-identical over 18 microflows before any behaviour changed). - The join is emitted BEFORE the visited guard. Arriving twice is what crossed MEANS, and the guard silently swallowed the second branch's join, leaving that path falling off the end of the description. - MDL-FLOW01 is retired on what was EMITTED, not on what was labelled. An inheritance split has its own traversal that walks through a labelled merge without emitting a join, so the label goes unused and the reader still gets the nested rendering. Suppressing on the label alone silenced the warning on Administration.ManageMyAccount, whose description is byte-identical with and without this change — which is why warnings are now computed after the body. (Its MDL-FLOW01 is a pre-existing classifier false positive: the shared entry is the split's own join. Left alone rather than silenced by accident.) The post-dominator is labelled as well as the shared entry, and that is not belt-and-braces. mxcli permits fall-through into a `merge`, so an EMPTY branch — split2's false arm — would fall into the shared merge instead of past it, silently describing a different graph. Explicit joins everywhere is what the proposal's Mode 2 sketch wanted fall-through banned for. Interleaved graphs are untouched and keep MDL-FLOW01: they overlap at more than one entry, and nesting needs a duplicated activity or an invented boolean (Boehm-Jacopini). The warning is now a true statement about them rather than a blanket one. Verified: 16 of 18 microflows describe byte-identically against a baseline binary, and the 2 that change are the 2 genuinely crossed ones. Both round-trip with their merge $IDs intact, converge after one step, and a re-exec is elided (Unchanged). Behaviour checked on a real runtime across the whole truth table — the two `$A = false` rows are the ones the old flattening got wrong. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018hifgRSawfaRWXS44YKtSJ
1 parent d3e7273 commit a725383

14 files changed

Lines changed: 697 additions & 55 deletions

‎.claude/skills/fix-issue/findings/mdl-executor.jsonl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,3 +610,4 @@
610610
{"area": "mdl-executor", "date": "2026-09-13", "symptom": "DESCRIBE silently deletes an ExclusiveMerge: describe -> exec leaves the microflow with fewer merge nodes than the stored graph, with no warning, no MDL-FLOW01 and mx check clean", "cause": "The nested describer walks straight through a merge with a single incoming path without emitting anything for it, so the rebuild has no reason to create it. Only two merge shapes were represented: a split's join point (rendered by `end if`) and a labelled error rejoin (`merge <label>`).", "file": "mdl/executor/cmd_microflows_show_merge.go", "fix": "droppedMergeWarnings() emits a describe-time warning for any ExclusiveMerge that is neither a split join point, nor a labelled error rejoin, nor has in-degree >= 2. Wired into both describe paths beside irreducibleGraphWarnings.", "insight": "The obvious rule (represented == the join point findSplitMergePoints pairs with a split) is WRONG on real code and produces a false positive on ordinary Marketplace microflows. findMergeForSplit needs a join common to ALL branches, so a split where one branch returns pairs with nothing -- yet its merge is still emitted as the continuation after `end split` and survives with its $ID intact (Administration.ManageMyAccount). The in-degree clause is what separates the two. Establish the rule by CORRELATING survival with structure over a corpus rather than reasoning from the describer's code: measuring merge $IDs before and after a round trip over 21 microflows gave in-degree=1 deleted 7 of 7, in-degree>=2 survived 6 of 7. The one exception is a merge lost to flattening in an irreducible graph, which MDL-FLOW01 already owns with a stronger message. Also: count-based comparison cannot tell 'preserved' from 'deleted and recreated' -- compare $IDs. And when scanning describe output for your own warning, grep a string unique to it: MDL-FLOW01's text also contains 'is not represented', which faked a false positive for one round of measurement."}
611611
{"area":"mdl-executor","date":"2026-09-13","symptom":"DESCRIBE renders a microflow whose branches cross as `c1 and c2` when the activity actually runs on `not(c1) or c2` — a program that always logs described as one that never does, with mx check clean","cause":"Nested if/then/else is single-entry/single-exit; a Mendix microflow is an arbitrary digraph. When an inner split's branch lands where an outer split's branch lands, the describer walks the graph as a tree and emits the conjunction of the guards along one path.","file":"mdl/executor/cmd_microflows_normalize.go","fix":"DESCRIBE MICROFLOW ... NORMALIZED (Mode 3): fold the branch guards into one condition via mdl/microflownorm and rewrite a COPY of the graph into the equivalent nested one, then let the existing describer render it. Refuses per-decision when the region holds an activity, a rule-based split, or genuinely interleaved branches.","insight":"Do not write a second describer for a second rendering mode — rewrite the GRAPH and reuse the one describer, or the two drift and every activity renderer is implemented twice. Two verification lessons. (1) A boolean simplifier needs a truth-table equivalence test over generated formulas, not per-rule unit tests: an unsound rewrite produces a pretty WRONG guard, which is the original bug from the other direction. Run it with a rule deliberately broken as the control — mine caught it at the first assignment. (2) Algebra is not behaviour: build the original and the microflow rebuilt from its normalized description side by side and compare return values over the whole input truth table on a real runtime. The rows that matter are the ones the OLD rendering got wrong, so make the fixture's return value distinguish them (a `log` activity is invisible to a test; a `$Result` string is not). Also: the fold leaves the entry merge with in-degree 1, which describe->exec would then silently delete, so splice it out in the transform — otherwise Mode 3's output does not describe the graph its own re-execution builds."}
612612
{"area":"mdl/executor","date":"2026-09-13","symptom":"CATALOG.GRAPH_CYCLES returns 0 rows on a project whose CATALOG.GRAPH_MODULE_COUPLING lists mutual Source/Target module pairs, so a user reads 'no circular dependencies' from a table that was never computed (mendixlabs/mxcli#1060)","cause":"graph_cycles_data is written only by the graph-analysis pass (REFRESH CATALOG COMMUNITIES), while graph_module_coupling is a plain SQL view over refs that any full-mode catalog answers. GRAPH_CYCLES and its four siblings appeared in neither fullOnlyTables nor sourceOnlyTables, so no warning fired; and the recorded build mode is only fast/full/source, so a communities-augmented cache is indistinguishable from a plain full one — which also let a later `refresh catalog full` drop the graph tables silently","file":"`mdl/executor/cmd_catalog.go` (`communitiesOnlyTables`, `warnIfCatalogModeInsufficient`, `tableRequiredMode`, `carryGraphAnalysis`, `cachedCatalogInfo`), `mdl/catalog/catalog.go` (`MetaGraphAnalysis`), `mdl/catalog/builder_graph.go`, `mdl/catalog/builder.go`","insight":"**An empty analytic table is only an answer once something distinguishes 'computed and empty' from 'never computed'.** The mode ladder could not carry that bit: fast/full/source is a LEVEL, and the graph pass is orthogonal to it (it augments any level), so folding it in makes 'source' and 'full+graph' incomparable — it has to be a flag, not a rank. Guard it by MEASUREMENT, not a second hand-written list: run the pass on a synthetic refs graph and diff which tables went from empty to non-empty, then compare that set to the classification map. Shape the fixture so every table fills — two clusters for the community split and the integration surface, one MUTUAL pair for cycles — or the guard silently skips the very table the bug was about","fix":"Record MetaGraphAnalysis/MetaGraphResolution when the pass runs; classify the six tables in communitiesOnlyTables and warn 'requires refresh catalog communities (not run for this catalog)'; report it in SHOW CATALOG STATUS; re-run the pass when a full rebuild replaces a cache that had it"}
613+
{"area":"mdl-executor","date":"2026-09-14","symptom":"DESCRIBE flattens a microflow whose branches cross into nested ifs that mean something else, and warns MDL-FLOW01 'must not be re-executed' instead of describing it","cause":"Nested if/then/else is single-entry/single-exit. A merge reached by branches of two different splits has no place in a tree, so the describer walked past it and emitted the conjunction along one path.","file":"mdl/executor/cmd_microflows_show_crossed.go","fix":"Mode 2: label the shared-suffix entry AND the split's post-dominator, emit `join <label>` at every branch end, then declare each merge as a top-level section after the traversal. MDL-FLOW01 is retired per decision when the description actually declared the merge.","insight":"Three traps, each of which produced plausible-looking output. (1) A crossed merge must be emitted the OPPOSITE way from an error-rejoin merge -- rejoin is DECLARED where the traversal meets it, crossed is JOINED by each branch and declared once afterwards -- so the label alone cannot drive emission; carry a crossed set beside the names. (2) Emit the join BEFORE the visited guard: arriving twice is what 'crossed' MEANS, and the guard silently swallows the second branch's join, leaving that path falling off the end. (3) Retire a warning on what was EMITTED, not on what was labelled. An inheritance split has its own traversal that walks through a labelled merge without emitting a join, so the label goes unused and the reader still gets the nested rendering -- suppressing on the label alone silenced MDL-FLOW01 on Administration.ManageMyAccount, whose description is byte-identical with and without the feature. That forced warnings to be computed AFTER the body instead of before it. Method: keep a baseline binary (git stash -u; build) and diff `describe` over every microflow in a corpus -- the refactor step should be byte-identical (it was, 18 of 18) and the feature step should change only the microflows it targets (2 of 18). Anything else changing is the bug."}

‎cmd/mxcli/syntax/features_microflow.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ func init() {
227227
"-- 2. Crossed branches: an inner split's branch landing where an outer\n" +
228228
"-- split's branch lands. No nesting of IF reproduces that.\n" +
229229
"--\n" +
230+
"-- DESCRIBE emits both forms itself, so these are words you will READ as\n" +
231+
"-- often as write. A crossed graph now describes faithfully by default --\n" +
232+
"-- every branch ends in JOIN and the shared part follows as MERGE sections\n" +
233+
"-- -- and the old MDL-FLOW01 'must not be re-executed' warning is gone with\n" +
234+
"-- it. See microflow.normalized-describe for the opt-in alternative that\n" +
235+
"-- folds the guards instead of naming the merges.\n" +
236+
"--\n" +
230237
"-- Rules, all reported by `mxcli check`:\n" +
231238
"-- MDL-FLOW02 JOIN with no MERGE of that label, or a MERGE nothing joins\n" +
232239
"-- MDL-FLOW03 the same label declared twice\n" +

‎docs/11-proposals/PROPOSAL_structured_microflow_description.md‎

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@ date: 2026-08-20
66

77
# Proposal: Structured description of irreducible microflow graphs
88

9-
**Status:** Partial — Phase 0 (detector, `MDL-FLOW01`, describe-time warning),
10-
**Phase E** (`merge`/`join`, both authoring and DESCRIBE, for error-path rejoins)
11-
and **Mode 3** (`DESCRIBE … NORMALIZED`, opt-in guard folding for recombinable
12-
graphs) are shipped; the prevalence scan that gates the rest is
13-
[measured below](#measured-2026-09-12) and selects Mode 3, which the scan called
14-
the class most irreducible graphs fall into.
15-
16-
**Mode 2 for the *non*-error irreducible graphs remains the open piece.** Mode 3
17-
covers them only when the caller opts in *and* the region folds; the DEFAULT
18-
rendering of a crossed graph is still flattened MDL with the MDL-FLOW01 warning,
19-
and an interleaved graph has no faithful rendering at all. Phases 1–2 otherwise
20-
unscheduled. One
21-
[known limitation](#known-limitation-a-merge-outside-both-described-forms-is-dropped)
22-
is open but now reported: a merge that is neither an error rejoin nor an
23-
`if`/`else` join is dropped by a describe → exec round trip, and DESCRIBE warns.
24-
**Date:** 2026-08-20 (scan: 2026-09-12; Phase E, the runtime measurements and Mode 3: 2026-09-13)
9+
**Status:** Implemented for every class the proposal set out to cover.
10+
Phase 0 (detector, `MDL-FLOW01`), **Phase E** (`merge`/`join` for error-path
11+
rejoins), **Mode 2** (faithful DEFAULT rendering of a crossed graph, using the
12+
same `merge`/`join` vocabulary) and **Mode 3** (`DESCRIBE … NORMALIZED`, opt-in
13+
guard folding) are all shipped.
14+
15+
What remains unfaithful is the **interleaved** class only — branches overlapping
16+
at more than one entry, where nesting requires a duplicated activity or an
17+
invented boolean (Böhm–Jacopini) and no faithful rendering exists. Those keep
18+
MDL-FLOW01, which is now a true statement about them rather than a blanket one.
19+
One [known limitation](#known-limitation-a-merge-outside-both-described-forms-is-dropped)
20+
is open but reported: a merge that is neither an error rejoin, an `if`/`else`
21+
join, nor a crossed entry is dropped by a describe → exec round trip, and
22+
DESCRIBE warns.
23+
**Date:** 2026-08-20 (scan: 2026-09-12; Phase E, the runtime measurements and Mode 3: 2026-09-13; Mode 2: 2026-09-14)
2524

2625
`DESCRIBE MICROFLOW` renders a microflow's control flow as nested `if/then/else`.
2726
That works only for graphs that are *properly nested*. A Mendix microflow is an
@@ -151,7 +150,45 @@ common case.
151150
Properly nested graphs describe exactly as they do today. No change, no new
152151
syntax, no regression in readability for the ~all case.
153152

154-
### Mode 2 — faithful, with named merges (default for irreducible graphs)
153+
### Mode 2 — faithful, with named merges (default for irreducible graphs) — SHIPPED 2026-09-14
154+
155+
Implementation notes, where they differ from the sketch below:
156+
157+
- **Fall-through is permitted in the language but never RELIED ON by the
158+
emitter.** The proposal wanted fall-through into a `merge` banned outright;
159+
Phase E shipped the permissive alternative. Mode 2 gets the same safety by
160+
labelling the split's **post-dominator** as well as the shared entry, so every
161+
branch ends in an explicit `join`. Without that, an empty branch (split2's
162+
false arm in the reporter's graph) falls into the shared merge instead of past
163+
it — silently describing a different graph, which is the exact failure Mode 2
164+
exists to end.
165+
- **A crossed merge is emitted the OPPOSITE way from an error-rejoin merge**, and
166+
the label alone does not say which: a rejoin is *declared* where the traversal
167+
meets it, a crossed merge is *joined* by each branch and declared once
168+
afterwards. Hence `mergeLabels` carries a crossed set beside the names.
169+
- **A `join` is emitted on every arrival, before the `visited` guard.** Arriving
170+
more than once is what "crossed" means; letting the guard swallow the second
171+
branch's join leaves that path falling off the end of the description.
172+
- **MDL-FLOW01 is retired per decision, on the strength of what was EMITTED**,
173+
not of what was labelled. Those differ: an inheritance split has its own
174+
traversal that walks through a labelled merge without emitting a join, so the
175+
label goes unused and the reader still gets the nested rendering. Suppressing
176+
on the label alone retired the warning on `Administration.ManageMyAccount`,
177+
whose description is byte-identical with and without Mode 2 — measured, and
178+
the reason the warnings are now computed after the body rather than before it.
179+
(That microflow's MDL-FLOW01 is a pre-existing false positive in the
180+
classifier — its shared entry is the split's own join, reached because some
181+
branches return early. Left alone here rather than silenced by an unrelated
182+
mechanism.)
183+
- **Regression control**: 16 of 18 microflows in a blank 11.14 app plus
184+
FeedbackModule and Administration describe **byte-identically** to before; the
185+
two that change are the two genuinely crossed ones. Both round-trip with their
186+
merge `$ID`s intact, converge after one step, and a re-exec is elided
187+
(`Unchanged`). Behaviour verified on a **real runtime** across the complete
188+
truth table — the two `$A = false` rows are the ones the old flattening got
189+
wrong (`mdl-examples/bug-tests/923-crossed-branches{,.test}.mdl`).
190+
191+
The original sketch:
155192

156193
A merge becomes a first-class **statement** rather than an inferred annotation,
157194
and branches `join` it. Both words are Mendix's own vocabulary for the concept,
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
-- ============================================================================
2+
-- Mode 2: the DEFAULT describe of a graph whose branches cross
3+
-- ============================================================================
4+
--
5+
-- Same graph as 923-normalized-describe.mdl, kept separate because it pins the
6+
-- other half of #923. Mode 3 (NORMALIZED) is opt-in and rewrites the graph into
7+
-- an equivalent one; Mode 2 is what `describe microflow` does with no modifier
8+
-- at all, and it must reproduce THE graph, not an equivalent one.
9+
--
10+
-- split1 : true -> split2 false -> merge1
11+
-- split2 : true -> merge1 false -> merge2
12+
--
13+
-- BEFORE Mode 2 this described as `if $A then if $B then ...`, i.e. `$A and $B`,
14+
-- carrying an MDL-FLOW01 warning that the description was not equivalent and
15+
-- must not be re-executed. The truth is `not($A) or $B`.
16+
--
17+
-- AFTER, every branch says where it goes:
18+
--
19+
-- if $A then
20+
-- if $B then join shared1; end if;
21+
-- else
22+
-- join shared1;
23+
-- end if;
24+
-- join shared2;
25+
-- merge shared1; <activity> join shared2;
26+
-- merge shared2; <tail>
27+
--
28+
-- and the MDL-FLOW01 warning is GONE, because it is no longer true.
29+
--
30+
-- Note the `join shared2` after `end if`: that is split2's EMPTY false arm,
31+
-- which is why the post-dominator is labelled too. Without it the empty arm
32+
-- would fall through into `merge shared1` and describe a different graph.
33+
--
34+
-- Run it:
35+
-- mxcli exec mdl-examples/bug-tests/923-crossed-branches.mdl -p app.mpr
36+
-- mxcli -p app.mpr -c "describe microflow Mode3.MF_Orig" -- faithful, no warning
37+
-- mxcli test mdl-examples/bug-tests/923-crossed-branches.test.mdl -p app.mpr --local
38+
--
39+
-- Measured on Mendix 11.14.0: both merge $IDs survive the round trip, the
40+
-- description is a fixed point, and a re-exec of it is elided (Unchanged).
41+
42+
CREATE MODULE Mode3;
43+
/
44+
CREATE OR REPLACE MICROFLOW Mode3.MF_Orig (A: Boolean, B: Boolean) RETURNS String
45+
BEGIN
46+
DECLARE $Result String = 'skipped';
47+
IF $A THEN
48+
IF $B THEN
49+
JOIN m1;
50+
ELSE
51+
JOIN m2;
52+
END IF;
53+
ELSE
54+
JOIN m1;
55+
END IF;
56+
MERGE m1;
57+
SET $Result = 'ran';
58+
JOIN m2;
59+
MERGE m2;
60+
RETURN $Result;
61+
END;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Mode 2 must preserve BEHAVIOUR. MF_Orig is the #923 crossed graph; MF_Mode2 is
3+
* what the DEFAULT `describe microflow` emitted for it, executed back — so this
4+
* compares the graph against its own faithful description.
5+
*
6+
* Before Mode 2 that description was `$A and $B`, so the two A=false rows are
7+
* the ones the old flattening got wrong. They are the test.
8+
*
9+
* @test A=true B=true
10+
* @expect $orig = 'ran' and $m2 = 'ran'
11+
*/
12+
$orig = call microflow Mode3.MF_Orig(A = true, B = true);
13+
$m2 = call microflow Mode3.MF_Mode2(A = true, B = true);
14+
/
15+
16+
/**
17+
* @test A=true B=false
18+
* @expect $orig = 'skipped' and $m2 = 'skipped'
19+
*/
20+
$orig = call microflow Mode3.MF_Orig(A = true, B = false);
21+
$m2 = call microflow Mode3.MF_Mode2(A = true, B = false);
22+
/
23+
24+
/**
25+
* @test A=false B=true (old flattening said skipped)
26+
* @expect $orig = 'ran' and $m2 = 'ran'
27+
*/
28+
$orig = call microflow Mode3.MF_Orig(A = false, B = true);
29+
$m2 = call microflow Mode3.MF_Mode2(A = false, B = true);
30+
/
31+
32+
/**
33+
* @test A=false B=false (old flattening said skipped)
34+
* @expect $orig = 'ran' and $m2 = 'ran'
35+
*/
36+
$orig = call microflow Mode3.MF_Orig(A = false, B = false);
37+
$m2 = call microflow Mode3.MF_Mode2(A = false, B = false);
38+
/

‎mdl/executor/cmd_microflows_irreducible_warning_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func reporterCollection() *microflows.MicroflowObjectCollection {
5353
}
5454

5555
func TestIrreducibleGraphWarnings_FlagsTheReporterGraph(t *testing.T) {
56-
got := irreducibleGraphWarnings(reporterCollection())
56+
got := irreducibleGraphWarnings(reporterCollection(), nil)
5757
if len(got) != 1 {
5858
t.Fatalf("want 1 warning, got %d: %v", len(got), got)
5959
}
@@ -102,10 +102,10 @@ func TestIrreducibleGraphWarnings_SilentOnNestedGraphs(t *testing.T) {
102102
},
103103
}
104104

105-
if got := irreducibleGraphWarnings(ifElse); len(got) != 0 {
105+
if got := irreducibleGraphWarnings(ifElse, nil); len(got) != 0 {
106106
t.Errorf("plain if/else warned: %v", got)
107107
}
108-
if got := irreducibleGraphWarnings(nil); len(got) != 0 {
108+
if got := irreducibleGraphWarnings(nil, nil); len(got) != 0 {
109109
t.Errorf("nil collection warned: %v", got)
110110
}
111111
}

0 commit comments

Comments
 (0)