feat(flow): support custom persistence key in @persist#5649
Merged
lucasgomide merged 6 commits intomainfrom Apr 29, 2026
Merged
feat(flow): support custom persistence key in @persist#5649lucasgomide merged 6 commits intomainfrom
lucasgomide merged 6 commits intomainfrom
Conversation
Allows users to specify which state attribute to use as the persistence key instead of always defaulting to state.id. Usage: @persist(key='conversation_id') Falls back to state.id when key is not provided (no breaking change). Raises ValueError if the specified key is missing or falsy on state.
480e4be to
6ddfaaf
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6f1f907. Configure here.
lorenzejay
approved these changes
Apr 29, 2026
iris-clawd
approved these changes
Apr 29, 2026
Contributor
iris-clawd
left a comment
There was a problem hiding this comment.
Looks good 👍
Code:
- Clean threading of
keythrough all wrapper paths (sync, async, class-level, method-level) — nothing missed. - Good separation between custom-key
ValueErrorand the defaultid-missing error, so existing flows are unaffected. - The
str(e) or LOG_MESSAGES["id_missing"]fix in theexcept (TypeError, ValueError)block correctly preserves the custom key error message instead of swallowing it.
Tests:
- Pydantic, dict, and missing-key error cases all covered. The assertion that
load_state(flow.state.id) is Nonein the Pydantic test is a nice touch — proves the custom key was actually used as the lookup, not just ignored.
Docs:
- Consistent examples across all 4 languages, all 3 doc pages.
One minor note (non-blocking): if someone passes key="id" explicitly, it would behave identically to omitting it — which is fine, but might be worth a one-liner in the docstring mentioning it's a no-op in that case. Totally optional.
💬 259
lorenzejay
approved these changes
Apr 29, 2026
greysonlalonde
approved these changes
Apr 29, 2026
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.

Adds a
keyparameter to@persistso flows can use any state attribute (e.g.conversation_id) as the persistence key instead of always falling back tostate.id. When the named attribute is missing or falsy, raises a clearValueErroridentifying the missing key.Note
Medium Risk
Changes core persistence key selection and error handling, which can affect how existing flows are saved/loaded if users adopt
keyor rely on prior error messages.Overview
@persistnow accepts an optionalkeyparameter to choose which state attribute (Pydantic/object) or dict key is used as the persistence identifier, defaulting to the existingstate.idbehavior.Persistence now raises a clear
ValueErrorwhen the custom key is missing or falsy, and tests were added to cover Pydantic, dict-based states, and the failure path. Documentation across EN/AR/KO/PT-BR was updated with examples and behavior notes for custom persistence keys.Reviewed by Cursor Bugbot for commit 9efe193. Bugbot is set up for automated code reviews on this repo. Configure here.