Repository navigation
Conversation
Contributor
|
This branch has not been deployed
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.
📝 Changes Description
Prevent JSON serialization errors from destroying an existing DSPy checkpoint.
The JSON branch of
BaseModule.save()opens the destination with"wb"before callingorjson.dumps. If the new state contains a non-JSON-serializable value, serialization raises as intended, but opening the file has already erased the last valid checkpoint. Saving a normalPredict("question -> answer"), then adding an unserializable value totracesand saving again reproduces this without an LM: a 483-byte checkpoint becomes empty.Serialize inside the existing error handler before opening the file, then write the resulting bytes. This preserves the existing error message and valid output format, avoids creating an empty file on an initial failed save, and leaves an existing checkpoint untouched on serialization failure. Pickle and whole-program saving are unchanged.
Verification
pytest tests/primitives/test_module.py tests/predict/test_predict.py -q: 99 passed, with two existing warnings.git diff --checkpassed.✅ Contributor Checklist
AI assistance used for investigation, code, tests, and self-review. This is not atomic file replacement: I/O errors or a process crash after opening the destination can still affect it. Full repository tests and cross-platform behavior were not verified; no real model/provider was called. Whole-file formatting was not changed because existing formatting differences are outside this patch.