Skip to content

loop-progress.ts's percentComplete can go negative, contradicting its documented 0-100 range #6773

Description

@JSONbored

Context

packages/loopover-engine/src/loop-progress.ts:33-34 documents percentComplete as "0-100, or null when the budget is unknown," but the implementation at lines 43-44 clamps only the upper bound (Math.min(100, ...)) with no Math.max(0, ...). LoopProgressState.iteration is a plain number with no runtime validation before this computation, so a negative iteration (from an upstream bookkeeping bug) produces a negative percentComplete. No test file exists for this module; the mirror host test only covers the upper-bound clamp.

Requirements

  • Clamp with Math.max(0, Math.min(100, ...)) so percentComplete can never leave [0, 100] regardless of the caller-supplied iteration value.

Deliverables

  • Lower-bound clamp added
  • Regression test with a negative iteration asserting percentComplete clamps to 0

Test Coverage Requirements

99%+ Codecov patch coverage on every changed line and branch, plus a regression test that reproduces the exact failure mode described above and asserts it's fixed.

Expected Outcome

percentComplete always stays within its documented [0, 100] range.

Links & Resources

packages/loopover-engine/src/loop-progress.ts:33-34,43-44.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:bugGittensor-scored bug fix — scores a 0.05x multiplier.help wantedExtra attention is needed

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions