fix(flow): keep fields added after a checkpoint on dict state restore - #6707
fix(flow): keep fields added after a checkpoint on dict state restore#6707bardock-2393 wants to merge 1 commit into
Conversation
_restore_state cleared dict-typed flow state before applying a stored checkpoint, so a key added to initial_state after that checkpoint was saved was wiped out instead of keeping its fresh default. Merges the stored values onto the freshly-constructed state instead, matching how the BaseModel branch already fills unset fields from the model's defaults via model_validate. Contributes to crewAIInc#6706
|
Per CONTRIBUTING.md, this should carry the |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughDictionary-based flow state restoration now merges persisted values into the current state, preserving fields added after a checkpoint. A regression test verifies restored values and newly introduced defaults coexist. ChangesFlow state restoration
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
Summary
Contributes to #6706 by keeping dict-typed flow state fields that were added to
initial_stateafter an older checkpoint was saved._restore_statecleared the dict state before applying a stored checkpoint.self._stateis populated from the flow's currentinitial_stateat construction, so any key added since an older checkpoint was saved existed on the fresh instance with its default value — until.clear()wiped it out, leaving it missing entirely instead of falling back to that default. TheBaseModelbranch right below doesn't have this problem, sincemodel_validatealready fills unset fields from the model's own defaults; this brings the dict branch to the same behavior by merging the stored values on top of the constructed defaults instead of replacing the state outright.Testing
uv run pytest lib/crewai/tests/test_flow_persistence.py::test_dict_state_restore_keeps_fields_added_after_the_checkpoint -quv run pytest lib/crewai/tests/test_flow_persistence.py lib/crewai/tests/test_flow_persistence_factory.py -q(18 passed)uv run pytest lib/crewai/tests/ -k flow -q(600 passed, 22 skipped)uv run ruff check lib/crewai/src/crewai/flow/runtime/__init__.py lib/crewai/tests/test_flow_persistence.pyuv run ruff format --check lib/crewai/src/crewai/flow/runtime/__init__.py lib/crewai/tests/test_flow_persistence.pyuv run mypy lib/crewai/src/crewai/flow/runtime/__init__.py