docs(flows): fix class-level persistence example to pass flow_id for state resumption#5694
Open
Ghraven wants to merge 1 commit intocrewAIInc:mainfrom
Open
docs(flows): fix class-level persistence example to pass flow_id for state resumption#5694Ghraven wants to merge 1 commit intocrewAIInc:mainfrom
Ghraven wants to merge 1 commit intocrewAIInc:mainfrom
Conversation
…state resumption Fixes crewAIInc#5378 The original code example created a second `PersistentCounterFlow()` without any arguments, which generates a fresh UUID and therefore does not load the first run's persisted state. Both runs produced result `2` instead of the expected increasing value. Fix: capture `flow1.flow_id` after the first kickoff and pass it via `inputs={"id": flow_id}` to the second instance. This instructs the persistence layer to restore state from the previous run, so the second run resumes from `value=2` and produces `6` (increment: 3, double: 6). Also add inline output comments so the expected values are explicit.
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.
Fixes #5378
Problem
The class-level
@persist()example inmastering-flow-state.mdxshows a secondPersistentCounterFlow()that is expected to resume from the first run's persisted state. In practice both runs produce result2— the same output — because everyPersistentCounterFlow()call generates a fresh UUID and thus writes to a new persistence slot rather than loading the previous one.Root Cause
Flow.__init__assignsstate.id = uuid4()on every construction. The@persist()decorator saves and loads state keyed by this ID. Whenflow2 = PersistentCounterFlow()is called without arguments, it gets a different ID thanflow1and no prior state is found to restore.Fix
Capture
flow1.flow_idafter the first kickoff and pass it to the second instance viainputs={"id": flow_id}. This routesflow2to the correct persisted entry, so the second run resumes fromvalue=2and produces6(increment → 3, double → 6).Inline output comments are also added so expected values are explicit.