Skip to content

Commit 7e7bfd7

Browse files
committed
fix(catalog): tell an un-run graph pass apart from a graph with nothing in it
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" from a table that had never been computed (#1060). The two tables are built by different things. graph_module_coupling is a plain SQL view over refs, so any full-mode catalog answers it. graph_cycles_data is written only by the graph-analysis pass, which runs only from REFRESH CATALOG COMMUNITIES — and GRAPH_CYCLES, COMMUNITIES, COMMUNITY_SUMMARY, GRAPH_LAYERS, GRAPH_CENTRALITY and GRAPH_INTEGRATION_SURFACE were the only graph tables in neither fullOnlyTables nor sourceOnlyTables, so nothing warned. Measured on ako/TestApp: after `refresh catalog communities`, communities/layers/ centrality hold 150 rows each; after one `refresh catalog full force` all three hold 0, with the recorded mode still reading "full". The mode ladder cannot carry this bit. fast/full/source is a level — each contains the one below, which is what makes a rank comparison decide everything — and the graph pass is orthogonal to it, augmenting whichever level is cached. Folding it in would make "source" and "full+graph" incomparable. So it is recorded as a flag (MetaGraphAnalysis) plus the resolution it ran at. With that bit available: - a query against one of the six says "requires refresh catalog communities (not run for this catalog)" instead of returning 0 rows; - SHOW CATALOG STATUS reports "Graph analysis: ✓/✗" separately from the build mode, because it IS separate; - DESCRIBE CATALOG.GRAPH_CYCLES names the command that populates it; - a full rebuild over a catalog that had the pass re-runs it at the same resolution rather than dropping it — the #1081 shape, where a build silently replaces something richer than itself. A fast build is deliberately NOT promoted: it never overwrites a full cache, so it has nothing to preserve. The drift guard is a measurement, not a second hand-written list that would drift in lockstep with the first: run the pass over a synthetic refs graph and diff which tables went from empty to non-empty, then compare that set to the classification map. The fixture is shaped so every one of them fills — two clusters for the community split and the cross-community edge, one mutual pair for cycles — since otherwise the guard would skip the very table this was reported about. Removing graph_cycles from the map fails it with exactly the original bug. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JXnEgoc2NQP1Y2TWMCMXC4
1 parent 1a18bfe commit 7e7bfd7

9 files changed

Lines changed: 400 additions & 16 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,3 +607,4 @@
607607
{"area": "mdl/executor", "date": "2026-09-13", "symptom": "A workflow with `boundary event timer '\u2026'` (no interrupting / non interrupting) passes check and builds at 0 errors; the runtime then fails to start: `Class 'Workflows$TimerBoundaryEvent' could not be found`", "cause": "The bare form maps to `Workflows$TimerBoundaryEvent`, which exists in no cached 11.x runtime (only Interrupting/NonInterruptingTimerBoundaryEvent). mxbuild tolerates the unknown type. It was the documented syntax example", "file": "`mdl/executor/validate_workflow_refs.go` (`bareTimerBoundaryEventErrors`, MDL-WF07), `cmd/mxcli/syntax/features_workflow.go`", "insight": "**A type mxbuild accepts is not a type the runtime has.** Found only because a verification boot of an unrelated fix loaded it. When a grammar has a default branch that maps to a storage type, check that type against the runtime's class list, not against `mx check`", "fix": "Refuse the bare form on 11+ at check and exec, CREATE and every ALTER op that can carry a boundary event; update syntax help, skill table and the ako/mxcli#415 bug-test script to name the kind"}
608608
{"area": "mdl/executor", "date": "2026-09-13", "symptom": "A view entity whose association column is also declared as an attribute (`MeterRef: Trends.Meter` or `MeterRef: Trends.Meter.ID` beside `select m.ID as MeterRef`) passes `mxcli check`; `check -p` says 'OQL select has 1 columns but 2 attributes declared'; exec writes `Enumeration(Trends.Meter)` and mx check reports CE1613, or throws 'An error occurred when trying to set the Enumeration property' for the three-part form", "cause": "A bare qualified name parses as TypeEnumeration (the entity/enum ambiguity), and execCreateViewEntity converted it with convertDataType without asking what it names. The alias-to-attribute alignment skips association columns, so the declared attribute had no column and was compared against the next one", "file": "`mdl/executor/oql_view_associations.go` (`ValidateViewAttributeDeclarations` MDL080, `viewAttributeEntityTypeErrors`), `mdl/executor/cmd_entities.go` (`execCreateViewEntity`), `mdl/executor/validate.go`, `mdl/executor/validate_program.go`, `cmd/mxcli/lsp_diagnostics.go`", "insight": "**The TypeEnumeration/TypeEntity ambiguity has a consumer wherever a data type becomes a stored type, and view entity attributes were one nobody had listed.** Split the refusal by what it needs: an association column's alias and a three-part name are decidable from the script, so they belong in the no-project phase that exec's pre-check also runs; entity-vs-enum needs the project, so it goes in check -p AND the handler, because exec --no-check skips both phases. Verify the handler refusal by counting changed files, not by the error text", "fix": "Refuse in ValidateProgram/LSP (MDL080) and at the top of execCreateViewEntity before any backend call; report an attribute once"}
609609
{"area": "mdl/executor", "date": "2026-09-13", "symptom": "Three new MDL-WIDGET27 tests passed locally and failed in CI on the same commit: two reported the fallback remedy (\"move the entries into the widget body as container blocks\") instead of naming the container keyword, and the third found 0 violations where it wanted 1", "cause": "The tests resolved the widget through `LoadWidgetRegistry(fixtureProject(t))`, which reads `.def.json` files from `testdata/expr-checker/.mxcli/widgets/`. That directory is GITIGNORED — the definitions are derived, not tracked — so they exist for any developer who has ever run `mxcli widget docs` against the fixture (I generated them earlier in the same session, while investigating) and never exist on the runner. With no definition, `containerKeyword` returns \"\" and the two definition-dependent branches degrade exactly as designed: fallback wording, and silence for the scalar case", "file": "`mdl/executor/validate_widget_object_property_test.go` (`fixtureProjectWithDefs`)", "insight": "**A gitignored fixture makes a test environment-dependent in the one direction nobody checks** — the developer's tree is a superset of the runner's, so the test is green exactly where it is not being tested. The fix is to DERIVE the artifact from tracked inputs inside the test (`RefreshWidgetDefinitions` over the fixture's tracked `.mpk` files, into a temp copy, after removing any `.mxcli` the developer's tree carries), so local and CI see identical inputs. Reproduce by moving the gitignored directory aside before believing any diagnosis. **The sibling lesson is why this was not caught by the existing suite**: #999's test asserted `strings.Contains(msg, \"attribute\")` on a widget whose property is named `attributes`, so the property name alone satisfied it and the assertion passed with NO definition loaded — a substring assertion whose needle is a substring of the data it is meant to distinguish from proves nothing. Tightened to the remedy shape (`` `attribute <name> (…)` blocks ``) and verified with the derivation stubbed: all four then fail, where before only the three new ones did", "refs": []}
610+
{"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"}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ Two separate commands are needed. The full catalog must exist before community d
3737
| `REFRESH CATALOG FULL` | `GRAPH_GOD_NODES`, `GRAPH_MODULE_COUPLING`, `GRAPH_MODULE_COHESION`, `GRAPH_DEAD_ASSETS`, `GRAPH_ENTITY_HOTSPOTS`, `GRAPH_MODULE_DEPENDENCIES`, `GRAPH_REFKIND_DISTRIBUTION` |
3838
| `REFRESH CATALOG COMMUNITIES` | `COMMUNITIES`, `COMMUNITY_SUMMARY`, `GRAPH_CYCLES`, `GRAPH_LAYERS`, `GRAPH_CENTRALITY`, `GRAPH_INTEGRATION_SURFACE` |
3939

40+
**An empty table from the second row is ambiguous unless you check.** Step 2 is
41+
not a build mode — it augments whatever the catalog is, so `Build mode: full`
42+
says nothing about whether it ran, and before mendixlabs/mxcli#1060 an un-run
43+
pass and a genuinely cycle-free project produced the same `0 rows`. A query now
44+
warns `requires refresh catalog communities (not run for this catalog)` when the
45+
pass is missing, and `SHOW CATALOG STATUS` has a `Graph analysis:` line. **No
46+
warning plus no rows is a real answer**; treat anything else as "not computed
47+
yet", not as "clean".
48+
4049
`REFRESH CATALOG COMMUNITIES` with a resolution modifier:
4150
- `REFRESH CATALOG COMMUNITIES` — default resolution (balanced granularity)
4251
- `REFRESH CATALOG COMMUNITIES resolution 0.6` — coarser clusters (fewer, larger communities; good for monolith-to-multi-app planning)

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,10 @@ The dependency graph (`CATALOG.REFS`, full refresh) is analysed by a family of
249249
`graph_*` views and tables — god nodes, module coupling/cohesion, dead documents,
250250
communities, cycles, layers, centrality, and the integration surface. The
251251
community/cycle/layer/centrality tables are populated by `REFRESH CATALOG
252-
COMMUNITIES`. See **[Graph Analysis](graph-analysis.md)** for the full reference
253-
and the `mxcli graph-report` command.
252+
COMMUNITIES` — a pass, not a build mode, so a full-mode catalog has them empty
253+
until it runs and a query against one says so rather than returning `0 rows`.
254+
See **[Graph Analysis](graph-analysis.md)** for the full reference and the
255+
`mxcli graph-report` command.
254256

255257
```sql
256258
select * from CATALOG.graph_god_nodes order by Degree desc limit 20;

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,33 @@ populates these catalog objects (and fills the `PageRank`/`Betweenness` columns
6464
The `resolution` knob selects granularity: high γ → fine **candidate modules**;
6565
low γ → coarse **candidate apps**.
6666

67+
### If one of these is empty
68+
69+
Empty means one of two very different things, and they used to look identical.
70+
The tables above are filled by the pass, not by a build mode — so a catalog built
71+
with `refresh catalog full` has all of them empty while `graph_module_coupling`,
72+
a plain view over `refs`, answers normally. That asymmetry was
73+
[mendixlabs/mxcli#1060](https://github.com/mendixlabs/mxcli/issues/1060).
74+
75+
A query now says which case you are in:
76+
77+
```
78+
Warning: CATALOG.GRAPH_CYCLES requires refresh catalog communities (not run for this catalog)
79+
```
80+
81+
No warning and no rows means the pass ran and genuinely found nothing.
82+
`show catalog status` reports the same thing up front:
83+
84+
```
85+
Graph analysis: ✓ Available (resolution 1)
86+
Graph analysis: ✗ Not run (use refresh catalog communities)
87+
```
88+
89+
The pass is **not** a build mode — it augments whatever mode is cached, so
90+
`Build mode: full` says nothing about it. A later `refresh catalog full` used to
91+
drop these tables silently; it now re-runs the pass at the same resolution, so the
92+
graph survives a rebuild. To drop back, delete `.mxcli/catalog.db` and refresh.
93+
6794
### SHOW commands
6895

6996
```sql

‎mdl/catalog/builder.go‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package catalog
44

55
import (
66
"fmt"
7+
"strconv"
78
"strings"
89
"time"
910

@@ -600,6 +601,19 @@ func (b *Builder) Build(progress ProgressFunc) error {
600601
return fmt.Errorf("failed to commit transaction: %w", err)
601602
}
602603
tx = nil // Prevent rollback in defer
604+
605+
// Same flag AddGraphAnalysis writes, for the build-it-in-one-pass route.
606+
// Both routes must set it or an empty cycles table stays ambiguous down
607+
// whichever one the caller took (mendixlabs/mxcli#1060).
608+
if b.communitiesMode {
609+
if err := b.catalog.SetMeta(MetaGraphAnalysis, time.Now().Format(time.RFC3339)); err != nil {
610+
return err
611+
}
612+
if err := b.catalog.SetMeta(MetaGraphResolution,
613+
strconv.FormatFloat(effectiveResolution(b.resolution), 'g', -1, 64)); err != nil {
614+
return err
615+
}
616+
}
603617
b.tx = nil
604618

605619
return nil

‎mdl/catalog/builder_graph.go‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ package catalog
44

55
import (
66
"fmt"
7+
"strconv"
78
"strings"
9+
"time"
810

911
"github.com/mendixlabs/mxcli/mdl/catalog/graph"
1012
)
@@ -25,6 +27,17 @@ var graphRefKinds = []string{
2527
// betweenness is skipped (PageRank/communities still run) to keep the pass fast.
2628
const betweennessNodeCap = 6000
2729

30+
// effectiveResolution normalises the Leiden resolution. One function so the
31+
// value recorded in the cache is the value the pass actually used — recording
32+
// the caller's 0 would make a later re-run at "the same resolution" a different
33+
// run.
34+
func effectiveResolution(r float64) float64 {
35+
if r <= 0 {
36+
return 1.0
37+
}
38+
return r
39+
}
40+
2841
// AddGraphAnalysis runs the graph-analysis pass (communities/cycles/layers/
2942
// centrality) on an already-built catalog WITHOUT re-parsing. The catalog must
3043
// already contain the refs table (built in full or source mode). This lets
@@ -33,6 +46,7 @@ const betweennessNodeCap = 6000
3346
// the source FTS data. The graph rows reuse the catalog's existing SnapshotId so
3447
// the snapshot-framed views resolve.
3548
func (c *Catalog) AddGraphAnalysis(resolution float64) error {
49+
resolution = effectiveResolution(resolution)
3650
var snapID string
3751
if err := c.db.QueryRow("SELECT SnapshotId FROM snapshots ORDER BY rowid DESC LIMIT 1").Scan(&snapID); err != nil {
3852
return fmt.Errorf("catalog has no snapshot (build full first): %w", err)
@@ -52,7 +66,17 @@ func (c *Catalog) AddGraphAnalysis(resolution float64) error {
5266
_ = tx.Rollback()
5367
return err
5468
}
55-
return tx.Commit()
69+
if err := tx.Commit(); err != nil {
70+
return err
71+
}
72+
// Record that the pass ran. An empty graph_cycles_data means "no cycles"
73+
// only once this is set; before it, it means "never computed" — and the two
74+
// were indistinguishable (mendixlabs/mxcli#1060). Written after the commit
75+
// so the flag can never claim a pass that was rolled back.
76+
if err := c.SetMeta(MetaGraphAnalysis, time.Now().Format(time.RFC3339)); err != nil {
77+
return err
78+
}
79+
return c.SetMeta(MetaGraphResolution, strconv.FormatFloat(resolution, 'g', -1, 64))
5680
}
5781

5882
// buildGraphAnalysis runs the pure-Go graph algorithms over the refs graph and
@@ -77,10 +101,7 @@ func (b *Builder) buildGraphAnalysis() error {
77101

78102
g := graph.New(edges)
79103
projectID, snapshotID := b.snapshotMeta()
80-
resolution := b.resolution
81-
if resolution <= 0 {
82-
resolution = 1.0
83-
}
104+
resolution := effectiveResolution(b.resolution)
84105
// Communities.
85106
comm := g.Communities(resolution)
86107
commStmt, err := b.tx.Prepare(

‎mdl/catalog/catalog.go‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package catalog
66
import (
77
"database/sql"
88
"fmt"
9+
"strconv"
910
"strings"
1011
"time"
1112
)
@@ -280,6 +281,21 @@ const (
280281
MetaBuildMode = "build_mode"
281282
MetaBuildTime = "build_time"
282283
MetaBuildDuration = "build_duration"
284+
285+
// MetaGraphAnalysis records that AddGraphAnalysis has run against this
286+
// catalog, and MetaGraphResolution the Leiden resolution it used.
287+
//
288+
// Deliberately NOT another build mode. fast/full/source is a LEVEL — each
289+
// contains the one below, so a rank comparison decides everything. The graph
290+
// pass is orthogonal: it augments whatever level is there (that is the whole
291+
// point of AddGraphAnalysis being additive), so folding it into the rank
292+
// would make "source" and "full+graph" incomparable. It is a flag.
293+
//
294+
// Without it an un-run graph pass is indistinguishable from a graph with
295+
// nothing in it: the tables are empty either way, and the recorded mode still
296+
// says "full" (mendixlabs/mxcli#1060).
297+
MetaGraphAnalysis = "graph_analysis"
298+
MetaGraphResolution = "graph_resolution"
283299
)
284300

285301
// CacheInfo contains information about the cached catalog.
@@ -292,6 +308,11 @@ type CacheInfo struct {
292308
BuildDuration time.Duration
293309
IsValid bool
294310
InvalidReason string
311+
312+
// GraphAnalysis reports whether the communities/cycles/layers/centrality
313+
// pass has run against this catalog, and at which resolution.
314+
GraphAnalysis bool
315+
GraphResolution float64
295316
}
296317

297318
// NewFromFile opens a catalog from a persisted SQLite file.
@@ -406,6 +427,7 @@ func (c *Catalog) migrateIfSchemaMismatch() error {
406427
for _, key := range []string{
407428
MetaMprPath, MetaMprModTime, MetaMendixVersion,
408429
MetaBuildMode, MetaBuildTime, MetaBuildDuration,
430+
MetaGraphAnalysis, MetaGraphResolution,
409431
} {
410432
if _, err := c.db.Exec(`DELETE FROM catalog_meta WHERE Key = ?`, key); err != nil {
411433
return fmt.Errorf("clearing cache-info key %s: %w", key, err)
@@ -593,6 +615,12 @@ func (c *Catalog) GetCacheInfo() (*CacheInfo, error) {
593615
if durationStr, _ := c.GetMeta(MetaBuildDuration); durationStr != "" {
594616
info.BuildDuration, _ = time.ParseDuration(durationStr)
595617
}
618+
if v, _ := c.GetMeta(MetaGraphAnalysis); v != "" {
619+
info.GraphAnalysis = true
620+
}
621+
if v, _ := c.GetMeta(MetaGraphResolution); v != "" {
622+
info.GraphResolution, _ = strconv.ParseFloat(v, 64)
623+
}
596624

597625
return info, nil
598626
}

0 commit comments

Comments
 (0)