You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tui: cyclic Mermaid subgraphs overflow the renderer stack #60341
A Mermaid flowchart can overflow the TUI renderer stack when repeated subgraph IDs form a cycle. Rendering should stay responsive and show the source if the diagram cannot be drawn.
Steps to reproduce
Open a session whose assistant message contains this Mermaid block:
This self-cycle and a two-ID cycle both fail with RangeError: Maximum call stack size exceeded in descendantsOf. Both were reproduced with isolated imported sessions on dev 726cf096.
OpenCode version
Source checkout at 726cf096396d5014c3b1845e231cc01efe0421ee.
Operating System
macOS ARM64, Ubuntu 24.04 and Windows Server 2025.
changed the title [-]tui: cyclic Mermaid subgraphs hang or crash rendering[/-][+]tui: cyclic Mermaid subgraphs overflow the renderer stack[/+]on Oct 29, 2026
Thanks for the clear report. I reproduced this on the latest dev (bc7da10f3), running from source.
I used a simulated assistant reply containing your flowchart TD / subgraph A / subgraph A / N[First] / end / end block. The TUI never renders the rest of the message and switches to the "OpenCode crashed" screen with Maximum call stack size exceeded. The stack trace is repeated descendantsOf frames in packages/merman/src/flowchart/parser.ts. In my run the self-cycle crashed with the stack overflow rather than hanging. Calling the flowchart parser directly throws the same RangeError for both the self-cycle and a two-ID cycle (A > B > A).
The recording and screenshot below show it, and the script below reproduces it.
recording.mp4
Reproduction script (drive.ts)
import{Effect}from"effect"import{Stream}from"effect"import{Llm,OpenCodeDriver}from"opencode-drive"// Assistant reply containing a Mermaid flowchart whose subgraph IDs form a cycle.// Set CYCLE=two for the two-ID cycle (A > B > A).constdiagram=process.env.CYCLE==="two"
? "flowchart TD\nsubgraph A\nsubgraph B\nsubgraph A\nN[First]\nend\nend\nend"
: "flowchart TD\nsubgraph A\nsubgraph A\nN[First]\nend\nend"constreply="Here is the diagram:\n\n```mermaid\n"+diagram+"\n```\n\nAFTER-DIAGRAM-MARKER"exportdefaultOpenCodeDriver.use({
...(process.env.OC_DEV ? {opencode: {dev: process.env.OC_DEV}} : {}),tui: {recording: true},},({ ui, llm })=>Effect.gen(function*(){yield*ui.screenshot("01-home")yield*llm.serve(()=>Stream.make(Llm.text(reply)))yield*ui.submit("Draw the diagram")constresult=yield*ui.waitFor("AFTER-DIAGRAM-MARKER",{timeout: 20000}).pipe(Effect.as("rendered"),Effect.catch((e: unknown)=>Effect.succeed(`FAILED: ${String((easany)?._tag??e)}`)),)yield*Effect.log(`result: ${result}`)yield*ui.screenshot("02-after").pipe(Effect.catch((e: unknown)=>Effect.log(`screenshot failed: ${String((easany)?._tag??e)}`)))}),)
Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.
Activity
[-]tui: cyclic Mermaid subgraphs hang or crash rendering[/-][+]tui: cyclic Mermaid subgraphs overflow the renderer stack[/+]opencodejr commentedon Oct 29, 2026
Thanks for the clear report. I reproduced this on the latest
dev(bc7da10f3), running from source.I used a simulated assistant reply containing your
flowchart TD / subgraph A / subgraph A / N[First] / end / endblock. The TUI never renders the rest of the message and switches to the "OpenCode crashed" screen withMaximum call stack size exceeded. The stack trace is repeateddescendantsOfframes inpackages/merman/src/flowchart/parser.ts. In my run the self-cycle crashed with the stack overflow rather than hanging. Calling the flowchart parser directly throws the sameRangeErrorfor both the self-cycle and a two-ID cycle (A > B > A).The recording and screenshot below show it, and the script below reproduces it.
recording.mp4
Reproduction script (drive.ts)
Run it with opencode-drive:
opencode-drive run ./drive.ts. It drivesopencodefrom yourPATH; setOC_DEVto the path of an OpenCode checkout to run that from source instead.