Code Validation & Diagnostics
While you write Julia / MTK code in the CoModel text editor, the platform continuously runs syntax validation (parse) and model validation (mtkcompile) in the background, and reports errors/warnings back into the editor as IDE-style squiggly underlines, hover tooltips, and a Problems list.

Triggering Validation
Validation can be triggered in three ways:
| Trigger | Description |
|---|---|
| Debounced auto-validation | Submitted automatically after editing pauses for about 800 ms |
| Manual validation | Triggered immediately by the Validate button on the toolbar |
| Pre-save validation | Can be enabled in settings; if error-level diagnostics exist before saving, a prompt asks whether to continue saving |
During rapid consecutive editing, the system keeps only the latest validation result, so stale diagnostics never override the current code state.
Two-Stage Validation
Back-end validation runs in two sequential stages:
1. Syntax Validation (parse)
The first stage parses the whole file, for example with Julia's Meta.parseall:
# Valid example
using ModelingToolkit
@variables t
@named r = Resistor(R=1.0)
Syntax errors such as a missing end or unbalanced parentheses produce diagnostics with source="parse" and precise line and column positions. If this stage fails, the second stage does not run.
2. Model Validation (mtkcompile)
Once syntax passes, the second stage loads the text in an isolated subprocess and tries to build the MTK system up to mtkcompile. Common errors include:
| Error type | Example | Description |
|---|---|---|
| Undefined component | Resitor(R=1.0) |
Component name misspelled |
| Port mismatch | connect(r1.p, c1.n) |
Incompatible port type or direction |
| Structurally singular | Equation count does not match variable count | The model topology cannot be solved |
| Initialization problem | Missing initial conditions | Causes mtkcompile to fail |
This stage returns diagnostics with source="mtkcompile"; if the exception stack cannot be mapped to a user source line, it falls back to a file-level message that preserves the original error text.
Diagnostic Reporting
Validation results are mapped to Monaco editor markers:
| Level | Visual style | Purpose |
|---|---|---|
| error | Red squiggly underline | Syntax or model build errors |
| warning | Yellow squiggly underline | Potential issues; does not block simulation |
| info | Blue hint underline | Advisory hints |
Hover over a squiggly range to see the full diagnostic message, the source label (parse / mtkcompile), and the line/column range.
{
"level": "error",
"line": 12,
"column": 5,
"endLine": 12,
"endColumn": 18,
"message": "Undefined component Resitor (did you mean Resistor?)",
"source": "mtkcompile"
}
The Problems List
The information area below the editor provides the Problems list, which aggregates all diagnostics for the current text:
- Each diagnostic shows a level icon, the message, the
sourcelabel, and the position (Ln 12, Col 5). - Click any entry and the editor scrolls to the position and highlights the range.
- When validation passes, it shows "No problems found".

Status and Degradation
While validating, the interface shows a "Validating…" status. If the back-end service is unavailable, times out, or the task fails:
- Editing and saving are not blocked.
- The last valid diagnostics are retained and marked as stale.
- With no previous diagnostics, it shows "Validation service unavailable".

Security and Isolation
Because the mtkcompile stage executes user code, the back end runs validation tasks in isolated, restricted subprocesses:
- Each task gets its own temporary directory, with file-system writes, network access, and process spawning restricted.
- The default timeout is 30 seconds; the concurrency limit is configurable.
- Sensitive absolute paths are filtered out of error messages before they are returned; only relative/logical locations are exposed.