Skip to content

fix(compose): validate indirect edges in Workflow compile - #1268

Open
JopenChen wants to merge 1 commit into
cloudwego:mainfrom
JopenChen:fix/indirect-edge-validation
Open

fix(compose): validate indirect edges in Workflow compile#1268
JopenChen wants to merge 1 commit into
cloudwego:mainfrom
JopenChen:fix/indirect-edge-validation

Conversation

@JopenChen

@JopenChen JopenChen commented Sep 9, 2026

Copy link
Copy Markdown

What type of PR is this?

fix

Check the PR title.

  • This PR title match the format: (optional scope):
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level.

(Optional) Translate the PR title into Chinese.

fix(compose): 在 Workflow 编译时校验间接边的合法性

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
Add validation for noDirectDependency (indirect) edges during Workflow compilation.

There was a TODO at compose/workflow.go:509: "check indirect edges are legal". Edges created via WithNoDirectDependency() only establish data mappings without direct execution dependencies. Without validation, an illegal graph where no execution path exists from source to target could compile successfully and cause undefined behavior at runtime.

Changes:

  • Add validateIndirectEdges() called before graph compilation
  • Build control adjacency from g.controlEdges + g.branches (not wf.dependencies, because branchDependency can be overwritten by noDirectDependency for the same node pair)
  • BFS reachability check for each noDirectDependency edge
  • Clear error message for illegal configurations
  • 4 test cases: 2 illegal scenarios + 2 valid scenarios (including branch paths)

zh(optional):
在 Workflow 编译阶段增加对间接边(noDirectDependency)的合法性校验。

compose/workflow.go:509 处原有 TODO 标注 "check indirect edges are legal"。通过 WithNoDirectDependency() 创建的边仅建立数据映射而无直接执行依赖。若不校验,源节点到目标节点不存在执行路径的非法图也能编译通过,运行时产生不可预期行为。

主要改动:

  • 新增 validateIndirectEdges(),在图编译前调用
  • 从 g.controlEdges 和 g.branches 构建控制邻接表(不使用 wf.dependencies,因为同一节点对的 branchDependency 可能被 noDirectDependency 覆盖)
  • 对每条间接边执行 BFS 可达性检查
  • 非法配置返回清晰的错误信息
  • 新增 4 个测试用例:2 个非法场景 + 2 个合法场景(含分支路径)

(Optional) Which issue(s) this PR fixes:

N/A (resolves internal TODO)

(optional) The PR that updates user documentation:

N/A

Add validation for noDirectDependency (indirect) edges during Workflow
compilation. Previously, edges created via WithNoDirectDependency() were
not checked to ensure an execution path exists from the source node to the
target node through direct control edges.

Changes:
- Add validateIndirectEdges() to verify every indirect edge has a valid
  execution path via BFS reachability check
- Add buildControlAdjacency() to build adjacency from graph control edges
  and branch edges (handles cases where branchDependency and
  noDirectDependency coexist on the same node pair)
- Add isReachable() helper for BFS reachability
- Return clear error messages for illegal indirect edge configurations
- Add comprehensive tests covering illegal and valid scenarios

Fixes the TODO at compose/workflow.go:509
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant