Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"area": "mdl/executor", "date": "2026-11-24", "symptom": "A loop written by `create microflow` got its box Size from its body's ABSOLUTE canvas coordinates, so moving the loop 600px right grew the box by exactly 600 (body at 600,300 -> 710;380; at 1200,300 -> 1310;380, the issue's own numbers), and the centred box swallowed its neighbours. MPR008/MPR011 then blamed the neighbourhood.", "cause": "Three coordinate spaces met in one loop body. @position is a canvas coordinate everywhere in the language, but a loop's ObjectCollection stores children relative to the loop's top-left frame; addStatement filed the authored value raw, fitContainerSize measured those canvas values, and Studio Pro drew the child at canvas offset inside the frame. The box then grew with where the loop sat.", "file": "mdl/executor/cmd_microflows_builder_graph.go (addStatement records the consumed canvas @position per built object; save/restore across nested dispatches so an IF's branches do not wipe the split's), mdl/executor/cmd_microflows_builder_control.go (fitContainerSizeWithAuthored bounds the box around the loop's own anchor; finalize translates authored children and re-derives mergeSideFor tail sides), mdl/executor/layout.go, cmd_microflows_show_helpers.go (describe adds the frame back on @position/@merge inside loop bodies via ExecContext.describeFrameOrigin), cmd_flow_modify.go (storedLocator.within translates; pinBody; storedLoopStatement composes origins), flow_splice_loop_body.go", "fix": "Canvas in, frame stored: authored children and @merge-positioned merges are recorded per ID and translated into the frame at the container's finalize; describe adds the frame back on emission so describe->exec stays byte-identical for both Studio Pro and mxcli-authored flows; the splice locator, pinBody and storedLoopStatement translate the other way; enum-split tail sides are re-derived at finalize when the creation-time comparison mixed spaces.", "insight": "A stored-space change radiates to every consumer of the convention: builder, describer, splice locator, pin sets, storedLoopStatement, and flow siding that reads objectPosition mid-build. Fix it as one contract (canvas in the language, frame in storage, translate at the boundary in both directions) rather than patching consumers one by one. Geometry comparisons during the build (mergeSideFor via objectPosition) must run on final positions - derive sides at finalize, not creation, or the side depends on which space each operand was in at creation time. mxcli-authored loop children stored canvas-raw before, so old scripts' stored geometry CHANGES on re-exec (and that is the fix: the sticky wrong box from the issue heals on rebuild).", "refs": ["mendixlabs/mxcli#1935", "#884", "ako/mxcli#2369", "#1832", "#1693", "#750"], "test": "mdl/executor/issue1935_loop_box_test.go (box independent of loop position for loop and while; child stored relative to frame; auto-placed and @size contracts kept)"}
6 changes: 6 additions & 0 deletions cmd/mxcli/syntax/features_microflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,12 @@ func init() {
"pixel offset from its end of the line. (0, 0) at both ends is straight.\n" +
"@position on a split belongs to the SPLIT, so its end-if join has its own\n" +
"annotation. Container Size is still computed, not authorable.\n\n" +
"@position and @merge are CANVAS coordinates everywhere, inside a loop body\n" +
"too: state where the statement sits on the flow's canvas, and the loop box\n" +
"is sized from the body's bounds RELATIVE to the loop, so moving the loop\n" +
"never changes its box (mendixlabs/mxcli#1935). DESCRIBE prints those\n" +
"statements in canvas coordinates as well; what Mendix stores inside the\n" +
"box is the loop's own business.\n\n" +
"WITHOUT @position the builder places everything. The main line runs left to\n" +
"right and wraps onto a new row past 2880px; the line joining two rows leaves\n" +
"the bottom of one and arrives on top of the next. A guard (if … return; end\n" +
Expand Down
36 changes: 31 additions & 5 deletions mdl/executor/cmd_flow_modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -1677,15 +1677,22 @@ func bodyRefusal(lc mfmutator.Candidate, at ast.MicroflowStatement, why string)
// its nodes are drawn at, in the loop box's coordinates: each statement's
// @position and its notes' positions. Making room in that body then moves no
// node away from where the script draws it — under mdl 1, as at top level
// (statedPoints).
// (statedPoints). The locator's frame origin is the box's canvas origin
// (within), and the language's @position is a canvas coordinate (#1935), so
// position pins are translated into the box; a note's position: is stated in
// the box's own coordinates and pins as stored.
func (pd *patchDiff) pinBody(loop model.ID, declared []ast.MicroflowStatement) {
for _, st := range declared {
ann := statementAnnotations(st)
if ann == nil {
continue
}
if ann.Position != nil {
pd.bodyPins = append(pd.bodyPins, bodyPin{loop: loop, at: model.Point{X: ann.Position.X, Y: ann.Position.Y}})
at := model.Point{X: ann.Position.X, Y: ann.Position.Y}
if pd.loc != nil && pd.loc.inFrame {
at = model.Point{X: at.X - pd.loc.frameOrigin.X, Y: at.Y - pd.loc.frameOrigin.Y}
}
pd.bodyPins = append(pd.bodyPins, bodyPin{loop: loop, at: at})
}
for _, n := range ann.Notes {
if n.Position != nil {
Expand Down Expand Up @@ -2058,17 +2065,31 @@ func lcsStatements(declared, stored []ast.MicroflowStatement) [][2]int {
type storedLocator struct {
byPos map[model.Point][]mfmutator.Candidate
cands []mfmutator.Candidate
// frameOrigin is the canvas coordinate of this collection's frame origin,
// set by within for a loop body: the language's @position is a canvas
// coordinate, describe emits it as one, and the stored body keeps frame
// coordinates — locate translates (#1935). Top level keeps raw canvas.
frameOrigin model.Point
inFrame bool
}

func newStoredLocator(a *alterFlowContext) *storedLocator {
return locatorOver(a.cands, a.mf.ObjectCollection)
}

// within is the locator of a stored loop's body: describe prints a body
// statement's @position relative to the loop box, unique among the body's
// own objects but not across the flow.
// statement's @position on the canvas, while the stored body keeps positions
// relative to the loop box (#1935) — locate translates by the box's canvas
// origin. The body's coordinates are unique among the body's own objects but
// not across the flow, which is why the body gets its own locator.
func (l *storedLocator) within(loop *microflows.LoopedActivity) *storedLocator {
return locatorOver(l.cands, loop.ObjectCollection)
inner := locatorOver(l.cands, loop.ObjectCollection)
inner.frameOrigin = model.Point{
X: l.frameOrigin.X + loop.Position.X - loop.Size.Width/2,
Y: l.frameOrigin.Y + loop.Position.Y - loop.Size.Height/2,
}
inner.inFrame = true
return inner
}

func locatorOver(cands []mfmutator.Candidate, oc *microflows.MicroflowObjectCollection) *storedLocator {
Expand All @@ -2094,6 +2115,11 @@ func (l *storedLocator) locate(st ast.MicroflowStatement) (mfmutator.Candidate,
return mfmutator.Candidate{}, cannotSplice("the stored statement %q has no activity to address (a join, merge or end of a branch)", statementKind(st))
}
p := model.Point{X: ann.Position.X, Y: ann.Position.Y}
if l.inFrame {
// The script speaks canvas coordinates; the stored body speaks
// frame-relative ones (#1935).
p = model.Point{X: p.X - l.frameOrigin.X, Y: p.Y - l.frameOrigin.Y}
}
switch cs := l.byPos[p]; len(cs) {
case 1:
return cs[0], nil
Expand Down
36 changes: 33 additions & 3 deletions mdl/executor/cmd_microflows_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,34 @@ type flowBuilder struct {
// quiet silences the builder's own stderr warnings. Set for describe's
// layout check (derivedFlowLayout), which rebuilds a flow it only reads and
// must not repeat, once per round, a warning nobody asked for.
quiet bool
hierarchy *ContainerHierarchy // For resolving container IDs to module names
pendingAnnotations *ast.ActivityAnnotations // Pending annotations to attach to next activity
quiet bool
hierarchy *ContainerHierarchy // For resolving container IDs to module names
pendingAnnotations *ast.ActivityAnnotations // Pending annotations to attach to next activity
// pendingAuthoredPos holds the canvas @position the statement being built
// consumed, until the dispatch produces the object's ID; addStatement then
// files it into authoredPos. A loop's ObjectCollection stores positions
// relative to the loop's own frame, so these canvas values are translated
// into the frame of the collection that holds them once every container
// has its final size (#1935). Top-level objects keep canvas coordinates
// and are never translated.
pendingAuthoredPos *model.Point
// authoredPos maps a built object to the canvas @position its statement
// authored. Nested builders hand theirs up alongside their objects, so the
// root builder holds the whole table when the translation pass runs.
authoredPos map[model.ID]model.Point // canvas @position per built object
// sidedTails are enum-split tail flows whose destination side mergeSideFor
// derived from body geometry. A container's finalize re-derives them after
// the hand-placed children hold their frame positions, because during the
// build that comparison can read two coordinate spaces at once (#1935).
sidedTails []*microflows.SequenceFlow
// containerCursor is the frame-space line an inContainer builder's
// auto-placed statements continue on, saved across an authored statement's
// canvas detour (see addStatement).
containerCursorX, containerCursorY int
// inContainer marks a builder whose objects are stored inside a
// container's ObjectCollection (a loop body) rather than on the
// microflow's canvas.
inContainer bool
restServices []*model.ConsumedRestService // Cached REST services for parameter classification
listInputVariables map[string]bool // Variables later consumed by list-only actions
objectInputVariables map[string]bool // Variables later consumed through object/attribute access
Expand Down Expand Up @@ -242,6 +267,11 @@ func (fb *flowBuilder) nestedBuilder(x, y int) *flowBuilder {
posY: y,
baseY: y,
spacing: HorizontalSpacing,
// A nested builder's objects live in a container's frame, so its
// cursor stays frame-relative: an authored canvas @position places
// that one object and does not drag the auto-placed line that
// follows it out of the frame (#1935).
inContainer: true,

varTypes: fb.varTypes, // one variable scope
declaredVars: fb.declaredVars, // (fixes a nil map panic)
Expand Down
7 changes: 7 additions & 0 deletions mdl/executor/cmd_microflows_builder_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ func (fb *flowBuilder) addEnumSplit(s *ast.EnumSplitStmt) model.ID {
},
}
fb.objects = append(fb.objects, merge)
fb.noteAuthoredMerge(merge, s.Annotations)
}
return merge
}
Expand Down Expand Up @@ -784,6 +785,11 @@ func (fb *flowBuilder) addEnumSplit(s *ast.EnumSplitStmt) model.ID {
}
if origins != nil {
tail.DestinationConnectionIndex = mergeSideFor(fb.objectPosition(lastID), fb.objectPosition(ensureMerge().ID))
// The side is re-derived at the container's finalize, once every
// hand-placed child holds its frame position (#1935): during the
// build this comparison can read a canvas coordinate against a
// frame one, and the final geometry is what the side must match.
fb.sidedTails = append(fb.sidedTails, tail)
}
if column != nil {
tail.OriginConnectionIndex, tail.DestinationConnectionIndex = AnchorRight, AnchorBottom
Expand Down Expand Up @@ -1049,6 +1055,7 @@ func (fb *flowBuilder) addStructuredInheritanceSplit(s *ast.InheritanceSplitStmt
},
}
fb.objects = append(fb.objects, merge)
fb.noteAuthoredMerge(merge, s.Annotations)
for _, tail := range branchTails {
if tail.fromSplit {
var flow *microflows.SequenceFlow
Expand Down
86 changes: 81 additions & 5 deletions mdl/executor/cmd_microflows_builder_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func (fb *flowBuilder) addIfStatement(s *ast.IfStmt) model.ID {
},
}
fb.objects = append(fb.objects, merge)
fb.noteAuthoredMerge(merge, s.Annotations)
mergeID = merge.ID
}
if needMerge {
Expand Down Expand Up @@ -807,9 +808,16 @@ func (fb *flowBuilder) addLoopStatement(s *ast.LoopStmt) model.ID {
}

// Size the box from the children that were actually built, not from the
// statement count measured before the body existed (#884 problem 1). Recompute
// the centre too: the width just changed under it.
loopWidth, loopHeight = fitContainerSize(loopBuilder.objects, innerStartX, MinLoopWidth, MinLoopHeight)
// statement count measured before the body existed (#884 problem 1).
// Hand-placed children bound the box around this loop's own anchor so it
// does not grow with canvas position (#1935). Recompute the centre too:
// the width just changed under it.
anchorX, symmetricX := loopLeftX, false
if s.Annotations != nil && s.Annotations.Position != nil {
anchorX, symmetricX = s.Annotations.Position.X, true
}
loopWidth, loopHeight = fitContainerSizeWithAuthored(
loopBuilder.objects, loopBuilder.authoredPos, symmetricX, anchorX, fb.posY, MinLoopWidth, MinLoopHeight)
if s.Annotations != nil && s.Annotations.Size != nil && s.Annotations.Size.Width > 0 && s.Annotations.Size.Height > 0 {
// The box Studio Pro stored, @size(w, h) (ako/mxcli#2369).
loopWidth, loopHeight = s.Annotations.Size.Width, s.Annotations.Size.Height
Expand All @@ -820,6 +828,36 @@ func (fb *flowBuilder) addLoopStatement(s *ast.LoopStmt) model.ID {
loopLeftX = loopCenterX - loopWidth/2
}

// Children that carry a canvas @position are stored frame-relative — a
// loop's ObjectCollection positions its children from the box's top-left
// corner (#1935) — and every geometry decision the rest of the build makes
// about them (flow siding, box growth) reads this list, so they must hold
// frame values from here on, not after some post-pass. The frame is final:
// fitContainerSizeWithAuthored bounded it and @size may have overridden
// it. The post-pass in buildFlowGraph repeats the same arithmetic for what
// this loop cannot see here — its own centre, when the loop is itself a
// child of another body.
frameLeft, frameTop := loopLeftX, fb.posY-loopHeight/2
for _, obj := range loopBuilder.objects {
if obj == nil {
continue
}
if a, ok := loopBuilder.authoredPos[obj.GetID()]; ok {
obj.SetPosition(model.Point{X: a.X - frameLeft, Y: a.Y - frameTop})
}
}
// Re-derive the enum-split tail sides from the final frame geometry: the
// creation-time comparison read hand-placed children in canvas coordinates
// against auto-placed ones in frame coordinates (#1935). Both ends hold
// their stored positions now, which is the geometry the side must match.
for _, st := range loopBuilder.sidedTails {
origin, dest := loopBuilder.objectByID(st.OriginID), loopBuilder.objectByID(st.DestinationID)
if origin == nil || dest == nil {
continue
}
st.DestinationConnectionIndex = mergeSideFor(origin.GetPosition(), dest.GetPosition())
}

// Create LoopedActivity with calculated size
// Position is the CENTER point (RelativeMiddlePoint in Mendix)
loop := &microflows.LoopedActivity{
Expand Down Expand Up @@ -862,6 +900,12 @@ func (fb *flowBuilder) addLoopStatement(s *ast.LoopStmt) model.ID {
// dropped on the floor, so exec reported success on a flow it had silently
// written wrong (#1077).
fb.errors = append(fb.errors, loopBuilder.errors...)
for id, p := range loopBuilder.authoredPos {
if fb.authoredPos == nil {
fb.authoredPos = map[model.ID]model.Point{}
}
fb.authoredPos[id] = p
}
if fb.annotationsByLabel == nil {
fb.annotationsByLabel = loopBuilder.annotationsByLabel
}
Expand Down Expand Up @@ -1164,8 +1208,14 @@ func (fb *flowBuilder) addWhileStatement(s *ast.WhileStmt) model.ID {

whileExpr := fb.exprToString(s.Condition)

// Size from the built children, as addLoopStatement does (#884 problem 1).
loopWidth, loopHeight = fitContainerSize(loopBuilder.objects, innerStartX, MinLoopWidth, MinLoopHeight)
// Size from the built children, as addLoopStatement does (#884 problem 1),
// bounded around this loop's own anchor (#1935).
anchorX, symmetricX := loopLeftX, false
if s.Annotations != nil && s.Annotations.Position != nil {
anchorX, symmetricX = s.Annotations.Position.X, true
}
loopWidth, loopHeight = fitContainerSizeWithAuthored(
loopBuilder.objects, loopBuilder.authoredPos, symmetricX, anchorX, fb.posY, MinLoopWidth, MinLoopHeight)
if s.Annotations != nil && s.Annotations.Size != nil && s.Annotations.Size.Width > 0 && s.Annotations.Size.Height > 0 {
// The box Studio Pro stored, @size(w, h) (ako/mxcli#2369).
loopWidth, loopHeight = s.Annotations.Size.Width, s.Annotations.Size.Height
Expand All @@ -1176,6 +1226,26 @@ func (fb *flowBuilder) addWhileStatement(s *ast.WhileStmt) model.ID {
loopLeftX = loopCenterX - loopWidth/2
}

// Children that carry a canvas @position are stored frame-relative, as
// addLoopStatement does (#1935): the frame is final here, and the rest of
// the build reads these positions.
frameLeft, frameTop := loopLeftX, fb.posY-loopHeight/2
for _, obj := range loopBuilder.objects {
if obj == nil {
continue
}
if a, ok := loopBuilder.authoredPos[obj.GetID()]; ok {
obj.SetPosition(model.Point{X: a.X - frameLeft, Y: a.Y - frameTop})
}
}
for _, st := range loopBuilder.sidedTails {
origin, dest := loopBuilder.objectByID(st.OriginID), loopBuilder.objectByID(st.DestinationID)
if origin == nil || dest == nil {
continue
}
st.DestinationConnectionIndex = mergeSideFor(origin.GetPosition(), dest.GetPosition())
}

loop := &microflows.LoopedActivity{
BaseMicroflowObject: microflows.BaseMicroflowObject{
BaseElement: model.BaseElement{ID: model.ID(types.GenerateID())},
Expand Down Expand Up @@ -1206,6 +1276,12 @@ func (fb *flowBuilder) addWhileStatement(s *ast.WhileStmt) model.ID {
// dropped on the floor, so exec reported success on a flow it had silently
// written wrong (#1077).
fb.errors = append(fb.errors, loopBuilder.errors...)
for id, p := range loopBuilder.authoredPos {
if fb.authoredPos == nil {
fb.authoredPos = map[model.ID]model.Point{}
}
fb.authoredPos[id] = p
}
if fb.annotationsByLabel == nil {
fb.annotationsByLabel = loopBuilder.annotationsByLabel
}
Expand Down
6 changes: 6 additions & 0 deletions mdl/executor/cmd_microflows_builder_flows.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,12 @@ func (fb *flowBuilder) addErrorHandlerFlow(sourceActivityID model.ID, sourceX in
fb.flows = append(fb.flows, errBuilder.flows...)
fb.annotationFlows = append(fb.annotationFlows, errBuilder.annotationFlows...)
fb.errors = append(fb.errors, errBuilder.errors...)
for id, p := range errBuilder.authoredPos {
if fb.authoredPos == nil {
fb.authoredPos = map[model.ID]model.Point{}
}
fb.authoredPos[id] = p
}
// The handler's objects land in this collection, so its stated notes are
// this builder's to pin too.
for id := range errBuilder.statedNotes {
Expand Down
Loading
Loading