forked from qodo-benchmark/dify
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add conversation variable persistence layer #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tomerqodo
wants to merge
21
commits into
coderabbit_combined_20260121_augment_sentry_coderabbit_1_base_feat_add_conversation_variable_persistence_layer__pr429
Choose a base branch
from
coderabbit_combined_20260121_augment_sentry_coderabbit_1_head_feat_add_conversation_variable_persistence_layer__pr429
base: coderabbit_combined_20260121_augment_sentry_coderabbit_1_base_feat_add_conversation_variable_persistence_layer__pr429
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
13ca5f0
Added constructor-based DI for VariableAssigner v2 and wired the node…
laipz8200 3ee34c8
Updated to avoid the dict path and let the type checker enforce const…
laipz8200 cf98aa7
A new command for updating variables. (vibe-kanban 00377ffe)
laipz8200 0dd1f93
Add a new persistent storage for handling Conversation Variables. (v…
laipz8200 2e9b37e
- fix(lint): replace `outputs.keys()` iteration in `api/core/app/laye…
laipz8200 6fdda43
- feat(graph-engine): enforce variable update value types with Segmen…
laipz8200 3204369
- refactor(variable-assigner-v1): inline updated variable payload and…
laipz8200 c45590b
- refactor(graph-engine): switch VariableUpdate.value to VariableUnio…
laipz8200 dca3149
- refactor(variable-assigner): restore common_helpers updated-variabl…
laipz8200 f611c82
- refactor(variable-assigner): drop updated outputs now that persiste…
laipz8200 6430cdc
- chore(lint): run `make lint` (fails: dotenv-linter module missing a…
laipz8200 ee12c40
Revert "- refactor(graph-engine): switch VariableUpdate.value to Vari…
laipz8200 1a1c6f8
Revert "- feat(graph-engine): enforce variable update value types wit…
laipz8200 f409218
Revert "A new command for updating variables. (vibe-kanban 00377ffe)"
laipz8200 f99e6be
- refactor(services): move ConversationVariableUpdaterImpl and factor…
laipz8200 aca3e78
- chore(lint): run `make lint` (fails: import linter error and dotenv…
laipz8200 3ed9743
- chore(import-linter): remove obsolete ignore for variable_assigner …
laipz8200 cd8a75e
fix(core): guard conversation variable flush when no updates
laipz8200 eada52b
fix(core): use system variable conversation_id and add custom updater…
laipz8200 4b73fce
fix(services): use Exception for conversation variable not found
laipz8200 6ad378a
update pr
tomerqodo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
56 changes: 56 additions & 0 deletions
56
api/core/app/layers/conversation_variable_persist_layer.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import logging | ||
|
|
||
| from core.variables import Variable | ||
| from core.workflow.constants import CONVERSATION_VARIABLE_NODE_ID | ||
| from core.workflow.conversation_variable_updater import ConversationVariableUpdater | ||
| from core.workflow.enums import NodeType | ||
| from core.workflow.graph_engine.layers.base import GraphEngineLayer | ||
| from core.workflow.graph_events import GraphEngineEvent, NodeRunSucceededEvent | ||
| from core.workflow.nodes.variable_assigner.common import helpers as common_helpers | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class ConversationVariablePersistenceLayer(GraphEngineLayer): | ||
| def __init__(self, conversation_variable_updater: ConversationVariableUpdater) -> None: | ||
| super().__init__() | ||
| self._conversation_variable_updater = conversation_variable_updater | ||
|
|
||
| def on_graph_start(self) -> None: | ||
| pass | ||
|
|
||
| def on_event(self, event: GraphEngineEvent) -> None: | ||
| if not isinstance(event, NodeRunSucceededEvent): | ||
| return | ||
| if event.node_type != NodeType.VARIABLE_ASSIGNER: | ||
| return | ||
| if self.graph_runtime_state is None: | ||
| return | ||
|
|
||
| updated_variables = common_helpers.get_updated_variables(event.node_run_result.process_data) or [] | ||
| if not updated_variables: | ||
| return | ||
|
|
||
| conversation_id = self.graph_runtime_state.system_variable.conversation_id | ||
| if conversation_id is None: | ||
| return | ||
|
|
||
| for item in updated_variables: | ||
| selector = item.selector | ||
| if len(selector) < 2: | ||
| logger.warning("Conversation variable selector invalid. selector=%s", selector) | ||
| continue | ||
| if selector[0] != CONVERSATION_VARIABLE_NODE_ID: | ||
| continue | ||
| variable = self.graph_runtime_state.variable_pool.get(selector) | ||
| if not isinstance(variable, Variable): | ||
| logger.warning( | ||
| "Conversation variable not found in variable pool. selector=%s", | ||
| selector, | ||
| ) | ||
| continue | ||
| self._conversation_variable_updater.update(conversation_id=conversation_id, variable=variable) | ||
| self._conversation_variable_updater.flush() | ||
|
|
||
| def on_graph_end(self, error: Exception | None) -> None: | ||
| pass |
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
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
# First, check if the file exists and view the current code fd conversation_variable_updater.pyRepository: qodo-benchmark/dify-combined-coderabbit
Length of output: 179
🏁 Script executed:
Repository: qodo-benchmark/dify-combined-coderabbit
Length of output: 50395
🏁 Script executed:
Repository: qodo-benchmark/dify-combined-coderabbit
Length of output: 3650
🌐 Web query:
SQLAlchemy 2.x session lifecycle management context manager best practices💡 Result:
Concise best-practices for SQLAlchemy 2.x session lifecycle (context-manager focused)
Sources: SQLAlchemy 2.x docs — Session API & Session Basics; Transactions & session transaction patterns. [1][2][3]
References
[1] SQLAlchemy — Session API / sessionmaker.begin() / context manager usage.
[2] SQLAlchemy — Session Basics (scoping, autobegin, expire_on_commit; recommended pattern to pass session into functions).
[3] SQLAlchemy — Transactions & Session.begin_nested(), explicit begin, close/rollback behavior.
🏁 Script executed:
Repository: qodo-benchmark/dify-combined-coderabbit
Length of output: 589
🏁 Script executed:
Repository: qodo-benchmark/dify-combined-coderabbit
Length of output: 393
Wrap session creation in a context manager to ensure proper resource cleanup.
Session(db.engine)is created without any cleanup mechanism. If an exception occurs beforesession.commit(), the session remains open and the connection is leaked back to the pool. Usewith Session(db.engine) as session:to automatically close the session and rollback any open transaction, matching the established pattern throughout the codebase.🔧 Suggested fix
🤖 Prompt for AI Agents