fix(agent-core): prevent stack overflow on circular schema refs & add compatibility mappings#830
Open
creatiVision wants to merge 6 commits into
Open
fix(agent-core): prevent stack overflow on circular schema refs & add compatibility mappings#830creatiVision wants to merge 6 commits into
creatiVision wants to merge 6 commits into
Conversation
added 3 commits
June 16, 2026 23:50
🦋 Changeset detectedLatest commit: 5b7612a The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 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: 6f20830c5c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
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.
Description
This PR resolves a critical startup crash and implements much-needed compatibility mappings for standard MCP configurations (such as Claude Desktop and Antigravity).
1. Fix Circular Schema Reference Stack Overflow (
sanitizeMcpSchema)@mcp-z/mcp-pdf) define layout shapes with recursive definitions (where elements containchildrenarrays referencing their parent schema, i.e.,#definitions/__schema0). During tool discovery, Kimi Code's schema-sanitize engine recursively inlined local$refpointers without tracking visited refs, leading to infinite recursion and an immediate startup crash (Maximum call stack size exceeded).activeRefs: Set<string>). If a circular reference is detected, the recursion halts and gracefully returns a safe, compliant{ type: 'object', description: 'Circular reference' }placeholder instead.schema-sanitize.test.ts.2. Add Key Compatibility for Standard MCP Configurations (
config.toml&mcp.json)"disabled": true(standard Claude Desktop & Antigravity settings). Kimi only looked for"enabled": falseto recognize disabled servers, causing it to connect to and spin up unwanted/disabled servers on startup.max_tokensormax_output_tokensto set response size limits. Kimi Code only checked formax_output_size. When absent, Kimi's completion-budget fallback defaulted to requesting the entire context size (e.g.,1,048,576tokens for custom reasoning models), which triggers an immediate400 Bad Requestfrom providers (e.g., OpenRouter) and crashes with an unhelpful[compaction.unable]error on Turn 1."disabled": trueconfig objects toenabled: falseinsideMcpServerConfigSchema(packages/agent-core/src/config/schema.ts).transformModelData(packages/agent-core/src/config/toml.ts) to automatically fallback tomax_tokensandmax_output_tokenswhenmax_output_sizeis not declared.config-loader.test.tsandconfigs.test.ts.Verification Results
Automated Tests
Ran the entire
agent-coreconfiguration and schema test suite; all 39 tests passed flawlessly in < 1s:pnpm --dir packages/agent-core test test/mcp/schema-sanitize.test.ts test/mcp/config-loader.test.ts test/config/configs.test.tsManual Verification
Built the native single executable binary using
pnpm --dir apps/kimi-code run build:native:sea.The TUI CLI now loads and runs cleanly with no
Maximum call stack size exceedederrors or[compaction.unable]crashes, respecting disabled flags correctly.