feat(miner): throttle discovery concurrency as rate-limit budget drops - #5467
Conversation
The fanout already recorded GitHub's x-ratelimit-remaining but never slowed its own concurrent fetching in response, so a discover run could sprint at full concurrency straight into a 403. Add a pure resolveThrottledConcurrency helper that maps the recorded remaining budget to an allowed in-flight concurrency (full speed when unknown or above the high-water mark, serialized at/below the low-water mark, scaling linearly in between), and make mapWithConcurrency park its pooled workers against that live limit so effective concurrency tapers off as the budget approaches zero. Thresholds are options-configurable with sensible defaults. Only decides how many requests run; never changes which docs are fetched or how a policy verdict is derived. Closes JSONbored#4844
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5467 +/- ##
=======================================
Coverage 94.71% 94.71%
=======================================
Files 555 556 +1
Lines 44526 44546 +20
Branches 14664 14664
=======================================
+ Hits 42172 42192 +20
Misses 1619 1619
Partials 735 735
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Tip 🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩 ✅ Gittensory review result - approve/merge recommendedReview updated: 2026-07-12 21:33:02 UTC
✅ Suggested Action - Approve/Merge
Review summary Nits — 5 non-blocking
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
[BETA] Chat with GittensoryAsk Gittensory a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://gittensory.aethereal.dev/docs/gittensory-commands 🟩 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 Gittensory, a quiet PR intelligence layer for OSS maintainers.
|
Summary
x-ratelimit-remaining(for telemetry) but nothing slowed its own concurrent fetching in response — adiscoverrun could sprint at full concurrency straight into a403(Throttle discovery concurrency when rate-limit remaining gets low #4844).resolveThrottledConcurrency(baseConcurrency, rateLimitRemaining, lowWaterMark, highWaterMark)helper (packages/gittensory-miner/lib/discovery-throttle.js) that maps the recorded remaining budget to an allowed in-flight concurrency: full speed when the budget is unknown or at/above the high-water mark, serialized to a single request at/below the low-water mark, scaling linearly in between.mapWithConcurrencypool so each worker parks against a live limit derived fromsummary.rateLimitRemainingas it is updated by each response — so effective concurrency tapers off as the budget approaches zero instead of continuing at full speed. The initial burst still runs at the configured concurrency (the budget is unknown until the first response), then sustained concurrency backs off.rateLimitLowWaterMark/rateLimitHighWaterMark) with sensible defaults (50 / 250).Scope
type(scope): short summaryConventional Commit format.CONTRIBUTING.mdand does not reintroduce GitHub Pages, VitePress,site/, orCNAME.Validation
git diff --checknpm run typecheck(afternpm --workspace @jsonbored/gittensory-engine run build, as CI does)npm run test:coverage— verified the changed files at 100% line + branch coverage locally via the v8 JSON report:discovery-throttle.jsis fully covered, and every changed/added line inopportunity-fanout.js(the newdelay, the dynamicmapWithConcurrency,liveConcurrencyResolver, thenormalizeOptionsthreshold wiring, and both call sites) is covered — the remaining uncovered lines in that large file are all pre-existing and outside this diff.resolveThrottledConcurrencyacross every branch (unknown budget, at/below low-water, at/above high-water, linear mid-band, custom marks);mapWithConcurrencyfor the live cap, mid-run taper, and the real-timer park fallback; plus a fanout integration test that completes a multi-target run under a low remaining budget.If any required check was skipped, explain why:
actionlint,test:workers,build:mcp/test:mcp-pack,ui:openapi:check,ui:lint/ui:typecheck/ui:build, andnpm auditwere not run because this change touches onlypackages/gittensory-miner/**andtest/**— no workflow, worker, MCP, OpenAPI/API, UI, or dependency surface for those jobs to act on. The fullnpm run test:ciruns all of them on CI.Safety
Auth/CORS/session, API/OpenAPI/MCP, and UI safety boxes are not applicable — this PR changes none of those surfaces. The
mapWithConcurrencyexport is a small internal utility surfaced only so its dynamic-concurrency behavior can be unit-tested deterministically.