Skip to content

fix: harden quota-exhausted detection and MCP schema compatibility - #2836

Open
fdciabdul wants to merge 2 commits into
MoonshotAI:mainfrom
fdciabdul:fix/quota-and-schema-hardening
Open

fix: harden quota-exhausted detection and MCP schema compatibility#2836
fdciabdul wants to merge 2 commits into
MoonshotAI:mainfrom
fdciabdul:fix/quota-and-schema-hardening

Conversation

@fdciabdul

@fdciabdul fdciabdul commented Aug 12, 2026

Copy link
Copy Markdown

Related Issue

Relates to Meta Muse Spark strict tool-schema validation and Alibaba/DashScope token-plan quota exhaustion causing stuck retries.

Problem

  1. Meta Muse Spark 400: ^[a-zA-Z0-9@#%^&*()_+\-=[\]{}|;:,.<>?~\]*$ is not a "regex"— Spark validates toolparametersas JSON Schema strictly; keyword ispattern, not regex. Some MCP/openapi imports emit regex`, so the request fails before any inference.

  2. Alibaba token plan stuck on quota: DashScope sk-sp-H.HMXYM… token (Alibaba Cloud) when quota runs out returns 429 billing phrases (Arrearage/arrears/check your account balance/quota exceeded). Host classified it as retryable rate-limit and retried in a loop; needs fast-fail as quota_exhausted (non-retryable).

What changed

  • openai-common (kosong + agent-core-v2): make isOpenAIInsufficientQuotaCode case-insensitive; add isGenericQuotaExhaustedMessage anchored to Kimi billing wordings + Arrearage/arrearage; isOpenAIInsufficientQuotaError now uses it — Alibaba/DashScope 429 now fast-fails as APIProviderQuotaExhaustedError instead of retrying.

  • openai-responses (both): stream error errorFromOpenAIResponsesEvent also fast-fails when code or message matches quota billing phrases.

  • kimi-schema (both) + mcp types (both): normalize stray regexpattern (delete regex if pattern absent) at Kimi schema normalization and at MCP assertMcpInputSchema import. Fixes Muse Spark 400 on imported schemas with regex: "^[a-zA-Z0-9@#%^&*()_+\-=[\]{}|;:,.<>?~\]*$"`.

image

Checklist

  • I have read the CONTRIBUTING document.
  • I have explained the problem above.
  • Ran gen-changesets skill — .changeset/quota-and-schema-hardening.md

- 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-bot

changeset-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cc96688

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@moonshot-ai/kimi-code Patch
@moonshot-ai/kosong Patch
@moonshot-ai/agent-core Patch
@moonshot-ai/agent-core-v2 Patch

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +143 to +148
if ('regex' in obj) {
const regexValue = obj['regex'];
if (typeof regexValue === 'string' && !('pattern' in obj)) {
obj['pattern'] = regexValue;
}
delete obj['regex'];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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.

1 participant