Skip to content

Systems format translator: duplicate source/dest flow pairs produce colliding identifiers #399

@bpowers

Description

@bpowers

Problem

The systems format translator (src/simlin-engine/src/systems/translate.rs) does not validate or handle duplicate source/destination pairs in flows. If a model contains two flow declarations with the same source and destination, such as:

A > B @ 3
A > B @ 5

The translator generates colliding variable identifiers for both (e.g., both produce a_outflows_b and a_to_b), which would cause compilation failures or silent overwrites downstream.

Why it matters

  • Correctness: Silent overwrites mean one flow equation would replace the other, producing wrong simulation results with no error message.
  • Developer experience: If compilation does fail, the error would be a confusing duplicate-identifier error from the compiler rather than a clear message pointing at the duplicate flow declaration.
  • Robustness: As the systems format is intended for AI agents and humans to author models quickly, unclear failure modes undermine trust.

Component(s) affected

  • src/simlin-engine/src/systems/translate.rs (identifier generation in flow translation)

Possible approaches

  1. Reject duplicates with a clear error: During translation, track (source, dest) pairs and emit a diagnostic if the same pair appears twice. This is the simplest and probably correct behavior -- duplicate flows with the same source/dest are likely a modeling error.
  2. Disambiguate with suffixes: Generate identifiers like a_to_b_1, a_to_b_2 for duplicate pairs. This is more permissive but adds complexity and may mask authoring mistakes.

Option 1 is recommended.

Context

Identified during review of the systems format translation logic on the systems-format branch.

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