Skip to content

ltm: surface MostlyReinforcing/MostlyBalancing in JSON/TS/WASM layers #495

Closed

Description

@bpowers

Problem

PR #490 added MostlyReinforcing/MostlyBalancing (Rux/Bux) variants to the Rust LoopPolarity and DetectedLoopPolarity enums, plus a polarity_confidence: f64 field on DetectedLoop. The JSON-emitted to_loop_summary (in src/simlin-engine/src/analysis.rs) surfaces the new variants as mostly_reinforcing / mostly_balancing strings.

However, the TypeScript / WASM / C-FFI layers still see only the three legacy values:

  • src/libsimlin/src/ffi.rs SimlinLoopPolarity only has Reinforcing = 0, Balancing = 1, Undetermined = 2. src/libsimlin/src/analysis.rs coalesces MostlyReinforcing -> Reinforcing and MostlyBalancing -> Balancing before returning to FFI consumers, with the polarity confidence dropped on the floor.
  • The @simlin/engine / @simlin/diagram packages downstream of the WASM bindings therefore have no way to distinguish a steady-R loop from a Rux loop, even though the engine knows the difference.

This was an accepted trade-off for #490 to keep the FFI surface stable, but it's tech debt worth tracking separately.

What needs to happen

  1. Extend the C ABI: either add Rux = 3, Bux = 4 to SimlinLoopPolarity plus a polarity_confidence: f32 field on SimlinLoop, or expose confidence through a new accessor. Whichever shape is chosen needs to be additive so existing callers keep compiling.
  2. Update the cbindgen-generated simlin.h and the WASM @simlin/engine types to match.
  3. Plumb the new variants through src/diagram/ so the visual rendering can distinguish Rux / Bux (the LTM literature suggests a "gray" treatment, similar to the confidence < 0.99 rendering in section 13.7 of docs/reference/ltm--loops-that-matter.md).
  4. Mirror the FFI extension into pysimlin so its LoopPolarity enum can survive a round-trip through the FFI without coalescing the way the Python-side from_runtime_scores already preserves the variants.

Context

Discovered during PR #490 review (#490). The PR body acknowledged the FFI coalescing as a deliberate scope cut; this issue records the follow-up.

References

  • src/libsimlin/src/analysis.rs (current coalescing site)
  • src/libsimlin/src/ffi.rs (SimlinLoopPolarity)
  • src/simlin-engine/src/db_analysis.rs (DetectedLoopPolarity, polarity_confidence)
  • src/simlin-engine/src/ltm.rs (POLARITY_CONFIDENCE_THRESHOLD, LoopPolarity)
  • docs/reference/ltm--loops-that-matter.md section 13.7 (formula and gray-rendering convention)
  • LTM tracking epic: epic: Loops that Matter (LTM) -- open work #488
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

    ltmLoops that Matter (LTM) analysis subsystem

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions