Skip to content

Move 402 error messages to core for unified handling#321086

Closed
pwang347 wants to merge 5 commits into
mainfrom
pawang/agentHost402
Closed

Move 402 error messages to core for unified handling#321086
pwang347 wants to merge 5 commits into
mainfrom
pawang/agentHost402

Conversation

@pwang347

Copy link
Copy Markdown
Member

No description provided.

pwang347 added 2 commits June 11, 2026 22:04
Map a failed turn's protocol ErrorInfo (e.g. an upstream 402) into
structured IChatResponseErrorDetails so the chat UI shows the
plan-aware ChatQuotaExceededPart instead of a raw 'Error: (...)'
markdown line, with a friendly localized, reset-date-aware message.
Move buildQuotaExceededMessage into a shared chat/common module and have
ChatService substitute the friendly, plan-/reset-date-aware message for
any result flagged isQuotaExceeded, regardless of provider (agent host,
Copilot CLI, Claude CLI, ...). The agent-host adapter now only maps the
error type to flags; the message is no longer built per-provider.
Copilot AI review requested due to automatic review settings June 12, 2026 05:26

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 centralizes quota-exceeded (e.g. upstream 402) handling in the core chat pipeline so that providers can surface a structured “quota exceeded” signal while VS Code owns the final, plan-aware, localized user message and UI rendering.

Changes:

  • Added a shared buildQuotaExceededMessage helper (with unit tests) to generate localized, entitlement-aware quota messages and optional reset-date formatting.
  • Mapped agent host ErrorInfo into structured IChatResponseErrorDetails flags (isQuotaExceeded, isRateLimited) and updated agent-host invocation to return these details (instead of only emitting inline markdown errors).
  • Updated ChatService to substitute a unified, friendly quota message whenever a provider marks a result as isQuotaExceeded.
Show a summary per file
File Description
src/vs/workbench/contrib/chat/test/common/chatQuotaMessage.test.ts Adds unit tests for the new quota-message builder.
src/vs/workbench/contrib/chat/test/browser/agentSessions/stateToProgressAdapter.test.ts Adds unit tests for the new ErrorInfoIChatResponseErrorDetails mapping helper.
src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts Centralizes final quota-exceeded message substitution in core chat service.
src/vs/workbench/contrib/chat/common/chatQuotaMessage.ts Introduces shared, localized quota-exceeded message generation + reset date formatting.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/stateToProgressAdapter.ts Adds errorInfoToChatErrorDetails to convert agent host errors into structured chat error flags.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts Returns structured errorDetails on failed turns and suppresses inline markdown error emission on the live invoke path.

Copilot's findings

  • Files reviewed: 6/6 changed files
  • Comments generated: 3

Comment on lines +36 to +39
case ChatEntitlement.Free:
return reset
? localize('chat.quotaExceeded.free.reset', "You've reached your monthly credit limit. Upgrade to Copilot Pro or wait until your credits reset on {0}.", reset)
: localize('chat.quotaExceeded.free', "You've reached your monthly credit limit. Upgrade to Copilot Pro or wait for your credits to reset.");
Comment on lines +26 to +27
* upgrade / manage-budget button is rendered separately by `ChatQuotaExceededPart`
* based on entitlement, so this text intentionally avoids duplicating that action.
Comment on lines +58 to +60
const resetDate = new Date(isoDate);
const includeYear = resetDate.getFullYear() !== new Date().getFullYear();
const dateParts: Intl.DateTimeFormatOptions = includeYear
pwang347 added 3 commits June 11, 2026 23:03
Expand buildQuotaExceededMessage to faithfully cover usage-based-billing and
all plan tiers plus the special CAPI codes (overage_limit_reached,
additional_spend_limit_reached, billing_not_configured). Providers now forward
the structured backend code so core renders identical text regardless of origin:

- IChatResponseErrorDetails + ChatErrorDetails (proposed) gain quotaExceededCode
- protocol ErrorInfo gains code; the agent-host adapter forwards it
- chatServiceImpl feeds entitlement + UBB + forwarded code into the builder
- the Copilot fetch layer forwards capiError.code via quotaExceededCode

Tests updated for the expanded builder and the agent-host code forwarding.
Completes the centralization: the Copilot agent-host session forwards the SDK
session.error errorCode into ErrorInfo.code, and the Copilot CLI session
threads the SDK errorCode through CopilotCLIQuotaExceededError into
errorDetails.quotaExceededCode. Core now renders the exact, plan-aware quota
message for every chat-pipeline provider from a single place.
Inline chat already flows through IChatService/chatServiceImpl, but the inline chat intent dropped the structured quota flags and only forwarded a pre-built message. Forward isQuotaExceeded + quotaExceededCode so core builds the single, plan-aware quota message that the inline chat controller renders.
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.

2 participants