fix: prevent shared driver state mutation in multi-group FalkorDB usage#1294
Open
StephenBadger wants to merge 1 commit intogetzep:mainfrom
Open
fix: prevent shared driver state mutation in multi-group FalkorDB usage#1294StephenBadger wants to merge 1 commit intogetzep:mainfrom
StephenBadger wants to merge 1 commit intogetzep:mainfrom
Conversation
add_episode() and add_episode_bulk() mutate self.driver and self.clients.driver when switching FalkorDB graphs for different group_ids. In a multi-tenant server with one shared Graphiti client, writes to one group (e.g. "group-b") silently redirect all subsequent reads for another group (e.g. "group-a") to the wrong FalkorDB graph database, returning empty results. Root cause: FalkorDB uses a separate graph database per group_id. add_episode() clones the driver to point at the target group's graph but stores the clone back into self.driver/self.clients.driver, permanently changing which graph the shared instance targets. Core library changes: - add_episode() and add_episode_bulk() now create local driver/clients via clone() and model_copy() instead of mutating shared instance state - All private methods (_extract_and_resolve_edges, _process_episode_data, _get_or_create_saga, _extract_and_dedupe_nodes_bulk, _resolve_nodes_and_edges_bulk) accept optional driver/clients params so the local clone flows through without touching self - @handle_multiple_group_ids decorator now clones the driver for single group_id queries too (was only handling len > 1), preventing stale driver state from affecting search results
Member
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
Author
|
recheck |
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.
Summary
add_episode()andadd_episode_bulk()mutateself.driverandself.clients.driverwhen switching FalkorDB graphs for differentgroup_ids. In a multi-tenant server with one sharedGraphiticlient, writes to one group silently redirect all subsequent reads for other groups to the wrong FalkorDB graph database, returning empty results.group_id.add_episode()clones the driver to point at the target group's graph but stores the clone back intoself.driver/self.clients.driver, permanently changing which graph the shared instance targets. Concurrent or interleaved operations targeting different groups corrupt each other's queries.@handle_multiple_group_idsdecorator only cloned drivers forlen(group_ids) > 1, so single-group searches used whatever stale driver state the lastadd_episodeleft behind.Fix
add_episode()andadd_episode_bulk()now create localdriver/clientsviaclone()andmodel_copy()instead of mutating shared instance state_extract_and_resolve_edges,_process_episode_data,_get_or_create_saga,_extract_and_dedupe_nodes_bulk,_resolve_nodes_and_edges_bulk) accept optionaldriver/clientsparams so the local clone flows through without touchingself@handle_multiple_group_idsdecorator now clones the driver for singlegroup_idqueries too (>= 1instead of> 1)Reproduction
Graphitiinstance with a FalkorDB driveradd_episode(group_id="group-a", ...)— driver now points togroup-agraphadd_episode(group_id="group-b", ...)— driver flips togroup-bgraphsearch_(group_ids=["group-a"], ...)— returns empty results because driver is queryinggroup-bgraph