Skip to content

ltm-augment: substitute_reducers_in_equation parse-failure fallback returns input unchanged #661

Closed

Description

@bpowers

Problem

substitute_reducers_in_equation in src/simlin-engine/src/ltm_augment.rs (around line 1301) replaces a recognized reducer subexpression with its aggregate-node name to build the $⁚ltm⁚agg⁚{n} → target partial equation. If the parse of its input fails before substitution, the inline reducer survives unchanged into the agg→target partial.

This is a different hazard class from the one fixed by GH #311. GH #311 covered the case where a parse failure in the ceteris-paribus partial caused the unwrapped equation to be emitted (a PREVIOUS()-omission that silently makes the link score a constant 1). This item is the reducer-substitution-omission variant: the inline reducer is not replaced by the agg name, so the agg→target partial silently references the live reducer instead of the hoisted aggregate node.

Why it matters

Effectively unreachable in production -- the input is always a print_eqn re-print of an already-parsed AST, so the re-parse cannot realistically fail. This is a defense-in-depth candidate: it should mirror the GH #311 loud-failure treatment (convert the parse failure into a Warning naming the variable + offending equation text and skip the variable, rather than silently returning the input unchanged and producing a wrong-but-clean-compiling link score).

Components affected

  • src/simlin-engine/src/ltm_augment.rs (substitute_reducers_in_equation, substitute_reducers_in_expr0)

Possible approaches

Make substitute_reducers_in_equation return Result<_, PartialEquationError> like the sibling partial-equation builders already do (build_partial_equation_shaped etc.), and have the db-bearing caller convert the error into a Warning via the existing emit_ltm_partial_equation_warning path.

Severity

Low (defense-in-depth; unreachable today).

Discovery context

Identified during an LTM-hardening session while reviewing the GH #311 ceteris-paribus loud-failure fix for sibling omission hazards.

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