AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

[Bug]: TokenBucketRateLimiter Hangs Forever When One Request Exceeds The Token Bucket; SlidingWindowRateLimiter Lets It Straight Through

Two rate limiter implementations in llama-index-core mishandle oversize single requests: TokenBucketRateLimiter deadlocks when num_tokens exceeds token_burst; SlidingWindowRateLimiter silently allows the request to exceed the configured limit.

criticalConfidence 95%Llama_indexllama-index-coreIndexingDocument ProcessingAffected V0.14.25

Origin Analysis

Both limiters fail to validate that a single acquire(num_tokens) request is within the configured burst/capacity before entering their sleeping loops. TokenBucketRateLimiter waits indefinitely because the bucket can never accumulate enough tokens; SlidingWindowRateLimiter's empty-window path returns zero wait without checking the request's size against tokens_per_minute + token_burst.
import threading from llama_index.core.rate_limiter import TokenBucketRateLimiter, SlidingWindowRateLimiter tb = TokenBucketRateLimiter(tokens_per_minute=100) t = threading.Thread(target=lambda: tb.acquire(num_tokens=200), daemon=True) t.start() t.join(timeout=3) print(t.is_alive()) # True - still blocked, and it will never return sw = SlidingWindowRateLimiter(tokens_per_minute=100) sw.acquire(num_tokens=200) # returns at once, strict cap exceeded

Fixing Code Block

Edge Case Audit

This changes behavior from deadlock/silent-pass to raising an exception, which may break callers that do not expect or handle ValueError; ensure error handling is added. The capacity check in TokenBucketRateLimiter reads self.token_burst outside the lock; if token_burst is ever made mutable, move the check inside the lock to avoid a race. SlidingWindowRateLimiter's effective capacity is assumed to be tokens_per_minute + token_burst; verify against the actual sliding window implementation and add unit tests for boundary values. In concurrent scenarios, multiple threads may still race around the capacity edge; consider a global admission gate if strict enforcement is required. Rollback recommendation: keep the old behavior behind a configuration flag or monitor exception rates before full rollout, and downgrade to 0.14.25 if unexpected client failures occur.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state