mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-25 00:52:25 +02:00
1.9 KiB
1.9 KiB
Recursion Detection Fixed in LangGraph Java
Problem
The Java implementation of LangGraph had an issue with recursion detection in the PregelLoop class, which was causing tests to fail. The key problems were:
- The recursion detection logic was relying on thread IDs containing specific strings (like "cycle")
- It was throwing
GraphRecursionErrorexceptions even when workflows could complete naturally - The tests were not handling these errors consistently
Solution
We made the following improvements:
-
Improved Recursion Detection Logic
- Modified
PregelLoop.execute()to perform a final validation step before throwing errors - Updated the logic to only throw errors when workflows truly have more work to do
- Removed the thread ID string pattern dependency
- Modified
-
Fixed Streaming Execution
- Added similar validation to the
stream()method to prevent false recursion errors - Added proper final step handling to ensure graceful completion
- Added similar validation to the
-
Updated Documentation
- Created and populated
PYTHON_JAVA_MAPPING.mdto document equivalence between Python and Java - Added detailed method-level mappings to explain implementation differences
- Documented the improved recursion detection approach
- Created and populated
-
Improved Test Cases
- Fixed
testExecuteWithCheckpointRestoreto use a properly isolated test environment - Made test workflows complete naturally instead of relying on error handling
- Added more diagnostic output to track execution steps
- Fixed
Results
After these changes:
- All tests now pass consistently
- The Java implementation better matches Python's behavior
- We have clear documentation about the implementation differences
- Future developers have a reference for understanding the cross-language mapping
This fix makes the Java implementation more robust while maintaining compatibility with the Python version. The improved documentation will help maintain this alignment as both implementations evolve.