Skip to content

Surface monthly AI usage limit errors across Studio Code surfaces - #4310

Merged
sejas merged 1 commit into
trunkfrom
claude/studio-monthly-limit-errors-e8e82a
Jul 23, 2026
Merged

Surface monthly AI usage limit errors across Studio Code surfaces#4310
sejas merged 1 commit into
trunkfrom
claude/studio-monthly-limit-errors-e8e82a

Conversation

@youknowriad

Copy link
Copy Markdown
Contributor

Related issues

How AI was used in this PR

Investigated, implemented, and tested with Claude Code, including live simulation of the 429 responses against a local fake proxy. Reviewed by the author.

Proposed Changes

When a user hits their monthly AI usage limit, the Studio Code agent silently stopped replying: the WordPress.com proxy's 429 was classified as a transient error and retried with backoff, and the final failure never reached the UI — the spinner just stopped with no message.

This PR makes hitting the limit fail fast and communicate clearly, consistently across every surface:

  • No pointless retries: a 429 from the WordPress.com proxy (always the monthly cap there) now fails the turn immediately instead of burning ~15s of doomed retries. 429s on a user-supplied Anthropic API key keep retrying, since those are genuine transient rate limits.
  • Errors are part of the conversation: a failed turn now renders an in-flow marker in the transcript — like the existing "Interrupted by you" marker — in the desktop app, the desktop agentic UI, and studio ui. The error is persisted on the session's turn_closed entry, so the marker survives reload. Non-cap errors show their actual message instead of nothing.
  • Actionable, consistent copy: all surfaces share the same wording — "You've reached your monthly AI usage limit. It resets on <date>." — with the reset date fetched from the account's quota (the studio ui server gained a small quota proxy route for this). The CLI shows the same notice inline.

Testing Instructions

  1. npm run cli:build
  2. Start a fake proxy that returns the cap response:
    node -e 'require("http").createServer((q,s)=>{s.writeHead(429,{"Content-Type":"application/json"});s.end(JSON.stringify({type:"error",error:{type:"rate_limit_error",message:"Number of requests has exceeded your monthly limit."}}))}).listen(8931)'
  3. Point any surface at it with WPCOM_AI_PROXY_BASE_URL=http://127.0.0.1:8931:
    • Desktop: WPCOM_AI_PROXY_BASE_URL=http://127.0.0.1:8931 npm start, open a site → Studio Code, send a message.
    • Local UI: npm run build:local -w @studio/ui, then WPCOM_AI_PROXY_BASE_URL=http://127.0.0.1:8931 node --experimental-wasm-jspi apps/cli/dist/cli/main.mjs ui, send a message.
    • CLI: WPCOM_AI_PROXY_BASE_URL=http://127.0.0.1:8931 node --experimental-wasm-jspi apps/cli/dist/cli/main.mjs code, send a message.
  4. Verify the turn fails immediately (single request, no retry stall) and the usage-limit notice appears in the conversation flow with your account's reset date. Reload the session and verify the marker is still there.

⚠️ Visual change: the in-flow error marker needs human review in light + dark mode (verified in the browser UI in both schemes; the desktop renderer uses the equivalent --color-frame-error token).

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

🤖 Generated with Claude Code

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@wpmobilebot

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 77194d8 vs trunk

app-size

Metric trunk 77194d8 Diff Change
App Size (Mac) 1362.04 MB 1362.06 MB +0.02 MB ⚪ 0.0%

site-editor

Metric trunk 77194d8 Diff Change
load 1080 ms 1072 ms 8 ms ⚪ 0.0%

site-startup

Metric trunk 77194d8 Diff Change
siteCreation 7000 ms 7021 ms +21 ms ⚪ 0.0%
siteStartup 2354 ms 2349 ms 5 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@sejas sejas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on both UIs and CLI. It works as expected. Thanks for adding a handler for the cost cap error.

Classic Agentic CLI
Image Image  Image
@sejas
sejas merged commit 43fa8cb into trunk Jul 23, 2026
14 checks passed
@sejas
sejas deleted the claude/studio-monthly-limit-errors-e8e82a branch July 23, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants