Description
Problem
The stderr thought box added in #5205 pads every row to the width of the longest line (src/sequentialthinking/lib.ts, formatThought). The box's size is therefore lines × widest line, so a thought with one long line and many short ones expands quadratically when it is logged. Thought logging is on by default (DISABLE_THOUGHT_LOGGING unset), and the thought argument has no length limit, so one valid sequentialthinking call can exhaust the server's memory while formatting.
Before #5205 (v2.2.0, @modelcontextprotocol/server-sequential-thinking 2.0.0) the thought was printed as a single row, which grows linearly. This is a regression in the v2.3.0 release candidate. Copilot found it reviewing the milestone merge PR #5430, and it was reproduced on the candidate (cc602786).
Reproduce
SequentialThinkingServer.processThought from the candidate's dist/lib.js, with console.error replaced by a counter. The thought is one line of n characters followed by n - 1 one-character lines:
| n | thought (chars) | logged (chars) | RSS |
|---|---|---|---|
| 5,000 | 14,998 | 25,055,028 | 112 MB |
| 20,000 | 59,998 | 400,220,028 | 878 MB |
A 60 KB thought writes 400 million characters to stderr. A somewhat larger one exceeds V8's maximum string length or the heap.
Expected
The logged box stays linear in the size of the thought. Bound the rendered width (and, if needed, the total logged output). Change only the diagnostic on stderr: the stored thought and the tool result stay the same. #5205's behaviour stays: one row per line, any line ending ends a row, no \r inside a row. Add a regression test with mixed long and short lines.
Activity
fix(sequentialthinking): count header rows toward the log box's row cap