Skip to content

fix(graph): prevent duplicated append results when merging serial subgraphs#4527

Open
gaozexun wants to merge 2 commits intoalibaba:mainfrom
gaozexun:codex/fix-issue-4515-subgraph-merge-duplication-no-worktree
Open

fix(graph): prevent duplicated append results when merging serial subgraphs#4527
gaozexun wants to merge 2 commits intoalibaba:mainfrom
gaozexun:codex/fix-issue-4515-subgraph-merge-duplication-no-worktree

Conversation

@gaozexun
Copy link
Copy Markdown
Contributor

@gaozexun gaozexun commented Apr 8, 2026

Describe what this PR does / why we need it

This PR fixes duplicated/over-amplified AppendStrategy results when parent graph merges serial subgraph outputs (Issue #4515).

Before the fix, serial subgraph executions could produce duplicated output values:

  • two distinct subgraphs in serial -> expected 2, got 3
  • same subgraph instance reused by two nodes -> expected 2, got 4
  • parent node + two serial subgraphs -> expected 3, got 7

Does this pull request fix one issue?

Closes #4515

Describe how you did it

Two changes were applied:

  1. Isolate subgraph checkpoint namespace by nodeId
  • In SubCompiledGraphNodeAction, once subgraph saver exists, always assign deterministic node-scoped threadId:
    • ${parentThreadId}_${subGraphId(nodeId)} or subGraphId(nodeId)
  • This avoids checkpoint/state pollution across different parent nodes using subgraphs.
  1. Reset append-based keys before subgraph execution
  • Added OverAllState.withResetKeys(Set<String>).
  • In SubCompiledGraphNodeAction, build subgraph initial state by removing all keys whose strategy is AppendStrategy.
  • This ensures each subgraph run starts append accumulation from a clean baseline instead of inheriting parent historical append state.

Also added a non-mock reproduction test class:

  • Issue4515ReproductionTest (3 scenarios)

Describe how to verify it

Run:

./mvnw -pl :spring-ai-alibaba-graph-core -Dtest=Issue4515ReproductionTest test
./mvnw -pl :spring-ai-alibaba-graph-core -Dtest=Issue4515ReproductionTest,CompiledSubGraphTest,SubGraphTest,StateGraphTest test

@github-actions github-actions bot added the area/graph SAA Grpah module label Apr 8, 2026
@gaozexun gaozexun changed the title fix(graph-core): prevent duplicated append results when merging serial subgraphs fix(graph): prevent duplicated append results when merging serial subgraphs Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/graph SAA Grpah module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] 父图合并(处理)子图结果有问题,不合理。

1 participant