Skip to content

feat: forward account rate limits to clients as session metadata - #426

Open
ortwinvanderstappen wants to merge 1 commit into
agentclientprotocol:mainfrom
ortwinvanderstappen:feat/forward-account-rate-limits
Open

feat: forward account rate limits to clients as session metadata#426
ortwinvanderstappen wants to merge 1 commit into
agentclientprotocol:mainfrom
ortwinvanderstappen:feat/forward-account-rate-limits

Conversation

@ortwinvanderstappen

@ortwinvanderstappen ortwinvanderstappen commented Aug 22, 2026

Copy link
Copy Markdown

What

account/rateLimits/updated is already handled: the snapshot is stored in
sessionState.rateLimits and rendered by /status via formatRateLimitLines.
But the handler returns null, so nothing reaches the client — the numbers are
only visible if the user types a command.

This forwards them as session metadata too, using the existing
createCodexSessionInfoUpdate helper.

Why

It makes usage indicators free to build. A client that wants to show how much of
the plan is left has no way to learn it from the stream today, so it has to spawn
its own codex app-server and poll account/rateLimits/read — a second Codex
process and a duplicate request per refresh, for data the adapter already
receives, parses and keeps.

Forwarding it removes both: no extra process, no extra requests, no polling
machinery, and the figures update exactly when Codex says they changed.

Nothing is removed. /status keeps working, since the state is still recorded.

Change

One case in src/CodexEventHandler.ts:

             case "account/rateLimits/updated":
                 this.handleRateLimitsUpdated(notification.params);
-                return null;
+                return this.createCodexSessionInfoUpdate({
+                    rateLimits: notification.params.rateLimits,
+                });

Clients see the snapshot under _meta.codex.rateLimits, the same _meta.codex
convention as the other codex-specific session metadata.

Tests

src/__tests__/CodexACPAgent/rate-limit-events.test.ts — one snapshot of what
the client receives, so the wire format is visible in review.

  • npm run typecheck — clean
  • npx vitest run — 440 passed, 28 skipped, nothing else affected

@ortwinvanderstappen
ortwinvanderstappen force-pushed the feat/forward-account-rate-limits branch from 5ce4743 to 172549e Compare August 22, 2026 16:07
`account/rateLimits/updated` was already handled -- the snapshot is stored in
`sessionState.rateLimits` and rendered by `/status` -- but the handler returned
null, so nothing reached the client and the numbers were only visible if the
user typed a command.

Forward them as session metadata too, via the existing
createCodexSessionInfoUpdate helper, so clients see the snapshot under
`_meta.codex.rateLimits`.

This makes usage indicators free to build. A client that wants to show how much
of the plan is left otherwise has to spawn its own `codex app-server` and poll
`account/rateLimits/read`: a second Codex process and a duplicate request per
refresh, for data the adapter already receives, parses and keeps.

/status keeps working, since the state is still recorded.
@ortwinvanderstappen
ortwinvanderstappen force-pushed the feat/forward-account-rate-limits branch from 172549e to ee85ba9 Compare August 22, 2026 16:07
@ortwinvanderstappen
ortwinvanderstappen marked this pull request as ready for review August 22, 2026 16:16
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