Skip to content

fix(merman): fall back when state composite separation fails - #61468

Open
FAZuH wants to merge 1 commit into
anomalyco:devfrom
FAZuH:state-diagram-fallback
Open

FAZuH wants to merge 1 commit into
anomalyco:devfrom
FAZuH:state-diagram-fallback

Conversation

@FAZuH

@FAZuH FAZuH commented Nov 3, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #61467

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

A state diagram whose composite states cannot be separated within the layout search budget throws, and that error escaped the Markdown renderer and killed the TUI.

  • State composite separation did not converge is now a DiagramLayoutError rather than a plain Error.
  • createStateDiagramDrawing handles it the same way as the canvas-size failure for horizontal diagrams, so LR/RL retry the perpendicular direction. That retry already existed for diagrams wider than the layout target; it now also covers layout failures.
  • The Markdown block renderer treats DiagramLayoutError as "cannot render" and returns undefined, so the fence falls back to a normal code block when no direction can be laid out.

The failing diagram from #61467 now renders vertically instead of crashing.

How did you verify your code works?

bun run test in packages/merman: 510 pass, 0 fail.

Two regression tests:

  • state/diagram.test.ts asserts the fixture renders as its explicit TB layout.
  • test/markdown.test.ts renders the same fence through MarkdownRenderable and asserts the diagram is drawn rather than the source.

bunx tsc --noEmit -p packages/merman passes.

Visual

N/A

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #48573

A state diagram whose composite states cannot be separated within the
layout search budget threw a plain Error, which escaped the Markdown
renderer and crashed the TUI. Treat it as a typed layout error so
horizontal diagrams retry vertically, and so the renderer falls back to
the code block when no direction can be laid out.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The crash is fixed. I ran the #61467 reproduction in the TUI from source: the base shows the "OpenCode crashed" screen with State composite separation did not converge, and with this change the diagram renders vertically. The merman state and markdown tests pass (one timeout under bun's default 5s also happens on the base), and tsc --noEmit passes.

Public API: unchanged. DiagramLayoutError is a new class inside merman, which is internal.

The change is sound. The fallback to a vertical layout reuses the existing canvas-size retry, and the markdown renderer falls back to a plain code block if that also fails. One thing worth knowing (inline): the vertical layout it falls back to is drawn wrong for this diagram, an issue that predates this change.

Related: #48573

Before

After

expect(renderedStateDimensions(output).width).toBeLessThanOrEqual(stringWidth(label) + 8)
})

test("falls back to the vertical direction when horizontal composite separation does not converge", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this fixture, the TB output this compares against is itself broken, on the base too. The left box crosses the right box's border, done is clipped by left's edge, and the [*] start/end markers are missing. Render it with direction TB to see this. So the test locks in an overlapping layout as the expected result, and the TUI shows a garbled diagram rather than the source. Fixing the crash is still the right first step, and the TB layout can be fixed separately. But a test that only asserts the drawing doesn't throw (or a note that the TB layout here is known to be wrong) would avoid treating this output as correct.

This branch has not been deployed

No deployments
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.

TUI crash: "State composite separation did not converge" on a composite state diagram

1 participant