feat(engine): per-tenant resource quota evaluation - #5801
Conversation
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 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 #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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Tip 🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩 ✅ LoopOver review result - approve/merge recommendedReview updated: 2026-07-14 18:11:16 UTC
✅ Suggested Action - Approve/Merge
Review summary Nits — 5 non-blocking
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 LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
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:allowed: truewith per-dimension headroom;allowed: 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 --noEmitclean on the changed files).