Skip to content

feat(engine): per-tenant resource quota evaluation - #5801

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
lourincedaging0-commits:feat-tenant-quota
Jul 14, 2026
Merged

feat(engine): per-tenant resource quota evaluation#5801
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
lourincedaging0-commits:feat-tenant-quota

Conversation

@lourincedaging0-commits

Copy link
Copy Markdown
Contributor

Closes #4796. Adds a pure, deterministic per-tenant quota evaluator (packages/loopover-engine/src/tenant-quota.ts) for the Rent-a-Loop path, mirroring the governor's existing pure rate-limit calculator.

evaluateTenantQuota(usage, quota) takes one tenant's already-metered usage and their allocation (compute units, wall-clock ms, max concurrent loops — the quota the rental ledger #4792 resolves) and returns a decision:

  • within quotaallowed: true with per-dimension headroom;
  • exhaustedallowed: false, the first exhausted dimension (compute → time → concurrency precedence), and a clear, user-facing reason (acceptance 1: a tenant over quota is stopped cleanly with the correct explanation).

Tenant isolation (acceptance 2): the function reads only the tenant it's handed and holds no shared state, so one tenant hitting its quota has no effect on another's decision — verified by a test evaluating an over-quota and an under-quota tenant independently. All numeric inputs are normalized (non-finite/negative → 0) so a decision can never be NaN or negative.

Computes a decision only — no usage storage, metering, or loop-stopping (enforcement wiring is a separate, maintainer-owned concern). Pure engine module, no IO. 100% statements/branches/functions/lines on the new module (verified locally: vitest coverage + engine build + tsc --noEmit clean on the changed files).

Adds a pure, deterministic per-tenant quota evaluator for the Rent-a-Loop path (JSONbored#4796, part of JSONbored#4778):
given one tenant's already-metered usage and their allocation (compute units, wall-clock time, concurrent
loops), it decides whether the tenant is within quota and, when not, reports the first exhausted dimension
plus a clear, user-facing reason. It reads only the tenant it is handed, so one tenant exhausting its quota
can never observe or affect another tenant's decision. Computes a decision only — no usage storage, metering,
or loop-stopping (that enforcement wiring is separate). Inputs are normalized so a non-finite/negative
usage or quota can never make a decision NaN or negative. Mirrors the governor's pure rate-limit calculator.
Full branch coverage.

Closes JSONbored#4796
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.11%. Comparing base (96b8c42) to head (362ebe4).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5801   +/-   ##
=======================================
  Coverage   95.11%   95.11%           
=======================================
  Files         585      586    +1     
  Lines       46455    46480   +25     
  Branches    14854    14860    +6     
=======================================
+ Hits        44184    44209   +25     
  Misses       1515     1515           
  Partials      756      756           
Flag Coverage Δ
shard-1 43.72% <0.00%> (-0.03%) ⬇️
shard-2 36.22% <100.00%> (+0.03%) ⬆️
shard-3 32.14% <0.00%> (+0.04%) ⬆️
shard-4 32.89% <0.00%> (+0.05%) ⬆️
shard-5 31.63% <0.00%> (-0.02%) ⬇️
shard-6 44.49% <0.00%> (-0.06%) ⬇️

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

Files with missing lines Coverage Δ
packages/loopover-engine/src/tenant-quota.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@loopover-orb loopover-orb Bot added the gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. label Jul 14, 2026
@loopover-orb

loopover-orb Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Tip

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

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-14 18:11:16 UTC

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

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
Adds a pure, side-effect-free per-tenant quota evaluator mirroring the existing governor rate-limit/budget-cap style, with fixed compute→time→concurrency precedence, input normalization, and a decision object with headroom. Logic is correct: `>=` boundary is consistently applied, normalization prevents NaN/negative outputs, and the zero-allocation edge case is handled and tested. Test suite covers all three exhausted-dimension paths, precedence ordering, normalization of non-finite/negative inputs, the zero-quota edge, and tenant isolation — matching the 100% coverage claim. This is a clean, narrowly-scoped, well-documented addition that closes #4796 without touching enforcement wiring.

Nits — 5 non-blocking
  • The zero-quota test (test/unit/tenant-quota.test.ts) only asserts `exceeded === 'compute'` — worth also asserting `remaining` is all-zero and `reason` is non-null for full boundary coverage.
  • index.ts is flagged as a long file (605 lines) by the size-smell check; consider whether re-export barrels like this should be split, though this PR only adds 7 lines to it.
  • The exhaustive `switch` in `quotaReason` (tenant-quota.ts) relies on TS exhaustiveness rather than a default branch — fine given the closed `QuotaDimension` union, but worth a `never` assertion if the union ever grows.
  • Add a boundary-focused assertion for the zero-quota case to lock in that `remaining` and `reason` behave correctly at the exact edge.
  • Since this mirrors governor/rate-limit.ts and budget-cap.ts closely, consider a short shared JSDoc note in the module header linking all three for future readers navigating the quota/rate-limit family.
Signal Result Evidence
Code review ✅ No blockers 1 reviewer
Linked issue ✅ Linked #4796
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: 0 registered-repo PR(s), 0 merged, 0 issue(s).
Contributor context ❌ No public Gittensor match lourincedaging0-commits; not a blocker.
Gate result ✅ Passing No configured blocker found.
Improvement ✅ Minor risk: clean · value: minor — Code changes are accompanied by test evidence. LLM value judgment: moderate — The PR delivers a focused, fully-tested pure decision function that directly closes issue #4796 and slots cleanly into the existing governor-style quota/rate-limit module family without expanding scope into enforcement wiring.
Review context
  • Author: lourincedaging0-commits
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: not available
  • Contributor context: Public profile only; not a blocker.
  • 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.
[BETA] Chat with Gittensory

Ask 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.

  • @gittensory ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @gittensory chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @gittensory 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/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 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.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Per-tenant rate limits & quotas

1 participant