Skip to content

fix(communities): scope remove_communities to the group_ids being rebuilt#1658

Open
Saltasm wants to merge 1 commit into
getzep:mainfrom
Saltasm:fix/remove-communities-group-scope
Open

fix(communities): scope remove_communities to the group_ids being rebuilt#1658
Saltasm wants to merge 1 commit into
getzep:mainfrom
Saltasm:fix/remove-communities-group-scope

Conversation

@Saltasm

@Saltasm Saltasm commented Jul 17, 2026

Copy link
Copy Markdown

Problem

Fixes #1657.

build_communities(group_ids=[...]) documents scoped behavior — "Create communities only for the listed group_ids" — but its clear step deletes every Community node in the database:

# graphiti.py — build_communities
await remove_communities(driver)   # no group filter
MATCH (c:Community)
DETACH DELETE c

The rebuild then recreates communities only for the selected groups, so a scoped rebuild silently destroys all other groups' communities. Observed live on a 5-group graph: rebuilding 2 stale groups deleted the other 3 groups' 71 communities with no error or log line. Any multi-tenant deployment refreshing communities per tenant hits this on every call, and recovery costs a full LLM re-summarization across all groups.

Fix

Thread group_ids through the clear step:

  • community_operations.remove_communities(driver, group_ids=None) — scoped DETACH DELETE with WHERE c.group_id IN $group_ids when group_ids is provided; the existing full wipe when it is not (blank/None keeps the documented whole-graph behavior).
  • Same optional parameter on GraphOperationsInterface.remove_communities and all four driver implementations (neo4j, falkordb, kuzu, neptune) — each mirrors the group_ids is None branching already used by sibling operations in the same files.
  • build_communities passes its group_ids through.

Tests

tests/utils/maintenance/test_remove_communities.py (mocked driver, no DB):

  • unscoped call still deletes all (unchanged behavior)
  • scoped call emits the WHERE c.group_id IN $group_ids form with the right params
  • group_ids=[] behaves like None (no scoping requested, matching build_communities' blank semantics)
  • the graph_operations_interface fast path receives group_ids

🤖 Generated with Claude Code

…uilt

build_communities(group_ids=[...]) documents 'Create communities only for
the listed group_ids', but its clear step called remove_communities with no
group filter — deleting EVERY Community node in the database before
recreating only the selected groups. A scoped rebuild therefore silently
destroyed all other groups' communities.

Thread group_ids through remove_communities and all four driver
implementations (neo4j, falkordb, kuzu, neptune) plus the
GraphOperationsInterface signature: scoped DETACH DELETE with
WHERE c.group_id IN $group_ids when group_ids is provided, unchanged
full wipe when it is not (blank/None keeps the documented
whole-graph behavior).

Fixes getzep#1657

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

build_communities(group_ids=...) wipes ALL communities, then rebuilds only the selected groups

1 participant