Skip to content

fix: correctly flatten update_community results in add_episode#1421

Closed
octo-patch wants to merge 1 commit into
getzep:mainfrom
octo-patch:fix/issue-1396-add-episode-tuple-unpack
Closed

fix: correctly flatten update_community results in add_episode#1421
octo-patch wants to merge 1 commit into
getzep:mainfrom
octo-patch:fix/issue-1396-add-episode-tuple-unpack

Conversation

@octo-patch

Copy link
Copy Markdown

Fixes #1396

Problem

add_episode crashes with ValueError: too many / not enough values to unpack when the number of extracted entity nodes is anything other than exactly 2.

The root cause: semaphore_gather returns a list of N tuples (one per coroutine), where each tuple is (list[CommunityNode], list[CommunityEdge]). The previous code did:

communities, community_edges = await semaphore_gather(...)

This Python unpacking treats the returned list as if it has exactly 2 items, so it only worked by accident when N == 2. For N == 1 it raises ValueError: not enough values to unpack; for N >= 3 it raises ValueError: too many values to unpack.

Solution

Replace the tuple unpack with an explicit accumulation loop:

per_node_results = await semaphore_gather(...)
for node_communities, node_community_edges in per_node_results:
    communities.extend(node_communities)
    community_edges.extend(node_community_edges)

This correctly aggregates results across all nodes regardless of how many entity nodes were extracted from the episode. Also adds explicit type annotations to communities and community_edges since they were previously inferred as list[Any].

Testing

The fix is a straightforward logic correction with no behaviour change for callers — the returned communities and community_edges lists now have the correct types and values for all N. No external dependencies are required to verify the logic.

…etzep#1396)

semaphore_gather returns a list of N tuples (one per coroutine), where each
tuple is (list[CommunityNode], list[CommunityEdge]). The previous code
unpacked this as `communities, community_edges = <list of N tuples>`, which
only worked accidentally when exactly 2 nodes were extracted.

Replace the tuple unpack with an explicit loop that extends the accumulated
lists, making it work correctly for any number of extracted entity nodes.
SFEley added a commit to SFEley/graphiti that referenced this pull request Apr 21, 2026
Cherry-picked from getzep#1421 (fixes getzep#1396).

semaphore_gather returns a list of N tuples, not two parallel lists.
Unpacking as `communities, community_edges = ...` only worked by
accident when exactly 2 entity nodes were extracted. Replaces the
unpack with an explicit accumulation loop that works for any N.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@danielchalef

Copy link
Copy Markdown
Member

Thanks for this — correct fix for the update_community results not being flattened from semaphore_gather in add_episode (graphiti.py:1185). Consolidating on #1486 as the canonical fix (same fix + a regression test, rebased on main). Closing as superseded by #1486; credit to you for surfacing it too.

@zep-cla-assistant zep-cla-assistant Bot locked and limited conversation to collaborators Jun 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add_episode tuple-unpack fails when extracted node count is not exactly 2

2 participants