What happened?
pi crashes with RangeError: Maximum call stack size exceeded when investigating bash command failures that output unrecognized ANSI escape sequences.
The stack trace shows infinite recursion in the text rendering pipeline:
RangeError: Maximum call stack size exceeded
at wrapTextWithAnsi (pi-tui/dist/utils.js:607:16)
at Text.render (pi-tui/dist/components/text.js:55:30)
at truncateToVisualLines (visual-truncate.js:24:37)
at Object.render (bash.js:141:41)
at BashResultRenderComponent.render (pi-tui/dist/tui.js:85:38)
...
Root Cause: The extractAnsiCode() function in pi-tui/dist/utils.js has an incomplete CSI (Control Sequence Introducer) sequence parser. Line 249 only recognizes 5 CSI terminators:
// BEFORE (broken)
while (j < str.length && !/[mGKHJ]/.test(str[j]))
This misses 20+ valid CSI terminators including: A, B, C, D (cursor movement), f (position), r (scroll), s, u (cursor save/restore), h, l (modes), n (status), p (keyboard strings), etc.
When bash output contains unrecognized CSI sequences:
extractAnsiCode() returns null
- Lone
\x1b characters remain in parsed text
- Tokenization/wrapping logic enters infinite recursion
- Stack overflow crashes pi
Trigger: PyMuPDF PDF generation failures often output terminal control sequences that trigger this bug.
Steps to reproduce
- Open pi coding agent
- Run any bash command that produces ANSI escape codes with unrecognized CSI sequences
- Attempt to investigate/expand the failed command output
- Result: pi crashes with stack overflow
Example trigger:
# PyMuPDF failures often contain these sequences
echo -e '\x1b[1A\x1b[6n\x1b[H some text'
Expected behavior
pi should handle all valid ANSI escape sequences gracefully without crashing. The TUI should either:
- Render unrecognized sequences correctly, or
- Strip them silently without causing recursion
Fix Applied
Patched /opt/homebrew/lib/node_modules/@earendil-works/pi-tui/dist/utils.js line 249:
// AFTER (fixed)
while (j < str.length && !/[mGKHJfhnsuAHBCJDLSMRcXplW]/.test(str[j]))
Version
0.77.0
What happened?
pi crashes with
RangeError: Maximum call stack size exceededwhen investigating bash command failures that output unrecognized ANSI escape sequences.The stack trace shows infinite recursion in the text rendering pipeline:
Root Cause: The
extractAnsiCode()function inpi-tui/dist/utils.jshas an incomplete CSI (Control Sequence Introducer) sequence parser. Line 249 only recognizes 5 CSI terminators:This misses 20+ valid CSI terminators including:
A,B,C,D(cursor movement),f(position),r(scroll),s,u(cursor save/restore),h,l(modes),n(status),p(keyboard strings), etc.When bash output contains unrecognized CSI sequences:
extractAnsiCode()returnsnull\x1bcharacters remain in parsed textTrigger: PyMuPDF PDF generation failures often output terminal control sequences that trigger this bug.
Steps to reproduce
Example trigger:
Expected behavior
pi should handle all valid ANSI escape sequences gracefully without crashing. The TUI should either:
Fix Applied
Patched
/opt/homebrew/lib/node_modules/@earendil-works/pi-tui/dist/utils.jsline 249:Version
0.77.0