Skip to content

fix: prevent shared driver state mutation in multi-group FalkorDB usage#1294

Open
StephenBadger wants to merge 1 commit intogetzep:mainfrom
StephenBadger:fix/falkordb-driver-state-mutation
Open

fix: prevent shared driver state mutation in multi-group FalkorDB usage#1294
StephenBadger wants to merge 1 commit intogetzep:mainfrom
StephenBadger:fix/falkordb-driver-state-mutation

Conversation

@StephenBadger
Copy link

Summary

  • 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 silently redirect all subsequent reads for other groups 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. Concurrent or interleaved operations targeting different groups corrupt each other's queries.
  • @handle_multiple_group_ids decorator only cloned drivers for len(group_ids) > 1, so single-group searches used whatever stale driver state the last add_episode left behind.

Fix

  • 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 (>= 1 instead of > 1)

Reproduction

  1. Create a Graphiti instance with a FalkorDB driver
  2. Call add_episode(group_id="group-a", ...) — driver now points to group-a graph
  3. Call add_episode(group_id="group-b", ...) — driver flips to group-b graph
  4. Call search_(group_ids=["group-a"], ...)returns empty results because driver is querying group-b graph

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
@danielchalef
Copy link
Member

danielchalef commented Mar 3, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@StephenBadger
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

@StephenBadger
Copy link
Author

recheck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants