Skip to content

fix(utils): bound Mermaid ASCII pathfinder#5295

Open
roboomp wants to merge 1 commit into
mainfrom
farm/092ee66e/bound-mermaid-ascii-pathfinder
Open

fix(utils): bound Mermaid ASCII pathfinder#5295
roboomp wants to merge 1 commit into
mainfrom
farm/092ee66e/bound-mermaid-ascii-pathfinder

Conversation

@roboomp

@roboomp roboomp commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

Repro

The provided four-node Mermaid flowchart reproduced the hang with timeout 5s bun .wt/repro-mermaid-ascii.ts: before the fix the harness produced no output and exited 124, showing renderMermaidAsciiSafe() did not return within the bounded run.

Cause

packages/utils/src/vendor/mermaid-ascii/ascii/pathfinder.ts#getPath searched every free coordinate in the non-negative quadrant and only returned null after the priority queue emptied. When packages/utils/src/vendor/mermaid-ascii/ascii/edge-routing.ts#determinePath asked for an unreachable attachment point, the queue could never exhaust, so the existing direct fallback path was never reached.

Fix

  • Added occupied-grid/search-endpoint bounds with a routing margin around getPath().
  • Added an expansion budget backstop so pathological routes return null instead of growing unbounded state.
  • Added regression coverage for the reported declaration-order graph and an enclosed destination attachment point.
  • Added a utils changelog entry for the renderer termination fix.

Verification

Ran timeout 5s bun .wt/repro-mermaid-ascii.ts after the fix; it returned in about 8 ms with output length 419. Ran bun test packages/utils/test/mermaid-ascii.test.ts with 3 passing tests. Ran bun run check in packages/utils successfully. Fixes #5293

- Added bounded A* routing extents plus an expansion backstop so unreachable attachment points return null instead of searching the unbounded quadrant.
- Covered the reported declaration-order graph and an enclosed destination attachment point.
- Documented the Mermaid ASCII routing fix in the utils changelog.

Fixes #5293
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vouched Passed the vouch gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mermaid ASCII pathfinder searches unbounded grid when an edge endpoint is unreachable

1 participant