Skip to content

miner/loop-reentry-policy.ts's shouldReenter ceilings are invisible to Codecov #8347

Description

@JSONbored

Context

packages/loopover-engine/src/miner/loop-reentry-policy.ts (#2338) exports shouldReenter: the pure decision
half of "on a resolved outcome, automatically re-invoke discovery for the next candidate." Its own header
comment calls this "the top slop-at-scale risk for the whole miner subsystem" and gives it three independent
ceilings, all collected (not short-circuited) except the kill-switch check which IS checked first and does
short-circuit: a per-repo circuit breaker on consecutive "disengaged" outcomes, an hourly re-entry cap, and
a per-session re-entry cap. It is live and consumed via packages/loopover-miner/lib/loop-reentry.ts, and it
already has a full, passing test suite at packages/loopover-engine/test/loop-reentry-policy.test.ts (16
scenarios, node --test).

Same failure mode as #6250 (review-enrichment's node:test suite being invisible to Codecov): that engine
package suite doesn't run under root vitest, which is what Codecov's codecov/patch gate reads.
packages/loopover-engine/src/**/*.ts is already listed in vitest.config.ts's coverage.include, so this
is a per-file gap — nothing under root test/** currently exercises shouldReenter directly, so it reports
as ~0% covered in Codecov despite real, passing tests existing one directory over.

⚠️ Read this before starting. This issue is test-coverage-only. Do NOT modify
packages/loopover-engine/src/miner/loop-reentry-policy.ts,
packages/loopover-engine/src/governor/kill-switch.ts, or
packages/loopover-engine/test/loop-reentry-policy.test.ts. The only new artifact this issue calls for is
one new root-level vitest file that exercises the EXISTING, unchanged decision function. A PR that changes
any of this ceiling/circuit-breaker logic does not satisfy this issue and is out of scope for it.

Requirements

  • Create test/unit/loop-reentry-policy.test.ts using describe/it/expect from vitest, importing
    shouldReenter, DEFAULT_MAX_CONSECUTIVE_DISENGAGEMENTS, DEFAULT_MAX_REENTRIES_PER_HOUR, and
    DEFAULT_MAX_REENTRIES_PER_SESSION from "../../packages/loopover-engine/src/index" — the barrel —
    matching the existing sibling pattern in test/unit/calibration-dashboard.test.ts. Use a fake/stubbed
    MinerKillSwitchScope the same way packages/loopover-engine/test/loop-reentry-policy.test.ts already does
    — do not exercise the real isMinerKillSwitchActive implementation's own IO paths.
  • Cover, at minimum, every scenario already exercised in
    packages/loopover-engine/test/loop-reentry-policy.test.ts (read it for the exact fixtures/assertions to
    mirror), including:
    • Kill-switch active short-circuits to { reenter: false, reasons: ["<scope>_kill_switch_active"] } even
      when none of the other three ceilings would otherwise block — and the returned reasons array contains
      ONLY the kill-switch reason, nothing else.
    • Each of the three independent ceilings triggering on its own (consecutive disengagements at/above default
      and an explicit override; hourly cap at/above default and an explicit override; session cap at/above
      default and an explicit override) — boundary case for each: exactly at the threshold.
    • Two or more ceilings breached simultaneously: reasons contains ALL of them, not just the first
      (verifies the "collected, not short-circuited" contract from the module's own doc comment).
    • outcome: "merged" alone does NOT bypass the hourly/session cap when a cap is already spent.
    • A non-"disengaged" outcome never contributes to the consecutive-disengagement ceiling regardless of the
      consecutiveDisengagements count passed in (the module trusts the caller's own count; the ceiling check
      itself is gated on outcome === "disengaged").
    • A fully clean candidate (no kill-switch, no ceiling breached) returns { reenter: true, reasons: [] }.

Deliverables

  • New file test/unit/loop-reentry-policy.test.ts (vitest, imports via the engine barrel).
  • No changes to any file under packages/loopover-engine/src/** or packages/loopover-engine/test/**.

Test Coverage Requirements

packages/loopover-engine/src/miner/loop-reentry-policy.ts is inside coverage.include in vitest.config.ts
and therefore IS subject to the 99% Codecov codecov/patch branch-counted gate — today it reports ~0%
because nothing under root test/** exercises it directly. After this PR, npm run test:coverage (run
unsharded locally) should show this file at or near 100% line/branch coverage, including every ceiling's both
arms and the kill-switch short-circuit.

Expected Outcome

loop-reentry-policy.ts's already-real, already-tested re-entry ceilings become visible to Codecov, so a
future PR that changes this file is actually gated on real coverage instead of a blind spot — closing a
coverage gap in the exact module this repo's own comments flag as the top slop-at-scale risk for the miner
subsystem.

Links & Resources

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