Move 402 error messages to core for unified handling#321086
Closed
pwang347 wants to merge 5 commits into
Closed
Conversation
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.
Contributor
There was a problem hiding this comment.
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
buildQuotaExceededMessagehelper (with unit tests) to generate localized, entitlement-aware quota messages and optional reset-date formatting. - Mapped agent host
ErrorInfointo structuredIChatResponseErrorDetailsflags (isQuotaExceeded,isRateLimited) and updated agent-host invocation to return these details (instead of only emitting inline markdown errors). - Updated
ChatServiceto substitute a unified, friendly quota message whenever a provider marks a result asisQuotaExceeded.
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 ErrorInfo → IChatResponseErrorDetails 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 |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.