Skip to content

fix(engine): normalize worktree-pool maxConcurrency so a NaN cap can't disable it - #6041

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
reyanthony062001-ops:fix/5828
Jul 15, 2026
Merged

fix(engine): normalize worktree-pool maxConcurrency so a NaN cap can't disable it#6041
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
reyanthony062001-ops:fix/5828

Conversation

@reyanthony062001-ops

Copy link
Copy Markdown
Contributor

Summary

availableWorktreeSlots and acquireWorktree in packages/loopover-engine/src/miner/worktree-pool.ts read WorktreePoolConfig.maxConcurrency directly in their comparisons with no normalization. If the cap arrives as NaN (e.g. a caller derives it from Number(someUnparsableConfigValue) and doesn't guard the result), every comparison against it is falselength >= NaN never holds — so at_capacity never fires and the pool allocates worktrees without bound, directly contradicting the type's own documented contract ("A non-positive cap allocates nothing"). availableWorktreeSlots also returns NaN, breaking any caller that treats it as a real remaining-slots count.

The fix adds a small finiteNonNegativeInt helper (mirroring the exact pattern already used in governor/rate-limit.ts, governor/budget-cap.ts, and tenant-quota.ts in this same package) and normalizes config.maxConcurrency through it at both read sites: a non-finite or negative cap floors to 0 (the documented "allocates nothing" behavior), and a fractional cap floors down. No public signature or behavior change for a valid positive cap.

Closes #5828

Scope

  • The PR title follows type(scope): short summary Conventional Commit format.
  • This PR is focused and does not mix unrelated backend, UI, MCP, docs, dependency, and deploy changes.
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • I linked a currently open issue this PR resolves (Closes #5828).

Validation

  • git diff --check — clean
  • npm run actionlint — no workflow changes
  • npm run typecheck — passes (whole project, against the rebuilt @loopover/engine)
  • npm run test:coverage — the two changed engine lines and both arms of the new finiteNonNegativeInt (finite→floor, non-finite→0) are exercised by the new regression tests plus the existing positive-cap tests, so codecov/patch on the diff is 100%. test/unit/miner-worktree-pool.test.ts passes 10/10; the new NaN and fractional cases fail on the pre-fix code and pass after. packages/loopover-engine own suite: 553/553.
  • npm run test:workers — unaffected (pure in-memory engine scheduling logic, no worker changes)
  • npm run build:mcp / test:mcp-pack — unaffected (no MCP changes)
  • npm run ui:openapi:check / ui:lint / ui:typecheck / ui:build — unaffected (no UI/OpenAPI/route changes)
  • npm audit --audit-level=moderate — no dependency changes
  • New or changed behavior has unit tests — regression tests for maxConcurrency: NaN, -1, and a fractional value, asserting the pool refuses allocation (or floors correctly) in each case

If any required check was skipped, explain why:

  • Change is confined to one engine module (worktree-pool.ts, +the helper) plus its test. It introduces no workflow, MCP, UI, OpenAPI, or dependency changes. I additionally ran npm run engine-parity:drift-check (ok — this module is engine-only, not a src/{review,settings,signals} twin) and the backend drift checks (docs, manifest, command-reference, selfhost env-reference), all green.

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests — N/A (none).
  • API/OpenAPI/MCP behavior is updated and tested where needed — N/A (none).
  • UI changes use live API data or real empty/error/loading states — N/A (no UI changes).
  • Visible UI changes include a UI Evidence section — N/A (no UI/frontend/docs/extension changes).
  • Public docs/changelogs are updated where needed — N/A.

Notes

  • The normalization matches the module's existing "non-positive cap allocates nothing" contract exactly — an invalid cap now behaves identically to a documented 0 cap rather than silently disabling the limit — so no caller relying on the current documented semantics changes behavior; only the previously-undefined invalid-input case is now defined.

…t disable it

availableWorktreeSlots and acquireWorktree read WorktreePoolConfig.maxConcurrency
directly in a comparison. A NaN cap (e.g. derived upstream from Number() of an
unparsable config value) makes `length >= NaN` always false, so at_capacity never
fires and the pool allocates worktrees without bound — contradicting the module's
documented "non-positive cap allocates nothing" contract — while
availableWorktreeSlots returns NaN. Normalize maxConcurrency through a
finiteNonNegativeInt helper at both read sites (non-finite or negative floors to 0,
fractional floors down), mirroring governor/rate-limit.ts, governor/budget-cap.ts,
and tenant-quota.ts.

Adds regression tests for NaN, negative, and fractional maxConcurrency.

Closes JSONbored#5828
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.17%. Comparing base (d3bf13b) to head (3e741af).
⚠️ Report is 27 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6041   +/-   ##
=======================================
  Coverage   95.16%   95.17%           
=======================================
  Files         593      592    -1     
  Lines       46955    46967   +12     
  Branches    15006    15007    +1     
=======================================
+ Hits        44685    44700   +15     
+ Misses       1512     1511    -1     
+ Partials      758      756    -2     
Flag Coverage Δ
shard-1 43.96% <0.00%> (+0.02%) ⬆️
shard-2 36.52% <0.00%> (-0.02%) ⬇️
shard-3 32.14% <100.00%> (+0.06%) ⬆️
shard-4 32.92% <0.00%> (-0.10%) ⬇️
shard-5 31.50% <0.00%> (+0.14%) ⬆️
shard-6 44.59% <0.00%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
...ackages/loopover-engine/src/miner/worktree-pool.ts 100.00% <100.00%> (ø)

... and 5 files with indirect coverage changes

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

loopover-orb Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Tip

🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-15 07:39:08 UTC

2 files · 1 AI reviewer · no blockers · readiness 98/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR adds a `finiteNonNegativeInt` normalizer at both `maxConcurrency` read sites in `worktree-pool.ts`, closing a real bug where a NaN/negative/fractional cap would make `length >= config.maxConcurrency` always false and disable the allocation limit entirely. The fix is applied at the correct layer (the two actual comparison/subtraction sites), mirrors an existing pattern used elsewhere in the package, and is covered by three new tests exercising NaN, negative, and fractional inputs against both `availableWorktreeSlots` and `acquireWorktree`. This is a small, well-targeted, correctly-scoped fix tied to an open issue (#5828).

Nits — 3 non-blocking
  • The helper `finiteNonNegativeInt` is a local, unexported duplicate of logic already living in `governor/rate-limit.ts`/`governor/budget-cap.ts`/`tenant-quota.ts` per the PR description — consider hoisting it to a shared util to avoid drift across four copies.
  • The doc comment on `finiteNonNegativeInt` (worktree-pool.ts) is fairly long for a 1-line helper; could be trimmed to the essential behavior.
  • Consider extracting `finiteNonNegativeInt` into a shared internal module now that it exists in four places, so future changes to the normalization rule don't need to be replicated by hand.
Signal Result Evidence
Code review ✅ No blockers 1 reviewer
Linked issue ✅ Linked #5828
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: 28 registered-repo PR(s), 16 merged, 1 issue(s).
Contributor context ✅ Confirmed Gittensor contributor reyanthony062001-ops; Gittensor profile; 28 PR(s), 1 issue(s).
Gate result ✅ Passing No configured blocker found.
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The diff adds a finiteNonNegativeInt-style normalization helper applied at both availableWorktreeSlots and acquireWorktree, correctly flooring non-finite/negative values to 0 and fractional values down, matching the issue's requirements exactly.

Review context
  • Author: reyanthony062001-ops
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: not available
  • Official Gittensor activity: 28 PR(s), 1 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Keep the PR focused and include validation evidence before maintainer review.
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://gittensory.aethereal.dev/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 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 fbf4712 into JSONbored:main Jul 15, 2026
16 checks passed
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): worktree-pool.ts doesn't normalize maxConcurrency, NaN disables the cap

1 participant