feat(miner-governor): local rate-limit token-bucket + jittered-backoff calculator (pure) - #2416
Conversation
|
Warning 🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨 ⏸️ Gittensory review result - manual review recommendedReview updated: 2026-07-02 05:14:15 UTC
⏸️ Suggested Action - Manual Review Review summary Nits — 5 non-blocking
Review context
Contributor next steps
Signal definitions
🟩 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.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2416 +/- ##
=======================================
Coverage 95.93% 95.93%
=======================================
Files 225 226 +1
Lines 25337 25359 +22
Branches 9218 9228 +10
=======================================
+ Hits 24307 24329 +22
Misses 417 417
Partials 613 613
🚀 New features to boost your workflow:
|
cec8a61 to
b52c154
Compare
b52c154 to
04e6b13
Compare
04e6b13 to
d0d0a9f
Compare
d0d0a9f to
22e1256
Compare
22e1256 to
9f06ab0
Compare
9f06ab0 to
f8a4506
Compare
def4940 to
e973f2a
Compare
e973f2a to
b452a9f
Compare
b452a9f to
38b3472
Compare
38b3472 to
0f79737
Compare
…backoff calculator
0f79737 to
60f7ffd
Compare
Summary
Adds the Governor's pure rate-limit + jittered-backoff math to the shared engine package as
packages/gittensory-engine/src/governor/rate-limit.ts. Given a rolling-window bucket and a clock reading it decides whether an event is allowed and, when blocked, how long to wait; and it computes a jittered exponential backoff from an injected random source. It computes numbers only — no storage, no scheduling, and it does not itself gate any write action (that enforcement wiring is a separate, maintainer-owned concern).Closes #2327
Deliverables
LocalRateBucket/LocalRateLimitConfig/LocalRateLimitDecisiontypes, andevaluateLocalRateLimit(bucket, config, nowMs)returning{ allowed, remaining, resetAtMs, retryAfterMs }. A fully elapsed window is treated as reset, so a stale bucket at its limit is permitted again in the new window.jitteredBackoffMs(baseMs, attempt, randomFn)— exponential basebaseMs * 2 ** attemptscaled by a multiplicative jitter factor in the band[0.5, 1.5)drawn from an injectedrandomFn(neverMath.random(), so tests stay deterministic). The attempt is clamped non-negative and bounded so it cannot overflow to Infinity, and an out-of-contract random draw is clamped into the band.RateLimitConfig/RateLimitDecisioninsrc/auth/rate-limit.ts(that one is a Cloudflare Durable Object and is not reusable in the fully-local miner); this variant is millisecond-based and state-free.packages/gittensory-engine/src/index.ts).Scope
type(scope): short summaryConventional Commit format.CONTRIBUTING.md; stays insidepackages/gittensory-engine/and does not touchsite/,CNAME, or removed tooling.Validation
[0.5, 1.5)jitter band across a swept attempt range, negative/fractional attempt clamping, the exponent cap against overflow, a negative base, and out-of-contract random clamping.npm run build --workspace @jsonbored/gittensory-enginesucceeds.test/unit/governor-rate-limit.test.ts).