Skip to content

fix(writer): drop synthetic trailing newline from EndEvent ReturnValue#317

Open
hjotha wants to merge 2 commits intomendixlabs:mainfrom
hjotha:submit/writer-microflow-endevent-no-trailing-newline
Open

fix(writer): drop synthetic trailing newline from EndEvent ReturnValue#317
hjotha wants to merge 2 commits intomendixlabs:mainfrom
hjotha:submit/writer-microflow-endevent-no-trailing-newline

Conversation

@hjotha
Copy link
Copy Markdown
Contributor

@hjotha hjotha commented Apr 26, 2026

Part of #332.

Fixes #316.

Summary

The microflow writer no longer appends a synthetic trailing newline to EndEvent return expressions.

Root cause

The writer added "\n" whenever ReturnValue was non-empty, even though pristine Studio Pro MPRs store the field without that newline and mxcli's parser does not need it.

Fix

Pass ReturnValue through directly when serializing EndEvent objects.

Tests

Added writer tests for both empty and non-empty EndEvent return values.

Validation

  • make build
  • make test
  • make lint-go
  • make test-integration

Agentic Code Testing

  • No new authoring syntax.
  • Synthetic writer tests cover the serialized return expression shape.

Test plan

  • Empty return value stays unchanged.
  • Non-empty return value has no synthetic trailing newline.

Pristine Mx 9 EndEvents store the return expression in `ReturnValue`
without a trailing line break. The mxcli writer was appending "\n"
whenever `ReturnValue != ""`, which:

1. Diverged from Studio Pro's pristine on-disk shape, breaking
   byte-equality on roundtrip diffs.
2. Made Studio Pro reject some list-return EndEvents with CE0117
   "Error in expression" — the Mx parser tolerated the trailing
   newline in scalar return expressions but not in list-return
   contexts.

The append predates a clear understanding of which fields are pristine.
Empirically the parser does not need the trailing newline either:
mxcli's own MPR parser already accepted the value without it.

Drop the conditional newline and pass `o.ReturnValue` through directly.

Tests added in sdk/mpr/writer_microflow_version_test.go:

- `TestSerializeEndEvent_EmptyReturnValueHasNoTrailingLineBreak` —
  pins the void-microflow case (`empty`).
- `TestSerializeEndEvent_NonEmptyReturnValueHasNoSyntheticLineBreak` —
  pins the value-return case (`$Result`).

Both go through `serializeMicroflowObject` and assert the on-disk
ReturnValue matches the input exactly.
@github-actions
Copy link
Copy Markdown

AI Code Review

What Looks Good

  • The fix correctly addresses the reported issue by removing the synthetic trailing newline from EndEvent ReturnValue serialization
  • Tests cover both empty and non-empty return value cases as specified in the validation
  • The change is minimal and targeted, modifying only the necessary serialization logic
  • All validation checks pass (build, test, lint, integration)
  • Comments are updated to explain the rationale for the change
  • No MDL syntax changes are involved, so full-stack consistency requirements don't apply
  • The fix aligns with pristine Studio Pro MPR format as intended

Recommendation

Approve the PR. The change is correct, well-tested, and resolves the specific issue without introducing side effects.


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

Adds an MDL script under mdl-examples/bug-tests/ exercising both
non-empty and empty EndEvent ReturnValue serialization. The describe →
exec → describe fixpoint confirms no synthetic trailing newline drift
in serialized BSON.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

AI Code Review

Critical Issues

None

Moderate Issues

None

Minor Issues

None

What Looks Good

  • Bug fix correctness: The change directly addresses the root cause by removing the synthetic "+ \"\n\"" when serializing EndEvent ReturnValue, matching pristine Studio Pro MPR storage.
  • Test coverage:
    • Added MDL bug test (mdl-examples/bug-tests/316-endevent-no-trailing-newline.mdl) with clear reproduction steps and validation instructions.
    • Added two unit tests in sdk/mpr/writer_microflow_version_test.go covering empty and non-empty ReturnValue cases.
    • Tests verify the exact BSON output without trailing newlines.
  • Validation: All make targets pass (build, test, lint-go, test-integration).
  • Atomicity: Focused solely on the EndEvent ReturnValue newline issue with no unrelated changes.
  • Documentation: PR description clearly explains the symptom, root cause, fix, and validation steps.
  • No syntax changes: Since this is a writer fix (not MDL syntax), syntax design and full-stack consistency checks are not applicable.

Recommendation

Approve. The PR correctly resolves the bug with minimal, targeted changes, adequate test coverage, and proper validation. No further action needed.


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.

MPR writer appends a synthetic newline to microflow EndEvent return values

2 participants