fix(chat): offer the account switch when a Claude model limit fails a turn

KI
2h ago
+493-252

Summary

  • A Claude turn refused with "You've hit your Fable limit" now counts as a usage limit: it shows the composer notice with the account pill and Resume in place of a red "Task interrupted" card.

  • The usage-limit failure card (for turns already stored as failed) now has the same account pill and menu as the composer notice.

  • The account pill and menu move out of UsageLimitNotice into a shared UsageAccountMenu.

  • Picking another model, or another login, while the notice is up now resumes the session: queued messages go out in order, and with nothing queued the continue prompt is sent, as the Resume button does.

Why / Context

A per-model limit ("You've hit your Fable limit") did not match our usage-limit wording check, which only knew "hit your limit" and "hit your usage limit". The turn failed as a generic error, so the user got no path to another login, even though switching login is the fix.

How It Works

usageLimitFrom in the ACP adapter now checks, in order:

  1. error.data.rateLimit on the error that fails the turn (the Claude ACP agent's structured report).
  2. The window from an earlier usage_update (_meta["_claude/rateLimit"]), as before.
  3. error.data.errorKind of rate_limit or billing_error and a message that starts with one of Claude Code's own refusal prefixes (USAGE_LIMIT_ERROR_PREFIXES from the SDK). The agent gives a refusal and a passing 429 the same errorKind, so the wording is what tells them apart, as the agent does itself.
  4. The generic wording check, for other agents. It now accepts a named limit ("hit your Fable limit", "hit your Sonnet 4.5 limit") and rejects context, token, output and size limits.

To make 1 and 3 possible, AcpRpcError and the wire type now carry the JSON-RPC error data.

On the desktop, SessionView builds one accountSwitch value and passes it to both the notice and, through TurnFailureActionsProvider, the failure card. The card drops its "Usage settings" button because the menu has that row.

Manual QA Checklist

Done on the dev app over CDP with two Claude logins, one at its Fable limit.

  • Normal turns on Opus 5.5 and Fable 5.2 (login with quota): complete, no notice

  • Real refused Fable turn (real adapter): "Stopped by the usage limit" row, composer notice with account pill and Resume, no red card

  • Notice account menu: both logins listed, current one checked and disabled, Usage settings row

  • Switch login from the notice: notice clears, next Fable prompt answers on the other login

  • Stored failed turn: usage-limit card shows the account pill; menu opens inside the pane; Change model, Continue and Show details work

  • Overloaded (529): unchanged red card, no account pill

  • Passing rate limit (429, errorKind: rate_limit): unchanged red "Task interrupted" card

  • Messages sent while the notice is up: queued under the notice, none sent

  • Dismiss with messages queued: queue stays, headed "Queue paused by the usage limit"

  • Pick another model under the notice: notice clears, queued messages answered in order

  • Switch login with two messages queued: both sent in order on the new login

  • Switch login with nothing queued: the continue prompt is sent on the new login

The 529 and 429 items, and the five items after them, used a shim that rewrites the CLI's output. The switch-login continue has no unit test; it was checked in the app only.

Not done: a Codex session in the app, a switch started from the card's menu (same component and handler as the notice), the direct Claude harness in the app, mobile.

Testing

  • bun test in packages/chat (133 pass) and packages/chat-runtime (552 pass)
  • bun test on the desktop ChatSession folder (526 pass); mobile chatRows (13 pass)
  • Typecheck: chat-runtime and host-service clean
  • Biome on the changed areas, bun run check:i18n
  • Each new guard was removed once to confirm its test fails

Known Limitations

  • A real model-limit refusal shows "Usage limit reached" with no reset time and no model name. @agentclientprotocol/claude-agent-acp@0.107.0 sends only errorKind on this error, without rateLimit.

Follow-ups

  • Report the missing data.rateLimit upstream.

Summary by cubic

Claude model-limit refusals ("You've hit your Fable limit") now count as usage limits instead of generic errors, so the turn shows the composer notice with an account pill and Resume rather than a red "Task interrupted" card. The account pill and menu now live in a shared UsageAccountMenu used by both the composer notice and the usage-limit failure card for stored failed turns. Picking a different model while the limit holds now resumes the session just like Resume, instead of leaving the limit in place and queueing further messages. Switching login when nothing is queued also sends the continue prompt, so the refused prompt is answered on the new login.

How limits are detected

  • usageLimitFrom checks the error's error.data.rateLimit, then the earlier usage_update window, then errorKind of rate_limit or billing_error paired with Claude Code's own refusal prefixes, and finally the generic wording check.
  • The Claude agent gives a refusal and a passing 429 the same errorKind, so the message wording is what tells them apart, as the agent itself does.
  • The generic wording check now accepts named limits ("hit your Fable limit") and rejects context, token, output, and size limits.
  • AcpRpcError and the wire type now carry the JSON-RPC error data.
  • The failure card drops its "Usage settings" button since the account menu already has that row.

Summary by CodeRabbit

  • New Features
    • Added account switching to usage-limit notices and eligible failure cards, with account and plan details.
    • After a usage limit, choosing a different model resumes the session once the change is confirmed.
    • Switching accounts after a usage limit can continue work in the restarted session.
  • Bug Fixes
    • Improved usage-limit detection when error details or reset timing are available.
    • Reduced false usage-limit alerts for generic slowdowns, context and token limits, and unrelated errors.
    • Failure cards show account-switching and model-change options when appropriate, without also showing usage settings.