Skip to content

Commit 2d35684

Browse files
committed
feat(catalog): answer the module-cycle question, and make the edge scope visible
#1060 reported GRAPH_CYCLES empty while GRAPH_MODULE_COUPLING listed the same module pair in both directions. The previous commit made "never computed" say so. This one addresses the case where the pass HAS run and the answer is still not the one asked for. Two separate reasons the tables disagreed, both now addressed. **Granularity.** GRAPH_CYCLES is SCCs of the ASSET graph. Modules A and B reference each other through DIFFERENT documents, which form no cycle among themselves — the ordinary shape of a module cycle — so the asset table is correctly empty for a genuinely circular pair. There was no module-level cycle table at all; GRAPH_MODULE_DEPENDENCIES exposes the edges and nothing computed SCCs over them. CATALOG.GRAPH_MODULE_CYCLES is not a rollup of GRAPH_CYCLES but its own Tarjan run over the module graph. A row carries RefKinds: the kinds on that module's edges INTO THE REST OF THE CYCLE, so a reader is sent at the reference keeping it alive rather than everything the module points at. module_cycles() joins the Starlark builtins, so "no circular module dependencies" is enforceable. **Scope.** graphRefKinds admits ten structural kinds and drops the navigational ones so they do not blur clustering; GRAPH_MODULE_COUPLING reads every kind straight off refs. On ako/TestApp that is 110 of 316 edges — a third of the graph — with nothing recording the fact. GRAPH_MODULE_CYCLES therefore uses every kind, matching the table it is read beside. That is the load-bearing choice: on a blank Mendix app Administration -> Atlas_Core is a `layout` edge and nothing else, so a module-cycle table built on the structural subset would ship green and still answer "none" for exactly the pair that gets reported. And CATALOG.GRAPH_ANALYSIS_SCOPE makes the split answerable from SQL — one row per kind, its edge count, and whether it reaches the asset graph — with the IN list generated from graphRefKinds so the view describing the filter cannot drift from it. Measured end to end on a 16-module 11.14 app. GRAPH_ANALYSIS_SCOPE reproduces the 110/316 split exactly. TestApp has no mutual module pair, so GRAPH_MODULE_CYCLES is empty — the negative control; injecting one reverse `show_page` edge into refs produces Administration/Atlas_Core at size 2, naming `layout` one way and `show_page` the other, while GRAPH_CYCLES stays at 0 throughout. That contrast is the report. One bug the tests caught before it shipped: buildModuleCycles first sat after the `len(edges) == 0` early return, which is computed on the STRUCTURAL edge set — so a project whose only cross-module references are navigational got nothing, which is the reported case exactly. The test with `layout`-only edges fails without the reordering. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JXnEgoc2NQP1Y2TWMCMXC4
1 parent 7e7bfd7 commit 2d35684

14 files changed

Lines changed: 565 additions & 25 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@
6161
{"area": "mdl/linter", "date": "2026-09-07", "symptom": "`mxcli lint` CONV010 reported \"ACT_ microflow 'X' contains 'ExclusiveMerge' activity\" on every ACT_ microflow containing an `if` — 122 times on one project, and on a minimal microflow whose ONLY violation was the merge (ako/CapTrackV4 R11).", "cause": "ALLOWED_ACTIVITY_TYPES in conv010_act_microflow_content.star listed ExclusiveSplit and not ExclusiveMerge. An `if` emits both, so the rule permitted the branch and flagged the join it necessarily creates. Fixed by adding ExclusiveMerge, with a test that asks the catalog's own labeller (getMicroflowObjectType) for the two names rather than hardcoding them.", "file": "`.claude/lint-rules/conv010_act_microflow_content.star`; tests `mdl/catalog/lint_rule_vocabulary_test.go`", "insight": "The codebase had already answered this in the other direction and the rule disagreed with it: countMicroflowActivities in mdl/catalog excludes ExclusiveMerge as structural, with a comment saying so. When a lint rule's vocabulary looks wrong, check whether another part of the same package has already classified the same thing. The control matters as much as the fix — LoopedActivity and InheritanceSplit must stay flagged, or a 'widen the list' fix passes the new test and guts the rule. Note also that `mxcli lint` loads Starlark rules ONLY from the project's own `.claude/lint-rules/`, never the embed, so a fixed built-in reaches an existing project only when it re-runs `mxcli init` — which is why a project can keep reporting a rule bug that is already fixed upstream."}
6262
{"area": "mdl/catalog", "date": "2026-09-07", "symptom": "A microflow wired as the project's AfterStartupMicroflow reported \"no callers found\" and \"no references found\", and `mxcli lint` QUAL004 said \"is not called from anywhere. Remove if unused.\" Dropping it left a dangling name that `mx check` also missed; only the runtime refused to start (ako/CapTrackV4 049, R13).", "cause": "The runtime calls these, so nothing in the model does, and CATALOG.REFS had no edge kind for a project setting. Added RefKindSettings and extractProjectSettingsRefs, emitting one `settings` edge per setting that names a microflow (AfterStartupMicroflow, BeforeShutdownMicroflow, HealthCheckMicroflow), with the SETTING as the edge's source; added \"settings\" to QUAL004's MICROFLOW_ENTRY_KINDS.", "file": "`mdl/catalog/builder_references.go` (RefKindSettings, extractProjectSettingsRefs, projectSettingsMicroflowRefs); `.claude/lint-rules/orphaned_elements.star`; tests `mdl/catalog/lint_rule_vocabulary_test.go`", "insight": "Same class as the scheduled-event edge, and the rule's own comment had already named the failure mode — \"a kind missing here turns a live document into a false 'not called from anywhere' finding\" — which makes the list of entry kinds worth auditing whenever a new way to invoke a microflow is added. The dangerous half is not the missing reference but the lint rule built on it: QUAL004 does not merely fail to notice, it actively advises deleting the microflow whose deletion breaks the build. The settings list is a literal rather than reflection over ModelSettings, because most of that struct is strings that are not microflow names and a wrong entry would invent an edge rather than miss one."}
6363
{"area": "mdl/catalog", "date": "2026-09-09", "symptom": "A new CATALOG view is queryable by name but absent from `show catalog tables`, so nobody can discover it — caught by TestTables_CoversAllViews, not by any query", "cause": "Adding a view to tables.go creates it in SQLite, but Catalog.Tables() is a separate hand-maintained list and is what SHOW CATALOG TABLES prints. The two are not derived from each other", "file": "`mdl/catalog/catalog.go` (Tables), `mdl/catalog/tables.go`", "insight": "Two hand-maintained lists of the same thing, with a guard test comparing them — the guard is the only reason this is a five-second fix instead of a view nobody finds for months. When adding a catalog view, expect to touch both. The general shape recurs in this codebase (stmtCreateInfo vs projectNameSets.setFor under-reported conflicts for the same reason), so the question to ask of any list is what compares it to its twin", "refs": ["ako/mxcli#413"]}
64+
{"area":"mdl/catalog","date":"2026-09-13","symptom":"A user asks 'are there circular dependencies between my modules?', reads CATALOG.GRAPH_CYCLES, gets 0 rows, and concludes there are none — while CATALOG.GRAPH_MODULE_COUPLING lists the same module pair in both directions (mendixlabs/mxcli#1060)","cause":"GRAPH_CYCLES is SCCs of the ASSET graph. Modules A and B reference each other through DIFFERENT documents, which form no cycle among themselves, so the asset table is correctly empty for a genuinely circular module pair. Compounded by scope: the asset graph admits only graphRefKinds, while coupling counts every kind — 110 of 316 edges on a stock 11.14 app, and Administration -> Atlas_Core there is `layout`-only","file":"`mdl/catalog/builder_graph.go` (`buildModuleCycles`, `loadModuleEdges`, `graphRefKindsSQL`), `mdl/catalog/tables.go` (`graph_module_cycles_data`, `graph_analysis_scope`), `mdl/linter/starlark_graph.go` (`module_cycles()`)","insight":"**When a report says two tables disagree, check whether they answer different questions before checking whether one is broken — then make the difference queryable.** Tarjan was fine; the granularity and the edge filter were both undocumented and invisible from SQL. Two traps in the implementation: (1) the new module pass sat after `if len(edges) == 0 { return }` on the STRUCTURAL edge set, so a project whose only cross-module refs are navigational — the reported case exactly — got nothing; a test with only `layout` edges caught it. (2) A module-cycle table built on the structural subset would have shipped green and still answered 'none' for the reported pair, so the edge set has to match graph_module_coupling, the table it is read beside. Generate the scope view's IN list from graphRefKinds rather than restating it, or the documentation of the filter drifts from the filter","fix":"Add graph_module_cycles (module SCCs, all kinds, with a RefKinds column naming the edges inside the cycle) and graph_analysis_scope (per-kind edge counts + InAssetGraph), plus a module_cycles() Starlark builtin"}

‎.claude/skills/mendix/graph-analysis/SKILL.md‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,37 @@ ORDER BY CycleSize DESC, CycleId
242242
**Size 2**: mutual reference between two elements — e.g. workflow A calls workflow B which triggers workflow A. Investigate before assuming it's intentional; these can cause infinite loops at runtime.
243243
**Size 3+**: a dependency ring — must be broken before the module can be split or properly layered.
244244

245+
### Module cycles are a different query, not a rollup
246+
247+
`GRAPH_CYCLES` is **document**-level. Two modules referencing each other almost
248+
never means two documents do — Administration calls something in Atlas_Core from
249+
one page while Atlas_Core reaches back from another — so `GRAPH_CYCLES` is
250+
correctly empty for a genuinely circular pair of modules. Reading it as "no
251+
circular dependencies" was mendixlabs/mxcli#1060. Ask the module question of the
252+
module table:
253+
254+
```sql
255+
SELECT ModuleName, CycleSize, RefKinds
256+
FROM CATALOG.GRAPH_MODULE_CYCLES
257+
ORDER BY CycleSize DESC, ModuleName
258+
```
259+
260+
`RefKinds` names the kinds on that module's edges **into the rest of the cycle** —
261+
the references to go and break, as opposed to everything else the module points at.
262+
263+
The two also read different edges. `GRAPH_MODULE_CYCLES` uses every reference
264+
kind, matching `GRAPH_MODULE_COUPLING`; the computed asset pass
265+
(`GRAPH_CYCLES`/`COMMUNITIES`/`GRAPH_LAYERS`/`GRAPH_CENTRALITY`) is restricted to
266+
the structural kinds so navigational edges do not blur the clustering. On a stock
267+
app that is about a third of the edges. `GRAPH_ANALYSIS_SCOPE` reports the split
268+
per kind, which is the query to run when coupling shows an edge and the computed
269+
tables act as though it were not there:
270+
271+
```sql
272+
SELECT RefKind, Edges, InAssetGraph FROM CATALOG.GRAPH_ANALYSIS_SCOPE
273+
ORDER BY InAssetGraph, Edges DESC
274+
```
275+
245276
---
246277

247278
## Use Case 8: Monolith-to-Multi-App Planning
@@ -303,7 +334,9 @@ Elements at the same layer can be parallelised safely. A microflow calling somet
303334
| Which modules are tightly coupled? | `GRAPH_MODULE_COUPLING` |
304335
| Is module M self-contained? | `GRAPH_MODULE_COHESION` |
305336
| What is unused / dead? | `GRAPH_DEAD_ASSETS` |
306-
| Are there circular dependencies? | `GRAPH_CYCLES` |
337+
| Are there circular dependencies between **documents**? | `GRAPH_CYCLES` |
338+
| Are there circular dependencies between **modules**? | `GRAPH_MODULE_CYCLES` |
339+
| Why isn't an edge I see in coupling affecting the cycles/layers? | `GRAPH_ANALYSIS_SCOPE` |
307340
| Which entities are hotspots? | `GRAPH_ENTITY_HOTSPOTS` |
308341
| What contracts would a split require? | `GRAPH_INTEGRATION_SURFACE` |
309342
| What reference types cross module boundaries? | `GRAPH_MODULE_DEPENDENCIES` |

‎CHANGELOG.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- **`CATALOG.GRAPH_MODULE_CYCLES` — the modules that depend on each other** (mendixlabs/mxcli#1060), plus a `module_cycles()` Starlark builtin for enforcing a no-circular-modules policy. Not a rollup of `GRAPH_CYCLES`: modules reference each other through documents that need form no cycle themselves, which is the ordinary shape and why the document-level table is legitimately empty for a genuinely tangled pair. Computed over **every** reference kind, matching `GRAPH_MODULE_COUPLING` — the table it is read beside — rather than the structural subset the clustering uses; on a blank Mendix app `Administration → Atlas_Core` is a `layout` edge and nothing else, so a module-cycle table on the structural subset would answer "none" for exactly the pair that gets reported. Each row carries `RefKinds`: the kinds on that module's edges **into the rest of the cycle**, not everything it points at.
12+
13+
- **`CATALOG.GRAPH_ANALYSIS_SCOPE` — which reference kinds reach the computed graph.** The two graph families disagree by construction and there was no way to see it from SQL: `GRAPH_MODULE_COUPLING` and friends read every kind straight off `refs`, while the computed pass (communities, cycles, layers, centrality) is restricted to the structural kinds. On a stock 11.14 app that is 110 of 316 edges. One row per kind with its edge count and whether it is in the asset graph; the `IN` list is generated from the filter itself, so the view cannot drift from what it describes.
14+
915
### Fixed
1016

17+
- **An empty graph-analysis table could not be told apart from one that was never computed** (mendixlabs/mxcli#1060). `CATALOG.GRAPH_CYCLES` answered `0 rows` on a project whose `CATALOG.GRAPH_MODULE_COUPLING` listed mutual module pairs, so it read as "no circular dependencies". The two are built by different things: coupling is a plain view over `refs` that any full catalog answers, while the cycles/communities/layers/centrality tables are written only by `REFRESH CATALOG COMMUNITIES` — and those six were in neither `fullOnlyTables` nor `sourceOnlyTables`, so nothing warned.
18+
19+
The mode ladder could not carry the distinction. fast/full/source is a *level*, each containing the one below, which is what lets a rank comparison decide everything; the graph pass is orthogonal, augmenting whichever level is cached. It is now recorded as a flag plus the resolution it ran at. A query against one of the six says `requires refresh catalog communities (not run for this catalog)`; `SHOW CATALOG STATUS` reports `Graph analysis: ✓/✗` separately from the build mode; `DESCRIBE CATALOG.GRAPH_CYCLES` names the command that populates it.
20+
21+
A full rebuild also dropped the graph tables silently while the recorded mode stayed `full` — measured on a 16-module app: 150 community rows before `refresh catalog full force`, 0 after. It now re-runs the pass at the same resolution instead. A fast build is deliberately not promoted: it never overwrites a full cache, so it has nothing to preserve.
22+
1123
- **A parallel split written from MDL ran every path empty** (reported in ako/view-entity-examples FINDINGS §6). `PARALLEL SPLIT … PATH 1 { … } PATH 2 { … }` passed `mxcli check`, built at 0 errors and round-tripped through `describe`, and at runtime each path ran from the split straight to its end: the activities inside never executed and left **no activity record**. Every gate said the workflow was fine, including the one that reads the model back.
1224

1325
Mendix stores an `EndOfParallelSplitPathActivity` as the last activity of every path, and its engine executes a path up to that marker. mxcli wrote paths without one — on both engines, and through `ALTER WORKFLOW … INSERT PATH` on both mutators — so the runtime synthesised an end ahead of the path's contents. Measured on Mendix 11.14.0 with the marker as the only variable between two instances of the same workflow, reading `system$workflowactivity`: without it neither path's call-microflow produced a record; with it both finished. The shipped fix was then booted on its own and the same query shows both paths' activities `Finished`, plus an end record for an empty path.

‎docs-site/src/tools/catalog-tables.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,18 @@ until it runs and a query against one says so rather than returning `0 rows`.
254254
See **[Graph Analysis](graph-analysis.md)** for the full reference and the
255255
`mxcli graph-report` command.
256256

257+
Cycles come in two flavours, because they are two questions:
258+
`CATALOG.GRAPH_CYCLES` for tangled **documents** and `CATALOG.GRAPH_MODULE_CYCLES`
259+
for tangled **modules** — the second is not a rollup of the first, since modules
260+
reference each other through documents that need form no cycle themselves.
261+
`CATALOG.GRAPH_ANALYSIS_SCOPE` reports which reference kinds reach the computed
262+
asset graph, which is what to check when a `graph_module_coupling` edge seems to
263+
have no effect on cycles or layers.
264+
257265
```sql
258266
select * from CATALOG.graph_god_nodes order by Degree desc limit 20;
259267
select * from CATALOG.graph_module_coupling order by Edges desc;
268+
select * from CATALOG.graph_module_cycles order by CycleSize desc;
260269
show communities;
261270
```
262271

‎docs-site/src/tools/graph-analysis.md‎

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ populates these catalog objects (and fills the `PageRank`/`Betweenness` columns
5555
|--------|----------|
5656
| `CATALOG.communities` | community id per asset |
5757
| `CATALOG.community_summary` | per-community size, dominant-module label, members |
58-
| `CATALOG.graph_cycles` | assets in a dependency cycle |
58+
| `CATALOG.graph_cycles` | **assets** in a dependency cycle (structural kinds only) |
59+
| `CATALOG.graph_module_cycles` | **modules** in a dependency cycle (every kind) |
5960
| `CATALOG.graph_layers` | topological layer sequence number per asset |
6061
| `CATALOG.graph_centrality` | PageRank / betweenness per asset |
6162
| `CATALOG.graph_module_dependencies` | directed module→module edges (kind + count) |
@@ -64,6 +65,48 @@ populates these catalog objects (and fills the `PageRank`/`Betweenness` columns
6465
The `resolution` knob selects granularity: high γ → fine **candidate modules**;
6566
low γ → coarse **candidate apps**.
6667

68+
### Two cycle tables, two questions
69+
70+
`graph_cycles` and `graph_module_cycles` are not a detail view and a rollup of
71+
each other. Modules A and B are in a cycle when A references B *and* B references
72+
A — through any documents, which need form no cycle between themselves. That is
73+
the ordinary shape, so `graph_cycles` is legitimately empty for a genuinely
74+
tangled pair of modules. Reading it as "no circular dependencies" while
75+
`graph_module_coupling` listed both directions is
76+
[mendixlabs/mxcli#1060](https://github.com/mendixlabs/mxcli/issues/1060).
77+
78+
They also read different edges, on purpose:
79+
80+
| | edge set | asks |
81+
|---|---|---|
82+
| `graph_cycles` | structural kinds only | which documents are tangled together |
83+
| `graph_module_cycles` | every kind, like `graph_module_coupling` | which modules cannot be extracted independently |
84+
85+
The asset graph excludes navigational kinds (`layout`, `show_page`,
86+
`datasource`, `widget`, `sync`, …) because they blur community and layer
87+
clustering. A module cycle is a different claim: a page bound to a layout in
88+
another module really is a dependency of that module, and on a blank Mendix app
89+
`Administration → Atlas_Core` is a `layout` edge and nothing else. A module-cycle
90+
table on the structural subset would answer "none" for exactly the pair that gets
91+
reported.
92+
93+
`graph_analysis_scope` makes the split answerable instead of buried in source —
94+
one row per reference kind with its edge count and whether it reaches the asset
95+
graph:
96+
97+
```sql
98+
select * from CATALOG.graph_analysis_scope order by InAssetGraph, Edges desc;
99+
```
100+
101+
On a stock 11.14 app that is 110 of 316 edges outside it. Each
102+
`graph_module_cycles` row also carries `RefKinds` — the kinds on that module's
103+
edges *into the rest of the cycle*, so you know which reference to go and break.
104+
105+
```sql
106+
select ModuleName, CycleSize, RefKinds from CATALOG.graph_module_cycles
107+
order by CycleSize desc, ModuleName;
108+
```
109+
67110
### If one of these is empty
68111

69112
Empty means one of two very different things, and they used to look identical.
@@ -104,7 +147,8 @@ show community members of Sales.Order -- its co-clustered assets
104147
**Spaghetti → layered / modular app.**
105148

106149
```sql
107-
select * from CATALOG.graph_cycles; -- the tangles to break
150+
select * from CATALOG.graph_cycles; -- tangled documents
151+
select * from CATALOG.graph_module_cycles; -- tangled modules
108152
select Layer, AssetName from CATALOG.graph_layers
109153
order by Layer; -- dependency depth
110154
show communities; -- cleaner module groupings
@@ -135,7 +179,7 @@ mxcli ships the *facts*, not an opinion. Teams enforce their own layering /
135179
allowed-dependency / no-cycle / coupling-budget policies via Starlark lint rules,
136180
using these builtins (which read the graph tables):
137181

138-
`community_of`, `layer_of`, `cycles`, `module_dependencies`, `centrality`,
182+
`community_of`, `layer_of`, `cycles`, `module_cycles`, `module_dependencies`, `centrality`,
139183
`god_nodes`, `integration_surface`, `refs_from`.
140184

141185
```python

0 commit comments

Comments
 (0)