Skip to content

LTM auto-flip warning unreachable through simlin_project_get_errors #466

Closed

Description

@bpowers

Problem

PR #461 (branch ltm-perf-enable-always) adds an auto-flip warning when LTM auto-switches to discovery mode. The warning accumulates through model_all_diagnostics only when SourceProject::ltm_enabled is true. But simlin_sim_new toggles ltm_enabled=false right after compile (to avoid leaking the flag to patch validation), and simlin_project_get_errors compiles with ltm_enabled=false by default.

A user workflow that silently drops the warning:

  1. Calls simlin_sim_new(..., enable_ltm=true) on a dense model.
  2. Hits "LTM auto-switched to discovery" silently (auto-flip triggered because the element-level largest SCC exceeded MAX_LTM_SCC_NODES).
  3. Calls simlin_project_get_errors / pysimlin's project.get_errors() to see what happened.

The get_errors call re-runs diagnostic collection with ltm_enabled=false, so the LTM diagnostic pipeline is skipped entirely and the auto-flip warning is invisible to the caller.

Evidence

  • The gate in model_all_diagnostics (src/simlin-engine/src/db.rs around lines 1942-1950):

    // When LTM is enabled, also trigger LTM variable generation so that
    // any diagnostics accumulated by `model_ltm_variables` (e.g., the
    // auto-flip warning from db_ltm.rs) surface through
    // `collect_all_diagnostics`.  Without this call, the warning would
    // be invisible to `simlin-mcp`/`libsimlin` callers even though
    // `model_ltm_variables` had already emitted it.
    if project.ltm_enabled(db) {
        let _ = model_ltm_variables(db, model, project);
    }
  • The reset in simlin_sim_new (src/libsimlin/src/simulation.rs around lines 94-99):

    // Always reset ltm_enabled to avoid leaking the flag to
    // subsequent operations (e.g. patch validation) that share
    // the same SourceProject.
    if enable_ltm {
        engine::db::set_project_ltm_enabled(&mut db, source_project, false);
    }
  • The test that locks in the gate: test_ltm_disabled_does_not_surface_auto_flip_warning in src/simlin-engine/src/db_ltm_unified_tests.rs:574.

Partial mitigation already in place

simlin_analyze_get_relative_loop_score's error message is self-contained (explains auto-flip threshold inline), so users hitting the score-unavailable path understand what happened. But the separate "ask the project for its errors" workflow silently drops the warning.

Why it matters

Degrades diagnostic UX for the canonical "why does my LTM analysis feel wrong?" workflow. Scores are correctly computed (or correctly unavailable) either way, so this is not a correctness issue, but it makes the auto-flip invisible through the primary error-inspection entry point that AI agents and CLI callers reach for first.

Severity

Medium.

Proposed fix options

One of:

  1. Capture compile diagnostics in simlin_sim_new (while ltm_enabled=true) and expose via SimlinSim state / a new FFI like simlin_sim_get_compile_warnings.
  2. Add an include_ltm_warnings flag to simlin_project_get_errors that re-enables LTM transiently during diagnostic collection.
  3. Remove the ltm_enabled gate in model_all_diagnostics so model_ltm_variables runs always; updates test_ltm_disabled_does_not_surface_auto_flip_warning to reflect new semantics. Downside: LTM synthesis cost is paid even for callers that never ran a sim.
  4. Track a "latest sim had LTM enabled" flag on SimlinProject and use it to decide whether get_errors should include LTM diagnostics. Naturally scopes LTM diagnostics to callers who asked for LTM at least once.

Discovery context

Flagged by Codex in review iterations 7, 9, and 11 of PR #461 (P2 in iter 11). Filed now because the mitigation work needs its own scope decision and is out-of-scope for the cap-lift work.

Files

  • src/simlin-engine/src/db.rs (around lines 1918-1950, model_all_diagnostics)
  • src/libsimlin/src/simulation.rs (around lines 94-99, simlin_sim_new's ltm_enabled reset)
  • src/simlin-engine/src/db_ltm_unified_tests.rs:574 (test_ltm_disabled_does_not_surface_auto_flip_warning)
  • src/simlin-engine/src/db_ltm.rs (model_ltm_variables, source of the auto-flip warning)

Activity

  1. added
    ltm
    on May 1, 2026
  2. bpowers commented on Jun 2, 2026

    @bpowers
    OwnerAuthor

    Fixed in PR #668 (merged as f9f850d). simlin_project_get_errors now surfaces LTM diagnostics (auto-flip advisory, fragment-failure and partial-equation warnings) for projects that requested LTM at least once, via an ltm_requested latch + transient re-enable — with LTM scoped as an analysis overlay: project compilability is still assessed LTM-off, so an LTM-incompatible model that simulates fine is never reported broken. SimlinErrorDetail also gained a severity field threaded through pysimlin and the TS engine so advisories display as warnings, not errors. Pinned by test_get_errors_surfaces_ltm_auto_flip_warning_after_ltm_sim (red-verified), test_get_errors_rk4_ltm_compile_failure_is_not_a_project_error, and pysimlin TestLtmOverlayNotProjectError/TestLtmAdvisorySeverity. The sibling simlin-mcp-core gap is tracked as #662.

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

    ltm

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions