Skip to content

fix: CreditLedger rate limits tracked but never enforced in factory #14

Closed

Description

@stackbilt-admin

CodeBeast Audit Finding — P1 HIGH

Severity: P1 — High
Category: Feature Gap / Correctness
Files: utils/credit-ledger.ts, factory.ts

Problem

CreditLedger implements full rate limit tracking:

  • RPM (requests per minute)
  • RPD (requests per day)
  • TPM (tokens per minute)
  • TPD (tokens per day)
  • Auto-reset stale windows
  • checkRateLimit() method

But LLMProviderFactory.generateResponse() never calls checkRateLimit() before dispatching a request. The tracking infrastructure exists but is purely decorative — rate limits are observed but never enforced.

Current Flow

Request → buildProviderChain() → check circuit breaker → send request
                                                    ↑ no rate limit check

Expected Flow

Request → buildProviderChain() → check circuit breaker → check rate limit → send request
                                                                        ↓ (exceeded)
                                                               skip to next provider

Impact

  • Providers get hammered past their rate limits
  • 429s trigger retries and circuit breaker degradation unnecessarily
  • Budget alerts fire but don't prevent overspend
  • The feature exists in docs/types but is inert

Fix

  1. Add checkRateLimit(providerName) call in the factory's provider loop, before generateResponse()
  2. If rate limit exceeded, skip to next provider in chain (same as circuit breaker open behavior)
  3. After successful response, record the usage against rate limit windows

🤖 Filed by CodeBeast audit

Activity

  1. added
    bug
    P1-high
    audit
    on Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1-highauditbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions