study-rate-limit

Study: rate-limit and cost telemetry by parsing failed pi request output

Metadata

Statusdone
Assignedagent-738
Created2026-07-25T13:23:45.757563955+00:00
Started2026-07-25T14:08:28.994310343+00:00
Completed2026-07-25T14:20:23.954056145+00:00
Tagsresearch, design, telemetry, openrouter
Tokens3951420 in / 23734 out

Description

Objective

Study how to detect rate-limit / quota / cost-exhaustion failures by parsing the ACTUAL outputs of failed pi-based (LLM) requests, and catalog OpenRouter's real billing/rate-limit surface (free-endpoint requests/day caps, how limits are represented, exact error messages). Output a detector spec + a parsed-failure signal the supervisor and adaptive-parallelism controller can consume.

Research questions

  • Failure taxonomy: enumerate the distinct failure shapes pi/openrouter returns — HTTP 402/429, rate-limit headers (Retry-After, X-RateLimit-*), quota/credit-exhausted bodies, 5xx, timeouts, provider-specific messages. For each: how to detect from the raw response/stream.
  • Where in WG do these surface today? Survey pi-handler stream parsing (src/stream_event.rs, src/graph.rs parse_token_usage, the spawn wrapper in src/commands/spawn/execution.rs), agent exit logs, raw_stream.jsonl. What is currently captured vs lost.
  • OpenRouter specifics: requests/day limits on free endpoints (which models), how the limit is communicated (headers vs body vs docs), credit/balance errors, 429 vs 402 distinction, keyed vs keyless. Use live docs/API.
  • Signal design: a normalized "failure reason" classification (rate-limit / credit-exhausted / auth / transient / hard) emitted from parsed output, with confidence, that the controller can threshold on.
  • Telemetry persistence: where the signal is stored so the controller has history (rolling window of recent failures per provider/model).

Inputs

  • src/stream_event.rs, src/commands/spawn/execution.rs (pi wrapper), src/graph.rs (usage parsing)
  • OpenRouter docs (requests/day, rate limits, errors) — web research
  • Recent real failures in this graph's logs as calibration examples

Deliverable

docs/studies/ratelimit-cost-telemetry-design.md

Validation

  • Design doc committed at docs/studies/ratelimit-cost-telemetry-design.md
  • Concrete taxonomy of pi/openrouter failure outputs with detection rules (string/header/code)
  • Documents OpenRouter free-endpoint requests/day limits and how they are represented, with citations
  • Specifies a normalized failure-reason signal + where it is emitted and stored
  • Maps to the exact WG source locations that would parse/emit it

Depends on

Required by

Log