Skip to content

fix(engine): treat an Infinity WIP cap as uncapped, not collapsed to 0 (#8861) - #8945

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
RealDiligent:fix/critical-issue-portfolio-infinity-uncapped-8861
Jul 26, 2026
Merged

fix(engine): treat an Infinity WIP cap as uncapped, not collapsed to 0 (#8861)#8945
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
RealDiligent:fix/critical-issue-portfolio-infinity-uncapped-8861

Conversation

@RealDiligent

Copy link
Copy Markdown
Contributor

Problem

Closes #8861.

packages/loopover-engine/src/portfolio/queue.ts's finiteNonNegativeInt returned 0 for any non-finite value, so nextEligibleItems with globalWipCap: Infinity returned [] — the opposite of "uncapped." This contradicts the codebase's own convention (portfolio-queue-cli.ts: "Unset dimensions stay genuinely uncapped (Infinity), not silently defaulted"). normalizePortfolioCaps in portfolio-queue-manager.ts — which feeds that engine call — performed the identical collapse.

Fix

Both finiteNonNegativeInt and normalizePortfolioCaps now preserve an explicit Infinity as "uncapped" while still coercing finite/absent values exactly as before (truncate, floor at 0, non-finite→0). Downstream the cap is used only in slice(0, cap) and count < cap comparisons, where Infinity correctly means no limit (the selection loop still breaks when items are exhausted).

Tests

  • nextEligibleItems with an Infinity cap returns the eligible items (was []); the prior test that pinned the buggy Infinity → [] behavior is updated to a genuine 0 cap.
  • normalizePortfolioCaps preserves Infinity and still coerces finite/negative values.

Reverting either fix fails its test. git diff --check clean.

@RealDiligent
RealDiligent requested a review from JSONbored as a code owner July 26, 2026 13:58
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

portfolio/queue.ts's finiteNonNegativeInt returned 0 for any non-finite value, so nextEligibleItems with
globalWipCap: Infinity returned [] -- the opposite of 'uncapped' -- contradicting the codebase's own
Infinity=uncapped convention (portfolio-queue-cli.ts). normalizePortfolioCaps in portfolio-queue-manager.ts
(which feeds that engine call) performed the identical collapse. Both now preserve an explicit Infinity as
uncapped while still coercing finite/absent values exactly as before.

Tests: nextEligibleItems with an Infinity cap returns the eligible items (was []); normalizePortfolioCaps
preserves Infinity; the prior test that pinned the buggy Infinity->[] behavior is updated to a genuine 0 cap.
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.86%. Comparing base (f4cf7cc) to head (ab3107a).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8945   +/-   ##
=======================================
  Coverage   93.86%   93.86%           
=======================================
  Files         805      805           
  Lines       80243    80244    +1     
  Branches    24319    24319           
=======================================
+ Hits        75321    75322    +1     
  Misses       3561     3561           
  Partials     1361     1361           
Flag Coverage Δ
backend 95.15% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/loopover-engine/src/portfolio/queue.ts 100.00% <100.00%> (ø)
...ages/loopover-miner/lib/portfolio-queue-manager.ts 100.00% <100.00%> (ø)

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 26, 2026
@loopover-orb

loopover-orb Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-26 14:19:29 UTC

4 files · 1 AI reviewer · no blockers · readiness 95/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR fixes a real bug: `finiteNonNegativeInt` in queue.ts and `normalizePortfolioCaps` in portfolio-queue-manager.ts both collapsed `Number.POSITIVE_INFINITY` to `0`, which meant an intended 'uncapped' WIP setting silently excluded every queue item via the `=== 0` short-circuit in `nextEligibleItems`. The fix correctly special-cases `Infinity` before the `Number.isFinite` check in both call sites, preserving all other coercion behavior (truncation, negative-clamping, NaN→0), and downstream `slice`/`<` comparisons against `Infinity` behave correctly as 'no limit'. Tests are updated to cover both the engine and manager layers, and the previously-buggy pinned test is correctly repointed to a genuine `0` cap case instead of being deleted.

Nits — 3 non-blocking
  • packages/loopover-miner/lib/portfolio-queue-manager.ts:56-58 — the inline `normalize` arrow uses a dense ternary chain that's a bit hard to scan; consider mirroring the engine's `finiteNonNegativeInt`-style early-return function for consistency between the two mirrored implementations.
  • The fix duplicates the same 'preserve Infinity' logic in two files (queue.ts and portfolio-queue-manager.ts) with slightly different styles (early-return vs. ternary) — worth a shared helper or at least matching style if this drifts again.
  • Consider extracting a single shared `normalizeWipCap`/`finiteNonNegativeInt`-equivalent used by both the engine and the miner package to avoid the two implementations diverging again in the future.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #8861
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 309 registered-repo PR(s), 124 merged, 37 issue(s).
Contributor context ✅ Confirmed Gittensor contributor RealDiligent; Gittensor profile; 309 PR(s), 37 issue(s).
Improvement ✅ Minor risk: clean · value: minor
Linked issue satisfaction

Addressed
The diff fixes both finiteNonNegativeInt in queue.ts and normalizePortfolioCaps in portfolio-queue-manager.ts to preserve Infinity as uncapped, and adds a pinning test confirming nextEligibleItems with globalWipCap: Infinity returns eligible items instead of an empty array, matching all three deliverables.

Review context
  • Author: RealDiligent
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, Ruby, TypeScript, Svelte, Cuda, JavaScript, Markdown, MDX
  • Official Gittensor activity: 309 PR(s), 37 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Triage stale or unlinked PRs.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

Decision record
  • action: merge · clause: success
  • config: 03a7f8b529a9 · pack: oss-anti-slop
  • record: 8671e1f2e33b (schema v2, head ab3107a)

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit 6aaea39 into JSONbored:main Jul 26, 2026
8 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 26, 2026
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(engine): portfolio queue.ts collapses the codebase's own "Infinity = uncapped" sentinel to 0

1 participant