Skip to content

feat: push account rate limits as numbers in the shape of the quotas RFD - #814

Open
alex09x wants to merge 1 commit into
agentclientprotocol:mainfrom
alex09x:feat/quota-numbers
Open

alex09x wants to merge 1 commit into
agentclientprotocol:mainfrom
alex09x:feat/quota-numbers

Conversation

@alex09x

@alex09x alex09x commented Nov 27, 2026

Copy link
Copy Markdown

What

The adapter already keeps the Codex rate limits of each session (account/rateLimits/updated), but a client can only see them as /status text. This pushes them as numbers.

When the app-server reports changed rate limits, the adapter sends _quota/update with the session's sessionId and a full snapshot of pools and meters. The shape and the mapping are the ones the quotas & limits RFD describes for Codex: agentclientprotocol/agent-client-protocol#2316

{
  "sessionId": "sess_abc123",
  "updatedAt": "2026-10-06T13:10:00.000Z",
  "pools": [
    {"id": "codex", "meters": [
      {"id": "primary", "usedPercent": 42, "window": "PT5H", "resetsAt": "2026-10-06T18:00:00.000Z"},
      {"id": "secondary", "usedPercent": 17, "window": "P7D", "resetsAt": "2026-10-11T09:00:00.000Z"}
    ]},
    {"id": "credits", "label": "Credits", "state": "available", "meters": [
      {"id": "balance", "remaining": {"value": "118.5", "unit": "credits"}}
    ]}
  ]
}
  • One pool per rate-limit bucket (limitId), with the primary and secondary windows as meters; a credits pool for the balance and the per-user spend cap.
  • Only values Codex reported are set; nothing is computed.
  • The initialize response advertises _meta.quota: {} (v1 and v2). The client sends nothing and only listens.
  • An unchanged snapshot is not sent again. updatedAt never decreases within the process.

When the RFD lands, the same snapshot becomes the quota_update session update and only the message name changes.

The wire contract is in docs/quota.md.

Why this shape

Issue #227 asks for the rate limits over ACP instead of /status text, and #334, #426 and #524 propose three different interim shapes (on usage_update, as session metadata, as a vendor notification). The RFD warns against putting quota on usage_update, whose used is context occupancy. This PR uses the RFD's own snapshot shape, so a client can parse it once for Codex now and for every agent later.

We use it in an orchestrator that picks the agent and the model for each run by the remaining weekly limits of Claude Code and Codex. Claude's adapter already sends its numbers (_claude/rateLimit on usage_update); for Codex we read account/rateLimits/read ourselves today.

Tests

  • QuotaSnapshot.test.ts: the mapping (file snapshot), only reported values, durations, monotonic updatedAt.
  • CodexAcpClient.test.ts: a changed update is pushed as _quota/update, an identical one is not.
  • Initialize expectations and the recorded scenario initialize responses include quota: {}; the scenario baseline comparison lists it as a feature change.
  • npm run typecheck and npm test: 2806 passed.

The adapter keeps the Codex rate limits of each session, but clients only
see them as /status text. Push them as numbers instead: when the
app-server reports changed rate limits, send `_quota/update` with the
session id and a full snapshot of pools and meters, shaped and mapped as
the quotas & limits RFD (agentclientprotocol/agent-client-protocol#2316)
describes for Codex. The initialize response advertises `_meta.quota`.
An unchanged snapshot is not sent again, and `updatedAt` never
decreases.

When the RFD lands, the same snapshot becomes the `quota_update`
session update.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant