fix: harden quota-exhausted detection and MCP schema compatibility - #2836
fix: harden quota-exhausted detection and MCP schema compatibility#2836fdciabdul wants to merge 2 commits into
Conversation
- openai-common: broaden quota-exhausted fast-fail to Alibaba/
DashScope generic billing phrases (arrearage, check balance,
quota exceeded) and make insufficient_quota case-insensitive;
host now fails fast as quota-exhausted (non-retryable) instead
of retry-looping on a dead token plan when quota runs out.
- openai-responses (v1+v2): same broadening for stream events
(code/message).
- kimi-schema + mcp types (v1+v2): normalize stray `regex`
JSON Schema keyword to `pattern` at MCP import and Kimi
normalization. Fixes Meta Muse Spark strict validation
("is not a regex" 400) on imported tool schemas carrying
`regex: "^[a-zA-Z0-9@#%^&*()_+\-=[\]{}|;:,.<>?~\`]*$"`.
🦋 Changeset detectedLatest commit: cc96688 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cc96688f8a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ('regex' in obj) { | ||
| const regexValue = obj['regex']; | ||
| if (typeof regexValue === 'string' && !('pattern' in obj)) { | ||
| obj['pattern'] = regexValue; | ||
| } | ||
| delete obj['regex']; |
There was a problem hiding this comment.
Preserve schema properties named regex
When a schema contains an ordinary tool parameter named regex, for example { type: 'object', properties: { regex: { type: 'boolean' } } }, this recursive sanitizer visits the properties map and treats that map entry as the stray vendor keyword, deleting it instead of only rewriting actual schema nodes. That removes the parameter from the tool schema before it reaches Kimi (and the same pattern appears in the MCP import sanitizer), so any tool exposing a regex option can no longer be described or called correctly; limit the rewrite to schema-keyword positions rather than arbitrary maps such as properties or $defs.
Useful? React with 👍 / 👎.
Related Issue
Relates to Meta Muse Spark strict tool-schema validation and Alibaba/DashScope token-plan quota exhaustion causing stuck retries.
Problem
Meta Muse Spark 400:
^[a-zA-Z0-9@#%^&*()_+\-=[\]{}|;:,.<>?~\]*$ is not a "regex"— Spark validates toolparametersas JSON Schema strictly; keyword ispattern, notregex. Some MCP/openapi imports emitregex`, so the request fails before any inference.Alibaba token plan stuck on quota: DashScope
sk-sp-H.HMXYM…token (Alibaba Cloud) when quota runs out returns429billing phrases (Arrearage/arrears/check your account balance/quota exceeded). Host classified it as retryable rate-limit and retried in a loop; needs fast-fail asquota_exhausted(non-retryable).What changed
openai-common (kosong + agent-core-v2): make
isOpenAIInsufficientQuotaCodecase-insensitive; addisGenericQuotaExhaustedMessageanchored to Kimi billing wordings +Arrearage/arrearage;isOpenAIInsufficientQuotaErrornow uses it — Alibaba/DashScope 429 now fast-fails asAPIProviderQuotaExhaustedErrorinstead of retrying.openai-responses (both): stream error
errorFromOpenAIResponsesEventalso fast-fails whencodeormessagematches quota billing phrases.kimi-schema (both) + mcp types (both): normalize stray
regex→pattern(deleteregexifpatternabsent) at Kimi schema normalization and at MCPassertMcpInputSchemaimport. Fixes Muse Spark 400 on imported schemas withregex: "^[a-zA-Z0-9@#%^&*()_+\-=[\]{}|;:,.<>?~\]*$"`.Checklist
gen-changesetsskill —.changeset/quota-and-schema-hardening.md