Skip to content

fix: preserve manual while-true loop roundtrips#354

Open
hjotha wants to merge 2 commits intomendixlabs:mainfrom
hjotha:submit/manual-while-true-loop-roundtrip
Open

fix: preserve manual while-true loop roundtrips#354
hjotha wants to merge 2 commits intomendixlabs:mainfrom
hjotha:submit/manual-while-true-loop-roundtrip

Conversation

@hjotha
Copy link
Copy Markdown
Contributor

@hjotha hjotha commented Apr 27, 2026

Closes #350.
Part of #332.

Summary

This extracts the manual while true loop preservation from the audit staging branch into a focused fix.

The builder already accepted while, break, and continue syntax, but it did not materialize break/continue events and it treated continue as a normal fallthrough path. For retry-style while true loops this could rebuild the flow as a LoopedActivity or synthesize an invalid fallthrough EndEvent.

Changes

  • Build BreakEvent and ContinueEvent objects for parsed break/continue statements.
  • Treat break/continue as terminal branch statements for control-flow analysis.
  • Detect manual while true bodies that need a graph-level back-edge and build them as an ExclusiveMerge loop header.
  • Route continue inside that manual loop back to the merge instead of emitting a standalone ContinueEvent.

Validation

  • make build
  • make lint-go
  • make test

Symptom: MDL that represents an unbounded retry-style while true loop with a continue could be rebuilt as a LoopedActivity or could fall through into a synthetic EndEvent, changing the model shape and sometimes producing invalid control flow.

Root cause: the flow builder parsed while/break/continue syntax but did not build BreakEvent or ContinueEvent objects, and it treated continue as a normal fallthrough statement instead of a terminal branch or manual back-edge.

Fix: add builder support for break/continue events, detect while true bodies that should be represented as a manual ExclusiveMerge back-edge, route continue to that merge, and mark terminal manual loops as already ending the flow.

Tests: add synthetic builder regressions for break/continue terminal detection, normal loop break/continue events, manual while true back-edge reconstruction, and avoiding a fallthrough EndEvent for terminal manual loops.
@github-actions
Copy link
Copy Markdown

AI Code Review

Critical Issues

None found.

Moderate Issues

  • Missing bug test in mdl-examples/bugtests/: Per the checklist, bug fixes should include an MDL test script in mdl-examples/bug-tests/ that reproduces the issue. This PR fixes manual while true loop handling but lacks an accompanying bug test in mdl-examples/bug-tests/ to verify the fix in Studio Pro context. While unit tests are added, the checklist specifically requires an MDL test script for bug fixes.

Minor Issues

None found.

What Looks Good

  • Focused scope: PR addresses a single concern (preserving manual while true loops) without unrelated changes.
  • Correct terminal statement handling: Break/Continue are now properly recognized as terminal statements in control flow analysis.
  • Proper loop header generation: Manual while true loops now use ExclusiveMerge as loop header with correct back-edge routing for continue.
  • Event generation: BreakEvent and ContinueEvent objects are correctly materialized.
  • Comprehensive unit tests: Added test coverage for break/continue terminal behavior, loop preservation, and edge cases.
  • No syntax changes: Since this is an internal fix (no new MDL syntax), full-stack consistency checks don't apply appropriately.
  • Clean implementation: Changes are localized to the microflow builder with clear helper functions.

Recommendation

Request changes to add an MDL test script in mdl-examples/bug-tests/ reproducing the manual while true loop issue (with break/continue) to satisfy the bug fix checklist requirement. Once added, the PR is ready for approval.

The core fix is technically sound and ready aside from the missing bug test artifact. Adding a simple test like:

manual while true loop with break and continue
while true
    if $condition
        break
    else
        continue
endwhile

would sufficiently validate the fix in Studio Pro.


Automated review via OpenRouter (Nemotron Super 120B) — workflow source

Adds an MDL script under mdl-examples/bug-tests/ exercising a
manual `while true` retry loop with `continue` and a terminal
`return` inside an IF. After exec, `mx check` reports 0 errors
and the rebuild does not produce a `LoopedActivity` or a
synthetic fallthrough EndEvent. Addresses moderate review
feedback on PR mendixlabs#354 requesting an MDL test artifact.

Co-Authored-By: Claude Opus 4.7 <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.

Preserve manual while-true retry-loop roundtrips

2 participants