Skip to content

docs: fix incorrect code example in flow state persistence guide#5775

Open
NIK-TIGER-BILL wants to merge 1 commit into
crewAIInc:mainfrom
NIK-TIGER-BILL:fix-5378-docs-code
Open

docs: fix incorrect code example in flow state persistence guide#5775
NIK-TIGER-BILL wants to merge 1 commit into
crewAIInc:mainfrom
NIK-TIGER-BILL:fix-5378-docs-code

Conversation

@NIK-TIGER-BILL
Copy link
Copy Markdown
Contributor

@NIK-TIGER-BILL NIK-TIGER-BILL commented May 11, 2026

Closes #5378

The class-level persistence example in the flow state guide claimed that state is automatically loaded on a second run, but the code never passed the previous flow's state.id to kickoff(). Without inputs={"id": ...} the new flow instance starts with a fresh UUID and empty state, so the second run produces the same result as the first.

Changes:

  • Update the English and Korean docs to pass inputs={"id": flow1.state.id} on the second run.
  • Add a test (test_class_level_persistence_docs_example) that verifies the corrected example behaves as documented (first run = 2, resumed run = 6).

Summary by CodeRabbit

  • Documentation

    • Updated and clarified flow state persistence examples in both English and Korean documentation to provide explicit guidance on resuming from previous runs using appropriate state identifiers and initialization parameters.
  • Tests

    • Added comprehensive test coverage for class-level flow state persistence functionality, validating resumption behavior with Pydantic-based state models.

Review Change Stack

…wAIInc#5378)

Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

📝 Walkthrough

Walkthrough

Documentation for class-level flow state persistence is corrected to show explicit state.id resumption via kickoff(inputs={"id": flow1.state.id}) in both English and Korean guides. A new test validates this pattern works across consecutive flow executions.

Changes

Flow State Persistence Documentation Fix

Layer / File(s) Summary
Documentation Examples
docs/en/guides/flows/mastering-flow-state.mdx, docs/ko/guides/flows/mastering-flow-state.mdx
"Second run" examples updated to explicitly pass inputs={"id": flow1.state.id} to kickoff() for resuming persisted state, removing the incorrect assumption that state loads automatically.
Test Validation
lib/crewai/tests/test_flow_persistence.py
New test_class_level_persistence_docs_example test exercises class-level @persist(persistence) with a CounterState model, verifying the first run initializes state and the second run correctly resumes from flow1.state.id with expected combined results.

🎯 2 (Simple) | ⏱️ ~8 minutes

🐰 A hop and a bounce through the state persistence lane,
Where docs now show the right way, no more in vain,
state.id passed forward, the pattern's now clear,
Tests confirm the flow resumes what it held dear! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing an incorrect code example in the flow state persistence documentation.
Linked Issues check ✅ Passed All objectives from issue #5378 are met: the docs are corrected to pass state.id on resume, a validating test is added, and the fix enables state persistence across runs.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the persistence documentation bug: English and Korean docs are corrected, and a validation test is added.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
lib/crewai/tests/test_flow_persistence.py (1)

394-397: ⚡ Quick win

Add an explicit state.id continuity assertion for resume semantics.

The value assertion is great, but adding assert flow2.state.id == flow1.state.id would directly lock in the documented “resume same lineage” contract.

✅ Suggested test hardening
     flow2 = PersistentCounterFlow()
     result2 = flow2.kickoff(inputs={"id": flow1.state.id})
+    assert flow2.state.id == flow1.state.id
     assert result2 == 6  # resumed at 2, incremented to 3, doubled to 6
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/crewai/tests/test_flow_persistence.py` around lines 394 - 397, Add an
explicit assertion that the resumed flow preserves lineage by checking
flow2.state.id equals flow1.state.id after creating flow2 and calling
flow2.kickoff; specifically, after result2 = flow2.kickoff(...) add assert
flow2.state.id == flow1.state.id (before or alongside the existing value
assertion) to enforce resume continuity for PersistentCounterFlow and its
kickoff behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@lib/crewai/tests/test_flow_persistence.py`:
- Around line 394-397: Add an explicit assertion that the resumed flow preserves
lineage by checking flow2.state.id equals flow1.state.id after creating flow2
and calling flow2.kickoff; specifically, after result2 = flow2.kickoff(...) add
assert flow2.state.id == flow1.state.id (before or alongside the existing value
assertion) to enforce resume continuity for PersistentCounterFlow and its
kickoff behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: feb1a95d-7993-43c9-87fc-3c118865c8c6

📥 Commits

Reviewing files that changed from the base of the PR and between 63a9e7e and c215924.

📒 Files selected for processing (3)
  • docs/en/guides/flows/mastering-flow-state.mdx
  • docs/ko/guides/flows/mastering-flow-state.mdx
  • lib/crewai/tests/test_flow_persistence.py

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.

[BUG] Wrong code in document

1 participant