Skip to content

Conversation

ChiaXinLiang
Copy link
Contributor

Description: Fixes infinite recursion issue in JSON schema dereferencing when objects contain both $ref and other properties (e.g., nullable, description, additionalProperties). This was causing Apollo MCP server schemas to hang indefinitely during tool binding.

Problem:

  • Commit fb5da83 changed the condition from set(obj.keys()) == {"$ref"} to "$ref" in set(obj.keys())
  • This caused objects with $ref + other properties to be treated as pure $ref nodes
  • Result: other properties were lost and infinite recursion occurred with complex schemas

Solution:

  • Restore pure $ref detection for objects with only $ref key
  • Add proper handling for mixed $ref objects that preserves all properties
  • Merge resolved reference content with other properties
  • Maintain cycle detection to prevent infinite recursion

Impact:

  • Fixes Apollo MCP server schema integration
  • Resolves tool binding infinite recursion with complex GraphQL schemas
  • Preserves backward compatibility with existing functionality
  • No performance impact - actually improves handling of complex schemas

Issue: Fixes #32511

Dependencies: None

Testing:

  • Added comprehensive unit tests covering mixed $ref scenarios
  • All existing tests pass (1326 passed, 0 failed)
  • Tested with realistic Apollo GraphQL schemas
  • Stress tested with 100 iterations of complex schemas

Verification:

  • make format - All files properly formatted
  • make lint - All linting checks pass
  • make test - All 1326 unit tests pass
  • ✅ No breaking changes - full backwards compatibility maintained

@ChiaXinLiang ChiaXinLiang requested a review from eyurtsev as a code owner August 16, 2025 17:05
Copy link

vercel bot commented Aug 16, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
langchain Ignored Ignored Preview Sep 11, 2025 7:07pm

Copy link

codspeed-hq bot commented Aug 16, 2025

CodSpeed WallTime Performance Report

Merging #32578 will not alter performance

Comparing ChiaXinLiang:fix/core-json-schema-infinite-recursion-32511 (2c27fd5) with master (38afedd)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 13 untouched

Copy link

codspeed-hq bot commented Aug 16, 2025

CodSpeed Instrumentation Performance Report

Merging #32578 will not alter performance

Comparing ChiaXinLiang:fix/core-json-schema-infinite-recursion-32511 (2c27fd5) with master (38afedd)

Summary

✅ 14 untouched

@mdrxy mdrxy changed the title fix(core): resolve infinite recursion in _dereference_refs_helper with mixed $ref objects fix(core): resolve infinite recursion in _dereference_refs_helper with mixed $ref objects Aug 18, 2025
@mdrxy mdrxy added core Related to the package `langchain-core` investigate Flagged for investigation labels Aug 18, 2025
@eyurtsev eyurtsev self-assigned this Sep 11, 2025
Marcus and others added 5 commits September 11, 2025 14:35
…h mixed $ref objects

Fixes infinite recursion issue in JSON schema dereferencing when objects contain both $ref and other properties (e.g., nullable, description, additionalProperties).

**Problem:**
- Commit fb5da83 changed the condition from `set(obj.keys()) == {"$ref"}` to `"$ref" in set(obj.keys())`
- This caused objects with $ref + other properties to be treated as pure $ref nodes
- Result: other properties were lost and infinite recursion occurred with complex schemas

**Solution:**
- Restore pure $ref detection for objects with only $ref key
- Add proper handling for mixed $ref objects that preserves all properties
- Merge resolved reference content with other properties
- Maintain cycle detection to prevent infinite recursion

**Impact:**
- Fixes Apollo MCP server schema integration (langchain-ai#32511)
- Resolves tool binding infinite recursion with complex GraphQL schemas
- Preserves backward compatibility with existing functionality
- No performance impact - actually improves handling of complex schemas

Fixes langchain-ai#32511
@eyurtsev eyurtsev force-pushed the fix/core-json-schema-infinite-recursion-32511 branch from 142771d to 99d6684 Compare September 11, 2025 19:05
@eyurtsev eyurtsev merged commit c687965 into langchain-ai:master Sep 11, 2025
78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to the package `langchain-core` investigate Flagged for investigation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

core: dereference_refs seems to lead to infinite recursion
3 participants