Repository navigation
Conversation
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.
There was a problem hiding this comment.
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
| expect(renderedStateDimensions(output).width).toBeLessThanOrEqual(stringWidth(label) + 8) | ||
| }) | ||
|
|
||
| test("falls back to the vertical direction when horizontal composite separation does not converge", () => { |
There was a problem hiding this comment.
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.


Issue for this PR
Closes #61467
Type of change
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 convergeis now aDiagramLayoutErrorrather than a plainError.createStateDiagramDrawinghandles it the same way as the canvas-size failure for horizontal diagrams, soLR/RLretry the perpendicular direction. That retry already existed for diagrams wider than the layout target; it now also covers layout failures.DiagramLayoutErroras "cannot render" and returnsundefined, 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 testinpackages/merman: 510 pass, 0 fail.Two regression tests:
state/diagram.test.tsasserts the fixture renders as its explicitTBlayout.test/markdown.test.tsrenders the same fence throughMarkdownRenderableand asserts the diagram is drawn rather than the source.bunx tsc --noEmit -p packages/mermanpasses.Visual
N/A
Screenshots / recordings
N/A
Checklist
Added by the opencode bot (AI-generated).
Related: #48573