Skip to content

fix: enhance message deserialization to prevent MESSAGE_COERCION_FAIL… #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2025

Conversation

bsbodden
Copy link
Contributor

…URE (#85)

  • Add comprehensive error handling and recovery in _deserialize_channel_values
  • Enhance _recursive_deserialize with detailed error messages for debugging
  • Document the message serialization/deserialization process extensively
  • Add tests to verify proper handling of LangChain message objects
  • Ensure messages stored in serialized format are properly reconstructed

The issue occurred when messages were stored in LangChain's serialized format with 'lc', 'type', 'constructor' fields but not properly deserialized back to message objects, causing errors when the application expected objects with 'role' and 'content' attributes.

This fix ensures robust handling of message serialization/deserialization with proper error recovery and detailed logging for debugging.

@bsbodden bsbodden self-assigned this Aug 14, 2025
@bsbodden bsbodden requested a review from Copilot August 14, 2025 19:23
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the MESSAGE_COERCION_FAILURE issue that occurs when using streaming with subgraphs, where messages stored in LangChain's serialized format fail to deserialize properly on subsequent requests with the same thread_id. The fix enhances message deserialization with comprehensive error handling and recovery mechanisms.

  • Add robust error handling and recovery in message deserialization methods
  • Enhance the JsonPlusRedisSerializer with proper LangChain object reconstruction
  • Add comprehensive documentation explaining the message serialization/deserialization process

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/test_issue_85_streaming.py Adds integration tests for streaming with subgraphs to verify MESSAGE_COERCION_FAILURE is resolved
tests/test_issue_85_message_coercion.py Adds unit tests specifically for message coercion and serialization roundtrip scenarios
langgraph/checkpoint/redis/jsonplus_redis.py Enhances JsonPlusRedisSerializer with comprehensive documentation and improved LangChain object handling
langgraph/checkpoint/redis/base.py Adds error handling, recovery mechanisms, and detailed logging to message deserialization methods

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

…URE (#85)

- Add comprehensive error handling and recovery in _deserialize_channel_values
- Enhance _recursive_deserialize with detailed error messages for debugging
- Document the message serialization/deserialization process extensively
- Add tests to verify proper handling of LangChain message objects
- Ensure messages stored in serialized format are properly reconstructed
- Test partial deserialization failures with recovery
- Verify error logging (not silent failures)
- Test channel isolation (failure in one channel doesn't affect others)
- Ensure fallback behavior returns original data when deserialization fails
@bsbodden bsbodden merged commit 36b503a into main Aug 14, 2025
19 checks passed
@bsbodden bsbodden deleted the bsb/issue-85 branch August 14, 2025 21:48
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