Skip to content

ltm: analyze_model swallows compile errors and returns an empty ModelAnalysis silently #660

Closed

Description

@bpowers

Problem

run_ltm_pipeline in src/simlin-engine/src/analysis.rs (around line 161) does:

let compiled_sim =
    crate::db::compile_project_incremental(db, source_project, &canonical_name).ok()?;

On any compile failure it .ok()?s to None, and analyze_model then returns an empty ModelAnalysis (no loops, intact model snapshot) with no explanation. The rustdoc on analyze_model documents this as intended ("Returns gracefully on simulation failure (empty loop fields, model snapshot intact)").

This was a benign graceful-degradation pattern until GH #486 landed the hard-fail compile guard for LTM + non-Euler integration (assemble_simulation returns an Err when ltm_enabled and the effective method is RK2/RK4 with stocks present). Now analyze_model on an RK4 model returns "no loops" silently -- the actionable, specific Euler error from the assemble path is discarded by the .ok()?, so the caller cannot tell "this model genuinely has no loops" apart from "this model could not be compiled for LTM analysis."

Why it matters

Diagnostic/UX gap. The MCP analyze surfaces are the primary consumers:

  • src/simlin-mcp-core read_model.rs (around line 108)
  • src/simlin-mcp-core edit_model.rs (around line 320)

An AI agent or CLI caller asking "what loops does this model have?" on an RK4+LTM model gets an empty result and no hint that the real issue is the non-Euler integration method. The error is genuinely actionable (switch to Euler, or disable LTM) but is thrown away.

Components affected

  • src/simlin-engine/src/analysis.rs (run_ltm_pipeline, analyze_model)
  • src/simlin-mcp-core/src/tools/read_model.rs, edit_model.rs (consumers)

Possible approaches

  • Have run_ltm_pipeline / analyze_model distinguish "compiled, no loops" from "failed to compile" and surface the compile Err string (or a structured diagnostic) instead of collapsing both to an empty ModelAnalysis.
  • At minimum, propagate the assemble-stage Err message into ModelAnalysis so the MCP analyze surfaces can show it.

Severity

Low-medium (UX / diagnostic visibility; not a correctness bug -- the result is empty, not wrong).

Discovery context

Identified during an LTM-hardening session reviewing the interaction between the GH #486 non-Euler hard-fail guard and the pre-existing graceful-degradation in analyze_model.

Part of epic #488.

Activity

  1. added
    engine
    ltm
    on Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    engineltm

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions