Skip to content

Display error max token reached in Studio Code Desktop#4077

Open
katinthehatsite wants to merge 4 commits into
trunkfrom
fix/display-error-when-reaching-limits
Open

Display error max token reached in Studio Code Desktop#4077
katinthehatsite wants to merge 4 commits into
trunkfrom
fix/display-error-when-reaching-limits

Conversation

@katinthehatsite

@katinthehatsite katinthehatsite commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Related issues

Fixes STU-1825

How AI was used in this PR

It was used to implement the feature.

Proposed Changes

This PR ensures that we throw an error when the usage limit is reached in the Studio Code UI.

Testing Instructions

  • Pull the changes from this branch
  • To mock the 429 error, apply this to apps/studio/src/components/studio-code-session/use-agent-run.tsx:
      504                                                              
      505        try {                                                                                         
      506 +        throw new Error( 'API Error: 429 — usage cap exceeded' );                            
      507          await interruptRequestsBySessionRef.current.get( sessionId );                               
      508          const { runId: newRunId } = await getIpcApi().continueAiSession( sessionId, prompt, {
      509            displayMessage,
  • Run npm start
  • Navigate to Studio Code tab for one of the sites
  • Try sending a message
  • Verify that banner appears above the composer with the friendly usage limit message

Currently, it looks like this:

Screenshot 2026-07-06 at 2 35 49 PM

I am not sure on the design so leaving it up for discussion.

I tried to use the meta field below the input field but it was looking like this, which I think was looking even worse:

Screenshot 2026-07-06 at 12 02 41 PM

Pre-merge Checklist

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

@katinthehatsite katinthehatsite self-assigned this Jul 3, 2026
@katinthehatsite katinthehatsite marked this pull request as draft July 3, 2026 15:00
@wpmobilebot

wpmobilebot commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing f981a00 vs trunk

app-size

Metric trunk f981a00 Diff Change
App Size (Mac) 1345.25 MB 1345.25 MB +0.01 MB ⚪ 0.0%

site-editor

Metric trunk f981a00 Diff Change
load 1091 ms 1108 ms +17 ms ⚪ 0.0%

site-startup

Metric trunk f981a00 Diff Change
siteCreation 6489 ms 6515 ms +26 ms ⚪ 0.0%
siteStartup 2387 ms 2390 ms +3 ms ⚪ 0.0%

Results are median values from multiple test runs.

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

@katinthehatsite katinthehatsite requested review from a team and Copilot July 6, 2026 13:44
@katinthehatsite katinthehatsite marked this pull request as ready for review July 6, 2026 13:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a dedicated “usage cap reached” error path for Studio Code Desktop so that HTTP 429 responses from the WordPress.com proxy are surfaced to users as a friendly, actionable message (and shown as a banner above the composer rather than as a generic run error).

Changes:

  • Added a shared isUsageCapError() helper in packages/common to detect usage-cap (429) errors by message pattern.
  • Updated Studio Code session run handling to translate detected 429 errors into a friendly message and expose usageCapReached state to the UI.
  • Rendered a new usage-cap banner above the composer in the Studio renderer; updated CLI UI to reuse the shared helper.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/common/ai/json-events.ts Adds isUsageCapError() helper used by CLI + Desktop to identify usage-cap errors.
apps/studio/src/components/studio-code-session/use-agent-run.tsx Detects usage-cap errors, maps them to a friendly i18n string, and tracks usageCapReached in run state.
apps/studio/src/components/studio-code-session/index.tsx Routes usage-cap messaging to the composer via a new usageCapMessage prop.
apps/studio/src/components/studio-code-session/composer/style.module.css Adds styling for a usage-cap banner above the composer.
apps/studio/src/components/studio-code-session/composer/index.tsx Renders an alert banner when usageCapMessage is set.
apps/cli/ai/ui.ts Replaces inline 429 regex detection with the shared isUsageCapError() helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +49 to +57
const USAGE_CAP_PATTERN = /API Error:\s*429|status code 429|"status":\s*429/i;

/**
* Returns true when an error message indicates the user hit the AI usage cap
* (HTTP 429 from the WordPress.com proxy).
*/
export function isUsageCapError( message: string | undefined | null ): boolean {
return USAGE_CAP_PATTERN.test( message ?? '' );
}
Comment on lines 435 to +440
<div className={ styles.root }>
{ usageCapMessage ? (
<div className={ styles.usageCapBanner } role="alert">
{ usageCapMessage }
</div>
) : null }
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.

3 participants