fix: preserve JSON-safe checkpoint serialization for msgpack async saves#182
Merged
fix: preserve JSON-safe checkpoint serialization for msgpack async saves#182
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 649a36aa1e
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@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.
Summary
Issue #181 reported that
AsyncRedisSavercould fail during checkpoint writes with:The failure showed up when checkpoint state contained LangChain message objects and RedisJSON received those live Python objects instead of a serialized representation.
Root Cause
The failing path was the checkpoint serializer fallback for non-JSON-safe payloads.
When a checkpoint contains binary data anywhere in its state,
JsonPlusRedisSerializer.dumps_typed(...)can fall back from JSON to MessagePack. In the Redis saver,_dump_checkpoint()then deserialized that MessagePack payload back into Python objects before writing it to Redis. That worked for rawbytes, which were partially normalized, but it also rehydrated LangChain messages likeHumanMessageandAIMessageas live objects.At that point, the checkpoint document was no longer fully RedisJSON-safe, and
AsyncRedisSavereventually passed those message objects down toclient.json().set(...), which raised the serialization error from the original issue.In short: the bug was not in normal JSON checkpoint writes. It was in the
msgpackfallback path, where deserialization reintroduced Python objects that RedisJSON cannot store directly.Fix
This change keeps the existing JSON path unchanged and narrows the fix to the
msgpackbranch in_dump_checkpoint().For
msgpackcheckpoint payloads, the saver now:byteswith Redis-safe marker dictionaries.This preserves the expected RedisJSON representation while still allowing checkpoint payloads that require MessagePack during intermediate serialization.
Tests
Added regression coverage for both the serializer boundary and the async Redis path:
msgpackfallback shape with LangChain messages plus binary state and asserts the dumped checkpoint remains JSON-safe.AsyncRedisSavercan store and reload that mixed checkpoint shape without raising the originalHumanMessage is not JSON serializableerror.These tests connect directly to issue #181 by exercising the exact failure mode: message objects becoming live Python instances again after MessagePack fallback.