fix(state): persist json checkpoints as utf-8 - #7257
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthrough
ChangesJSON checkpoint encoding
Merge Risk: ⚪ Minimal · up to Checkpoint JSON reads and writes now consistently use UTF-8 for synchronous and asynchronous paths, with focused coverage for non-ASCII round trips. No current merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Vidit-Ostwal
left a comment
There was a problem hiding this comment.
The provider change is the right fix and it hits all four I/O paths (open / aiofiles.open write + Path.read_text / aiofiles.open read). In scope, no rebase needed.
The new tests will not collect: they call Path(...) but never import pathlib.Path. That is a NameError on first run. Please add from pathlib import Path (or drop Path and read bytes with open(path, "rb")).
Nit, not blocking: read_bytes() == data.encode("utf-8") is the right assertion, but on UTF-8 CI it also passes without this patch. Fine as a regression guard once the import is fixed.
CodeRabbit's docstring-coverage warning is noise here — no new functions were added.
| with tempfile.TemporaryDirectory() as d: | ||
| path = provider.checkpoint(data, d, branch="main") | ||
|
|
||
| assert Path(path).read_bytes() == data.encode("utf-8") |
There was a problem hiding this comment.
Path is used here and again in test_acheckpoint_uses_utf8_for_non_ascii_json, but test_checkpoint.py does not import it (and this PR does not add from pathlib import Path). These tests will raise NameError as soon as they run. The author noted they could not run pytest locally, and Actions on this first-time fork PR have not run the test suite yet, so this was not caught.
Add the import, or use open(path, "rb").read() to stay consistent with the os.path style in this class.
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Thanks for catching that, and sorry I missed the import on the first pass. I added uv run pytest lib/crewai/tests/test_checkpoint.py -k "utf8_for_non_ascii_json" -n0 --allowed-hosts=127.0.0.1,localhostResult: |
Problem
JsonProviderpersists checkpoint JSON with the platform default text encoding in both the sync and async paths. The matching checkpoint readers also rely on the default encoding.That makes checkpoint round-trips environment-dependent when serialized state contains non-ASCII text on systems whose default encoding is not UTF-8.
Before / after
Before this change, checkpoint writes and reads used the process/platform default encoding.
After this change, sync and async checkpoint writes/readers use
encoding="utf-8", matching JSON's expected interoperable encoding and keeping checkpoint behavior stable across platforms.Closes #7256
Verification
python -m py_compile lib/crewai/src/crewai/state/provider/json_provider.py lib/crewai/tests/test_checkpoint.pygit diff --checkJsonProvidersync + async non-ASCII checkpoint round trip via file import: passedI also attempted:
python -m pytest lib/crewai/tests/test_checkpoint.py -k "JsonProviderFork or checkpoint_uses_utf8" -qThat local run was blocked by environment setup in this bare checkout: first the configured
--timeout=60option required a missing pytest-timeout plugin, then collection required repo dependencies such asjsonref. The added tests are narrow and exercise the same provider paths as the passing direct smoke test.Note: this replaces #7255, which the first-time-contributor issue gate closed before the tracking issue existed.