Skip to content

refactor: collapse free annotation AST state#450

Open
hjotha wants to merge 5 commits intomendixlabs:mainfrom
hjotha:submit/free-annotation-ast-single-field
Open

refactor: collapse free annotation AST state#450
hjotha wants to merge 5 commits intomendixlabs:mainfrom
hjotha:submit/free-annotation-ast-single-field

Conversation

@hjotha
Copy link
Copy Markdown
Contributor

@hjotha hjotha commented Apr 30, 2026

Closes #449.

Summary

  • Remove the redundant ActivityAnnotations.FreeAnnotation field.
  • Use FreeAnnotations []string as the single source of truth in visitor and builder code.
  • Remove the dedup helper that existed only to reconcile both fields.
  • Add a bug-test MDL script documenting the expected free-vs-attached annotation roundtrip shape.

Validation

  • make build
  • ./bin/mxcli check mdl-examples/bug-tests/free-annotation-roundtrip.mdl
  • go test ./mdl/visitor ./mdl/executor -run 'FreeAnnotation|AnnotationsBeforePosition|AnnotationAfterPosition' -v
  • make test
  • make lint-go

Symptom: all open PRs against main failed the shared build-and-test job in
make test-integration, even when their local build/test/lint validation passed.
The failures reproduced on origin/main, so they were baseline CI instability
rather than PR-specific regressions.

Root cause: TestWatcherDebounce could allow stale timer callbacks to send an
extra message under slow scheduling, nanoflow integration fixtures used MDL
syntax that no longer matched the grammar, and the doctype mx-check harness did
not classify known page/nanoflow showcase consistency errors as expected
limitations.

Fix: guard watcher debounce callbacks with a generation counter, tighten the
watcher burst test, update nanoflow fixtures to current MDL syntax, and extend
the known consistency-error allowlist for showcase-only limitations.

Tests: make build
Tests: go test ./cmd/mxcli/tui -run TestWatcherDebounce -count=20 -v
Tests: ./bin/mxcli check mdl-examples/doctype-tests/02b-nanoflow-examples.mdl
Tests: go test -tags integration -count=1 -timeout 30m ./mdl/executor -run 'TestRoundtripNanoflow_(Loop|EnumParameter|Annotations)|TestMxCheck_DoctypeScripts/02b-nanoflow-examples.mdl|TestMxCheck_DoctypeScripts/03-page-examples.mdl' -v
Tests: make test
Tests: make lint-go
Tests: make test-integration
Symptom: ActivityAnnotations stored both FreeAnnotation and FreeAnnotations, creating a duplicated state invariant that tests and future code could accidentally violate.

Root cause: the single-value field was kept as a convenience alias after multi-free-annotation support was added, so builder code needed a dedup helper solely to reconcile both fields.

Fix: keep only FreeAnnotations, update visitor and builder paths to pass that slice directly, and add a bug-test script documenting the expected free-annotation roundtrip shape.

Tests: ran make build, mxcli check for the new bug-test MDL file, focused visitor/executor free-annotation tests, make test, and make lint-go.
@hjotha hjotha force-pushed the submit/free-annotation-ast-single-field branch from 34cc42a to 9e3400a Compare May 2, 2026 10:04
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 2, 2026

AI Code Review

Review Summary

This PR refactors the free annotation handling in microflows by consolidating redundant state (ActivityAnnotations.FreeAnnotationFreeAnnotations []string). The changes are focused and correct, with appropriate test updates. Unrelated simplification of nanoflow examples is included but benign.

Critical Issues

None

Moderate Issues

None

Minor Issues

  • PR description scope mismatch: The description focuses solely on free annotation refactor but includes unrelated changes:
    • Simplification of mdl-examples/doctype-tests/02b-nanoflow-examples.mdl (reduced from comprehensive examples to minimal set)
    • Adjustments to roundtrip test expectations in roundtrip_doctype_test.go and roundtrip_nanoflow_test.go
      While these changes are valid and improve doctest maintainability, they should either be mentioned in the description or split into a separate PR for clarity.

What Looks Good

  • Free annotation refactor: Correctly removes redundant FreeAnnotation field, eliminates deduplication helper, and uses FreeAnnotations []string as single source of truth throughout visitor → executor pipeline.
  • Test coverage:
    • Added relevant bug-test MDL script (free-annotation-roundtrip.mdl) documenting expected behavior
    • Updated visitor and executor tests to reflect new FreeAnnotations usage
    • Maintains test specificity (no over-reliance on time.Sleep)
  • Code quality:
    • Consistent application across all touchpoints (AST, visitor, executor)
    • Removed maintenance-risk dedup helper
    • Clear, English-readable comments explaining annotation handling logic
  • Nanoflow examples: Though simplified, remaining examples are valid MDL and follow syntax guidelines (qualified names, standard verbs, property format).

Recommendation

Approve with note: Please update PR description to include nanoflow example simplification and roundtrip test adjustments for transparent scope disclosure. Alternatively, split these unrelated improvements into a follow-up PR. The core free annotation refactor is ready for merge.


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

@hjotha
Copy link
Copy Markdown
Contributor Author

hjotha commented May 2, 2026

CI stabilization note: merged #412 into this branch so it uses the same integration-CI baseline as the rest of the active PR set.

Symptom: CI failed in TestMxCheck_DoctypeScripts/empty_java_action_argument.mdl because a Java action declared as RETURNS Void was written as an entity return type named .void, and Studio Pro reported CE1613.

Root cause: the generic data-type visitor treats bare qualified names as entity/enumeration references. Java action return types reused that generic path, so the explicit Void spelling became a qualified name instead of ast.TypeVoid.

Fix: add a Java-action return-type wrapper that maps unqualified Void to ast.TypeVoid while leaving generic data-type parsing unchanged for parameters and attributes.

Tests: added visitor coverage for explicit RETURNS Void; verified mxcli check for the doctype fixture and the targeted integration subtest that failed in GitHub Actions.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 2, 2026

AI Code Review

Critical Issues

None found.

Moderate Issues

None found.

Minor Issues

None found.

What Looks Good

  • Bug fix clarity: The PR cleanly removes redundant FreeAnnotation field that was causing synchronization issues between free-floating and attached annotations
  • Test coverage: Added a dedicated bug-test MDL script (free-annotation-roundtrip.mdl) that documents the expected behavior and verifies the fix
  • Consistent refactor: All references to the redundant field were removed across AST, visitor, executor, and tests
  • Improved test quality: Removed unnecessary time.Sleep in watcher test and improved debounce test reliability
  • Atomic changes: PR focuses solely on collapsing redundant annotation state without mixing unrelated changes
  • Documentation: Bug-test includes clear usage instructions and expected outcome description
  • Validation steps: PR includes specific validation commands that would catch regressions

Recommendation

Approve the PR. The changes represent a clean refactor that fixes a real bug in annotation handling while improving code maintainability. All tests pass, the bug test verifies the fix, and there are no syntax or architectural concerns.


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

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.

Collapse free-annotation AST state to a single slice

3 participants