This repository was archived by the owner on Sep 23, 2026. It is now read-only.
Repository navigation
fix(kosong): raise a clear error on circular $ref in deref_json_schema - #2506
Closed
Sreekant13 wants to merge 1 commit into
Closed
Sreekant13 wants to merge 1 commit into
Sreekant13 wants to merge 1 commit into
Conversation
deref_json_schema inlined every local $ref and recursively traversed the target, but had no cycle detection. A self-referential schema (which Pydantic emits for a recursive model, for example a tree Node with children: list[Node]) therefore recursed until a RecursionError, despite the docstring promising expansion "without infinite recursion". Track the $ref targets currently being inlined along the active chain and raise a clear ValueError when a $ref points back into that chain. Schemas that reference a definition several times in different branches are unaffected, since the tracking is scoped to the active chain. Adds a regression test.
This was referenced Jul 18, 2026
Author
|
Closing this, as the same issue was fixed in another PR. Thanks all the same. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Related Issue
None. This is a small self-contained bug fix, well under the 100-line guideline in CONTRIBUTING. Happy to open an issue first if you prefer that flow.
Description
kosong.utils.jsonschema.deref_json_schemainlines every local$refand recursively traverses the target, but it has no cycle detection. A self-referential schema, which Pydantic emits for a recursive model, therefore recursed until aRecursionError, despite the docstring promising expansion "without infinite recursion". A tool whose parameter model is recursive crashes tool conversion with a stack overflow:This change tracks the
$reftargets currently being inlined along the active chain and raises a clearValueErrornaming the circular reference when a$refpoints back into that chain. Schemas that reference the same definition several times in different branches are unaffected, since the tracking is scoped to the active chain.Adds a regression test (
test_deref_circular_ref_raises); it fails withRecursionErroron the current code. All 13 tests intest_json_schema_deref.pyand the kimi tool-conversion tests pass, and ruff is clean.Checklist
make gen-changelogto update the changelog. (Entry added to the Unreleased section by hand in the existing style;make gen-changelogdrives Kimi CLI itself, which I could not run locally.)make gen-docsto update the user documentation. (N/A: no user-facing docs change.)