Add bounded provider-wide request scheduler with queue and 429 backpressure #73

Open
opened 2026-09-12 19:54:49 +00:00 by nsaspy · 0 comments
Owner

Goal

Make llm-log an admission/scheduling layer for shared LLM credentials instead of allowing every client request to immediately consume an upstream connection.

First slice

  • Enforce a provider-wide maximum active request count.
  • Maintain a bounded FIFO queue for excess requests.
  • Give each queued request a maximum queue-wait budget.
  • Admit queued requests as active slots free up.
  • Return 429 Too Many Requests with Retry-After when the queue is full or the queue-wait budget is exhausted.
  • Never start an upstream request after its queue deadline has expired.
  • Release slots on success, upstream failure, and client disconnect during an active relay.
  • Keep the mechanism generic per provider; do not special-case Z.AI.

Transparent streaming behavior

The normal proxy path must remain transparent. It must not emit SSE response-body bytes while queued because that would commit the downstream HTTP status before the upstream responds. Opt-in queue-status/SSE behavior for smart clients is tracked separately in #73.

Configuration

Add explicit scheduler settings with safe defaults, including max active requests, max queue depth, queue timeout, and retry-after.

Tests

Cover at least:

  • direct admission below the active limit;
  • FIFO admission after a slot is released;
  • queue-full 429;
  • queue-timeout 429;
  • Retry-After header;
  • slot release on upstream error;
  • no active-count leak;
  • per-provider isolation.

This is the first implementation slice before provider/client fingerprint profiles.

## Goal Make llm-log an admission/scheduling layer for shared LLM credentials instead of allowing every client request to immediately consume an upstream connection. ## First slice - Enforce a provider-wide maximum active request count. - Maintain a bounded FIFO queue for excess requests. - Give each queued request a maximum queue-wait budget. - Admit queued requests as active slots free up. - Return `429 Too Many Requests` with `Retry-After` when the queue is full or the queue-wait budget is exhausted. - Never start an upstream request after its queue deadline has expired. - Release slots on success, upstream failure, and client disconnect during an active relay. - Keep the mechanism generic per provider; do not special-case Z.AI. ## Transparent streaming behavior The normal proxy path must remain transparent. It must not emit SSE response-body bytes while queued because that would commit the downstream HTTP status before the upstream responds. Opt-in queue-status/SSE behavior for smart clients is tracked separately in #73. ## Configuration Add explicit scheduler settings with safe defaults, including max active requests, max queue depth, queue timeout, and retry-after. ## Tests Cover at least: - direct admission below the active limit; - FIFO admission after a slot is released; - queue-full 429; - queue-timeout 429; - `Retry-After` header; - slot release on upstream error; - no active-count leak; - per-provider isolation. This is the first implementation slice before provider/client fingerprint profiles.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nsaspy/llm-log#73
No description provided.