Skip to content

ltm-finding: truncate-before-filter can drop partition-dominant loops #310

Closed

Description

@bpowers

Summary

rank_and_filter() truncates discovered loops to MAX_LOOPS (200) before partition-aware contribution filtering.

Why this is a problem

LTM interpretation is partition-scoped: loops should be compared within cycle partitions. Global pre-truncation can drop loops that are dominant in small partitions but globally below rank 200, violating partition-local dominance semantics.

Literature / algorithm alignment

Reference and design docs emphasize partition-scoped comparison for relative contribution. Global truncation before partition-aware retention introduces cross-partition interference.

Current implementation behavior

Order in rank_and_filter():

  1. global sort by avg abs score
  2. truncate to 200
  3. partition-aware per-timestep contribution filter

Location:

  • src/simlin-engine/src/ltm_finding.rs (rank_and_filter)

Impact

  • False negatives for partition-dominant loops in large models.
  • Reported loop set can underrepresent smaller disconnected feedback subsystems.

Success criteria

  1. Reorder filtering so partition-aware retention is applied before any global cap, or apply per-partition quotas prior to global cap.
  2. Define and document deterministic tie-breaking when the final capped set still exceeds MAX_LOOPS.
  3. Add tests with >200 loops spanning multiple partitions where a low-global-score but high-partition-share loop is retained.
  4. Keep deterministic IDs and output ordering stable.

Notes

This issue concerns post-discovery ranking/filtering only, not the known flow-to-stock timing choice.

Activity

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

    @bpowers
    OwnerAuthor

    Concrete proposal: filter-then-truncate

    Adding implementation-level detail to complement the original report.

    Current order (src/simlin-engine/src/ltm_finding.rs:848-917)

    1. Sort by avg |score| desc
    2. truncate(MAX_LOOPS) -> 200
    3. Partition-relative contribution filter (>= MIN_CONTRIBUTION = 0.1%)
    4. Assign IDs
    5. Re-sort

    The risk is already acknowledged inline at lines 833-836:

    NOTE: This truncation happens before partition-aware filtering. A loop
    dominant in a small partition but globally ranked below 200th could be
    truncated. In practice MAX_LOOPS is generous enough that this is
    extremely unlikely.
    

    Proposed reorder

    1. Sort by avg |score| desc
    2. Partition-relative contribution filter (preserves small-partition dominance)
    3. truncate(MAX_LOOPS) -> 200 (now applies to contribution-significant loops only)
    4. Assign IDs
    5. Re-sort

    Why this is strictly an improvement

    • Cost: negligible. The filter pass is already O(n x steps); applying it to a few hundred extra raw discovery candidates before truncation is in the noise.
    • Correctness: a loop dominant in a 5-loop secondary partition (e.g. >= 0.1% of that partition's total |score|) is retained even when its global rank is well below 200. The point of partition-aware filtering is exactly to give small partitions their own threshold space; truncating first defeats that purpose.

    Edge cases

    • Filter result < 200 loops: truncation is a no-op. Correct.
    • Filter result > 200 loops: truncation cuts at the boundary, but every retained loop has already passed the contribution threshold, so the truncation only drops above-threshold but lower-ranked loops. That matches the paper's "top N" prescription (Eberlein & Schoenberg 2020, Section 7).

    Suggested test

    Add a unit test in ltm_finding.rs::tests that constructs a synthetic discovery result with:

    • One large partition (250+ loops)
    • One small partition (5 loops with high partition-relative contribution but low global avg |score|)

    Assert all 5 small-partition loops survive under filter-then-truncate. The same fixture against the current truncate-then-filter implementation should drop some of them, demonstrating the regression risk this protects against.

    File references

    • Current implementation: src/simlin-engine/src/ltm_finding.rs:848-917
    • Existing acknowledgment: lines 833-836 (NOTE comment)
    • Paper threshold values: Eberlein & Schoenberg 2020, Section 7
  3. bpowers commented on Jun 2, 2026

    @bpowers
    OwnerAuthor

    Fixed in PR #668 (merged as f9f850d), together with #543 (same function). rank_and_filter now applies the partition-aware MIN_CONTRIBUTION retention filter before any global cap, then ranks by partition-relative importance, then truncates to MAX_LOOPS — so a partition-dominant loop globally ranked below the cap survives. Deterministic content-based tie-breaking; a MaxLoopsGuard test-only override (the #515 pattern) keeps fixtures tiny. Pinned by test_rank_and_filter_310_partition_dominant_survives_cap (red-verified).

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