Skip to content

[Bug] Committed MPR with dangling unit GUID references crashes Studio Pro VersionControl status cache (RevStatusCache) #296

@Chendodelangen

Description

@Chendodelangen

Summary

After a sequence of CREATE + DROP mxcli operations, the committed AssetManagement.mpr (SQLite) can contain unit GUID references pointing to .mxunit files that no longer exist on disk and were never committed to git. Studio Pro's VersionControl git-integration then crashes on every open attempt — before the project is usable — because it tries to load the "deleted" units from its base_data cache to compute git diffs.

This is distinct from #295 (wrong mxunit content): that crash is on model load. This crash is on VC status initialization — later in the startup sequence, but equally fatal.

Environment

  • mxcli version: v0.7.0-dirty (2026-04-21T08:30:06Z) (Go: go1.26.2, windows/amd64)
  • Mendix version: 10.24.15.93102
  • Diagnostic bundle: mxcli-diag-20260424-115510.tar.gz (available on request)

Steps to Reproduce

# 1. CREATE a snippet (or any model element that produces new mprcontents/ files)
./mxcli.exe exec step6b-history-snippet.mdl -p AssetManagement.mpr
# → mxcli reports: errors_count:0
# → New mxunit written to mprcontents/a5/38/a538b889-*.mxunit

# 2. Commit only the MPR SQLite — NOT the new mprcontents/ files
git add AssetManagement.mpr
git commit -m "feat: add snippet"
# mprcontents/a5/38/ is now ABSENT from git history

# 3. DROP the snippet (removes mxunit from disk)
./mxcli.exe -p AssetManagement.mpr -c "DROP SNIPPET Module.MySnippet"
# → mxunit file deleted from disk
# → Committed SQLite still has the GUID reference

# 4. Open project in Studio Pro → CRASH

Expected Behaviour

Studio Pro opens normally. Either:

  • mxcli warns at step 1: "New mprcontents/ files created — include them in your git commit: mprcontents/a5/38/a538b889-*.mxunit"
  • Or mxcli validates at step 3 (DROP): "Warning: unit a538b889 is referenced in committed git history but the mxunit file was never committed — this will corrupt the VC cache after drop"

Actual Behaviour

Studio Pro crashes on every open with:

System.IO.DirectoryNotFoundException: Could not find a part of the path
  'C:\..\.mendix-cache\base_data\mprcontents\a5\38\a538b889-7c03-4a97-bdac-6c4e1c787f87.mxunit'
   at Mendix.Modeler.VersionControl.Status.RevStatusCache.CreateDeleteStatusItem(Guid unitID, String baseFilePath)
   at Mendix.Modeler.VersionControl.Status.RevStatusCache.DoRefresh(IProgressInfo info)
   at Mendix.Modeler.VersionControl.Status.StatusCacheManager.Initialize(IProject project, IProgressInfo info)

Studio Pro's VC diff code finds the unit GUID in the committed (base) MPR SQLite but not in the working copy. It classifies the unit as "deleted" and tries to load the original content from base_data/mprcontents/ for diff display. The cache entry doesn't exist (because the mxunit was never in git) → crash.

In our case this happened twice in one session with two different GUIDs (a538b889 and 9049003e), triggered by a DROP + CREATE cycle around bug #295.

mxcli log entries (from logs\mxcli-2026-04-24.log)

{"time":"2026-04-24T10:45:30.8979451+02:00","level":"INFO","msg":"session_start","mode":"exec","args":["mxcli.exe","exec","step6b-history-snippet.mdl","-p","AssetManagement.mpr"]}
{"time":"2026-04-24T10:45:32.7744023+02:00","level":"INFO","msg":"execute","stmt_type":"CreateSnippetStmtV3","stmt_summary":"CREATE SNIPPET AuditTrail_Custom.SNIPPET_Asset_AuditHistory","duration_ms":1857}

{"time":"2026-04-24T11:24:10.8593859+02:00","level":"INFO","msg":"session_start","mode":"batch","args":["mxcli.exe","-p","AssetManagement.mpr","-c","DROP SNIPPET AuditTrail_Custom.SNIPPET_Asset_AuditHistory;"]}
{"time":"2026-04-24T11:24:20.2021009+02:00","level":"INFO","msg":"execute","stmt_type":"DropSnippetStmt","duration_ms":9331}

{"time":"2026-04-24T11:24:23.886075+02:00","level":"INFO","msg":"session_start","mode":"exec","args":["mxcli.exe","exec","step6b-history-snippet.mdl","-p","AssetManagement.mpr"]}
{"time":"2026-04-24T11:24:25.2385013+02:00","level":"INFO","msg":"execute","stmt_type":"CreateSnippetStmtV3","duration_ms":1333}

All operations report errors_count:0. mxcli gives no indication that the resulting model state will be unloadable by Studio Pro.

Root Cause Analysis

MPR v2 stores unit metadata in SQLite (AssetManagement.mpr) and unit content in separate binary files (mprcontents/xx/yy/uuid.mxunit). When mxcli creates a model element, it:

  1. Writes the GUID to SQLite ✓
  2. Writes the .mxunit file to disk ✓ (or in [Bug] CREATE SNIPPET with Params + $currentObject page call creates null PageParameterMapping — project fails to open in Studio Pro #295's case: writes it with broken content)

But mxcli gives no guidance that the new mprcontents/ files must be committed to git alongside the MPR. When those files are later removed by a DROP, the committed MPR SQLite has a stale reference that Studio Pro's VC integration cannot resolve.

Recovery

The only fix was to restore the MPR SQLite to a clean commit that predated the dangling references and force-commit it as a new HEAD, which Studio Pro then uses as the new VC baseline.

Suggested Fix

One or more of:

  1. After any CREATE/ALTER/DROP: print a warning if git status shows uncommitted mprcontents/ files that are referenced by the current MPR SQLite
  2. Provide mxcli git-stage or mxcli git-add: a helper that stages all MPR-referenced mxunit files alongside the SQLite
  3. After DROP: warn if the dropped unit's GUID appears in committed git history but the mxunit file was never committed — flag it as a VC integrity risk

Diagnostic bundle

Available: mxcli-diag-20260424-115510.tar.gz — contains full session log for 2026-04-24 including all operations leading to the corruption.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions