fix: treat terminal nested IF as returning in flow builder#262
fix: treat terminal nested IF as returning in flow builder#262ako merged 2 commits intomendixlabs:mainfrom
Conversation
AI Code ReviewCritical IssuesNone found. Moderate IssuesNone found. Minor Issues
What Looks Good
RecommendationApprove. The fix is correct, well-documented, and follows project conventions. The minor test coverage concern is alleviated by the PR's explicit test plan assertions and passing Automated review via OpenRouter (Nemotron Super 120B) — workflow source |
Code Review — fix: treat terminal nested IF as returning in flow builderOverviewMinimal, targeted fix. The root cause is clear: The fix introduces CorrectnessRecursion is sound —
The calling site in IssuesNo tests in the diff The test plan says "Regression test: a microflow containing
VerdictThe logic is correct and the fix is minimal. Same blocker as #261: tests are claimed but absent. Before merging, add a unit test for |
lastStmtIsReturn only matched a literal ast.ReturnStmt as the last statement, missing the case where a body ends in an IF whose branches both return. The outer IF then thought its THEN branch continued, emitted a duplicate "true" SequenceFlow plus an orphan EndEvent with no ReturnValue, and Studio Pro rejected the file with "Sequence contains no matching element" on any diff or microflow open. Widen the predicate to "last stmt is a guaranteed terminator" — RETURN, RAISE ERROR, or an IF/ELSE where every branch is terminal (recursively). LOOP is explicitly not terminal because BREAK exits even if the body returns. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Add `cmd_microflows_builder_terminal_test.go` covering lastStmtIsReturn across all terminal-statement shapes: plain return, RaiseErrorStmt, IF without ELSE (non-terminal), IF with both branches returning, else-if chains, mixed return/raise, and LOOP (never terminal per BREAK semantics). - Add `mdl-examples/bug-tests/262-terminal-nested-if-no-dangling-merge.mdl` reproducer per CLAUDE.md checklist.
8554167 to
cdfb0d0
Compare
|
Thanks @ako — addressed in cdfb0d0:
|
AI Code ReviewCritical IssuesNone found. Moderate IssuesNone found. Minor IssuesNone found. What Looks Good
RecommendationApprove - This is a well-implemented bug fix with comprehensive test coverage that correctly resolves the reported issue. The changes are minimal, focused, and maintain consistency with existing code patterns. All verification steps pass including Studio Pro validation. Automated review via OpenRouter (Nemotron Super 120B) — workflow source |
Summary
The flow-graph builder treated a microflow ending with a nested
if { ... return } else { ... return }as "still continuing", so it tried to wire a merge/continuation edge after the IF. With both branches already terminating at their own EndEvents the edge dangled and Studio Pro raisedKeyNotFoundExceptionwhen opening.Root cause:
lastStmtIsReturnonly matched*ast.ReturnStmt. The fix introduces a recursiveisTerminalStmthelper that recognises:ReturnStmt— always terminalRaiseErrorStmt— always terminal (raised error exits the flow)IfStmt— terminal iff it has an ELSE and both branches are recursively terminalLoopStmt, since BREAK can exit) — non-terminalThe calling site in
cmd_microflows_builder_control.gois unchanged;bothReturnnow evaluates correctly for nested IFs and else-if chains where every leaf terminates.Part of umbrella #257.
Test plan
mdl/executor/cmd_microflows_builder_terminal_test.gopin all terminal-detection cases: empty body, plain return,RaiseErrorStmt, IF without ELSE (non-terminal), IF/ELSE with both branches returning (terminal), IF where only one branch returns (non-terminal), else-if chains, mixed return/raise, and LOOP (never terminal).mdl-examples/bug-tests/262-terminal-nested-if-no-dangling-merge.mdl.go build ./... && go test ./...pass.KeyNotFoundException.