Open
Conversation
… initialization in FalkorDB
- Added integration tests for FalkorDriver.clone() and ensure_database_initialized() to verify correct behavior with multiple group IDs. - Introduced new test cases for handling group ID isolation to prevent driver mutation during concurrent operations. - Updated Makefile to include integration tests and adjusted test command to run with pytest-xdist for parallel execution. - Refactored logging statements for better readability in edges and nodes embedding processes. - Added new test suite for decorators to ensure proper functionality of group ID handling. - Removed empty test initialization file and updated pytest configuration to exclude certain directories.
Member
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
danielchalef
added a commit
that referenced
this pull request
Mar 7, 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.
Summary
Fix a race condition where FalkorDB driver state was mutated in-place when
group_iddiffered from the current database, causing concurrent calls to corrupt each other's database context.Type of Change
Objective
When
add_episodeoradd_episode_bulkwas called with agroup_iddifferent from the FalkorDB driver's current database, the code mutated shared state:Under concurrent calls (e.g.,
asyncio.gatherwith different tenants), coroutines would overwrite each other's driver, writing data to the wrong database.Changes
Core fix -- driver isolation (
graphiti_core/graphiti.py):self.driver/self.clients.drivermutation from bothadd_episodeandadd_episode_bulkdriverkwarg, create a localclients = self.clients.model_copy(update={'driver': driver}), and thread that through all internal calls_process_episode_data,_extract_and_dedupe_nodes_and_edges,_resolve_nodes_and_edges_bulk,_get_or_create_saga,_extract_and_resolve_edges) updated to accept and propagatedriverself.driver/self.clientsreference in these methods replaced with the localdriver/clientsDecorator-based group_id handling (
graphiti_core/decorators.py):@handle_single_group_id-- detects FalkorDB provider, clones the driver scoped to the group_id, callsensure_database_initialized(), and injects asdriverkwarg. The originalself.clients.driveris never touched.@handle_multiple_group_ids-- now callsensure_database_initialized()on each cloned driverFalkorDB driver (
graphiti_core/driver/falkordb_driver.py):clone()now usescopy.copy(self)instead of constructing a newFalkorDriver, avoiding re-running__init__(which schedules index builds, creates new operation objects, etc.)_initialized_databases: set[str]-- shared by reference across all clones via shallow copyensure_database_initialized()-- idempotent guard that callsbuild_indices_and_constraints()only once per database across all clonesBase driver (
graphiti_core/driver/driver.py):ensure_database_initialized()toGraphDriverbase classBuild/test infra:
Makefile: Addedtest-integrationtarget, addedDISABLE_NEO4J=1and-n autoto unit test command, increased Docker wait timeout to 300s for WSLpytest.ini: Addednorecursedirs = mcp_server serverto prevent collecting tests from sub-projectsmcp_server/tests/__init__.pyFormatting (auto-applied by
make format):edges.py,nodes.py,community_operations.py,edge_operations.py,gliner2_client.py,gliner2_neo4j.py(line length, quote style)Testing
tests/test_decorators.pyget_parameter_position,@handle_multiple_group_ids,@handle_single_group_idtests/test_group_id_isolation.pyadd_episode_bulkpropagates drivertests/driver/test_falkordb_driver.pyclone(),ensure_database_initialized(), shared_initialized_databasesBreaking Changes
Checklist
make lintpasses)