Skip to content

fix(miner): treat an absent x-ratelimit-remaining header as unknown, not a 0 budget - #9897

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
kai392:fix/9678-ratelimit-absent-header
Jul 29, 2026
Merged

fix(miner): treat an absent x-ratelimit-remaining header as unknown, not a 0 budget#9897
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
kai392:fix/9678-ratelimit-absent-header

Conversation

@kai392

@kai392 kai392 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Closes #9678

What

recordRateLimit in packages/loopover-miner/lib/opportunity-fanout.ts did Number(response.headers.get("x-ratelimit-remaining")). Headers.get() returns null for an absent header, and Number(null) === 0 — which Number.isFinite accepts. So a forge or reverse proxy that doesn't emit x-ratelimit-remaining made the miner record a remaining budget of 0, and the running Math.min pinned it at 0 for the rest of the run. resolveThrottledConcurrency then serialized the entire fan-out to a single in-flight request against a budget that was never reported — defeating the "unknown budget runs at full baseConcurrency" contract discovery-throttle.ts documents. This is reachable in exactly the GitHub-Enterprise/compatible-forge configuration forge-config.ts exists to support.

The fix reads the raw header and skips a null or blank/whitespace-only value before any Number(...) conversion, matching the package's own http-retry.ts remaining != null guard. A genuinely-present "0" (or any finite number) is still recorded; a present-but-non-numeric value is still skipped by Number.isFinite. The x-ratelimit-reset branch is unchanged.

Tests

New cases in test/unit/miner-opportunity-fanout.test.ts: an absent header leaves rateLimitRemaining null (not 0); a blank/whitespace-only header is skipped; a present "0" is still recorded (real exhaustion isn't lost). Verified: 30/30, non-vacuous (the absent + blank cases fail with the fix reverted), tsc --noEmit clean, git diff --check clean.

@kai392
kai392 requested a review from JSONbored as a code owner July 29, 2026 19:32
@loopover-orb

loopover-orb Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-29 19:40:40 UTC

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

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This fixes a real bug: recordRateLimit previously did Number(response.headers.get("x-ratelimit-remaining")) directly, and since Headers.get() returns null for an absent header and Number(null) === 0 (which Number.isFinite accepts), a forge omitting the header would pin rateLimitRemaining to 0 and serialize the whole fan-out via resolveThrottledConcurrency. The fix correctly reads the raw header and guards null/blank before calling Number(), mirroring the existing `remaining != null` pattern already used in http-retry.ts and github-client.ts's recordRateLimit. The three new tests exercise the absent, blank, and genuinely-present-'0' cases and are non-vacuous per the description (fail with the fix reverted), so this is a well-targeted, narrow fix.

Nits — 4 non-blocking
  • opportunity-fanout.ts:212-224 duplicates the same null/blank-guard pattern already present in discovery-index/github-client.ts's recordRateLimit and http-retry.ts's remaining != null check — worth a shared helper someday, though the package-isolation comment in github-client.ts suggests this divergence is intentional.
  • The reset-header parsing on the next line (`Number(response.headers.get("x-ratelimit-reset"))`) has the identical absent-header-becomes-0 latent issue, just masked because `resetSeconds > 0` already filters it out — worth a one-line comment noting why it's safe there, to avoid a future 'fix' attempt on a non-bug.
  • Consider extracting the null/blank-then-parse guard into a small shared utility across opportunity-fanout.ts, http-retry.ts, and github-client.ts's recordRateLimit to prevent this class of bug from recurring elsewhere.
  • A one-line comment on the x-ratelimit-reset line noting why `resetSeconds > 0` already makes it safe against the same Number(null)===0 issue would preempt a redundant future fix.

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 #9678
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: 89 registered-repo PR(s), 43 merged, 7 issue(s).
Contributor context ✅ Confirmed Gittensor contributor kai392; Gittensor profile; 89 PR(s), 7 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The diff mirrors http-retry.ts's null/blank guard by reading the raw header before Number() conversion, leaving rateLimitRemaining untouched when absent/blank while still recording a present '0' and skipping non-numeric values, and the reset branch is untouched. It adds the three required regression tests (absent header -> null, blank -> null, present '0' -> 0), satisfying the deliverables includi

Review context
  • Author: kai392
  • 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: 89 PR(s), 7 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 <question> answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat <question> 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.

🟩 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

@superagent-security

Copy link
Copy Markdown
Contributor

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

…not a 0 budget (JSONbored#9678)

recordRateLimit did `Number(response.headers.get("x-ratelimit-remaining"))`, but headers.get()
returns null for an ABSENT header and Number(null) === 0 (which Number.isFinite accepts). So a
forge/reverse-proxy that omits the header made the miner record a remaining budget of 0, and the
running Math.min pinned it at 0 for the whole run -- resolveThrottledConcurrency then serialized the
entire fan-out to a single in-flight request against a budget that was never reported, defeating the
"unknown budget runs at full concurrency" contract discovery-throttle.ts documents.

Read the raw header and skip a null or blank/whitespace-only value before converting, matching
http-retry.ts's own `remaining != null` guard. A genuinely-present "0" (or any finite number) is
still recorded; a present-but-non-numeric value is still skipped by Number.isFinite. The
x-ratelimit-reset branch is unchanged.

Tests: absent header -> rateLimitRemaining stays null (not 0); a blank header is skipped; a present
"0" is still recorded.

Closes JSONbored#9678
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 29, 2026
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.37%. Comparing base (e3247ed) to head (edf5fd1).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #9897       +/-   ##
===========================================
- Coverage   91.75%   79.37%   -12.39%     
===========================================
  Files         920      282      -638     
  Lines      113064    58775    -54289     
  Branches    27214     8680    -18534     
===========================================
- Hits       103746    46652    -57094     
- Misses       8033    11840     +3807     
+ Partials     1285      283     -1002     
Flag Coverage Δ
backend 100.00% <100.00%> (+4.31%) ⬆️

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

Files with missing lines Coverage Δ
packages/loopover-miner/lib/opportunity-fanout.ts 100.00% <100.00%> (ø)

... and 771 files with indirect coverage changes

@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 dcd70b9 into JSONbored:main Jul 29, 2026
8 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.

miner(discover): a missing x-ratelimit-remaining header is recorded as 0

2 participants