Skip to content

diagram: stale pre-edit sim curves shown (no staleness indicator) after an edit makes the model non-simulatable #813

Description

@bpowers

Problem

In the diagram editor, after an edit makes a model fail to simulate, the editor keeps showing the pre-edit simulation curve as if it were current, with no staleness indication. Clicking a still-valid variable renders its stale pre-edit curve until the model successfully simulates again.

Root cause

ProjectController.this.data (the attached sim Series map) is only ever assigned on a successful run and is never cleared:

  • Declared/initialized: src/diagram/project-controller.ts:263 (private data: ReadonlyMap<string, Series> = new Map())
  • Assigned only on success: src/diagram/project-controller.ts:956 (this.data = data;), at the very end of loadSim() after a successful run.
  • Re-attached unconditionally when building the published snapshot: src/diagram/project-controller.ts:634-635:
    if (this.data) {
      activeProject = projectAttachData(activeProject, this.data, 'main');
    }
    and surfaced in the snapshot at src/diagram/project-controller.ts:327 (data: this.data).

loadSim() early-returns in several failure paths without touching this.data:

  • if (!(await engine.isSimulatable())) { return; } (the model no longer compiles/simulates after the edit)
  • the nested catch after both model.run() and the LTM-disabled retry fail, which does await this.refreshCachedErrors(); return;

In all of these the previously-attached this.data stays live, so the next snapshot re-attaches the old series to the (now different) project, and the UI renders stale curves.

Why it matters

Correctness / trust of the UX. A modeler edits an equation, the model breaks, but the chart/sparkline keeps showing the old simulation output with no indication it is stale. They may believe their change had no effect, or draw conclusions from a curve that no longer corresponds to the current model. This is a silent-wrong-data class of bug, worse than showing nothing.

Component(s) affected

  • src/diagram/project-controller.ts (loadSim, snapshot build / projectAttachData re-attach path)
  • Downstream consumers of the snapshot data (charts, sparklines in the variable details / canvas)

Possible approaches

  1. Clear or mark-stale this.data when a re-sim fails or early-returns (e.g. set to an empty map, or wrap in a { stale: boolean }) so no pre-edit series is re-attached to a changed project.
  2. Track a dataGeneration/projectGeneration correspondence so the snapshot only attaches data when it matches the current project generation, and otherwise surfaces a staleness flag.
  3. Surface a staleness indicator in the chart/sparkline UI (dim/overlay "out of date") rather than silently dropping the curve, so the user knows a re-sim is needed.

Option 2 + 3 together preserve the last-good curve while honestly marking it stale; option 1 is the minimal correctness fix.

How discovered

Identified during a pre-deploy audit of the Simlin diagram editor. This is a separate UX-correctness bug NOT addressed by PR #810.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions