Skip to content

sequentialthinking: the multi-line thought box grows quadratically and can exhaust memory #5433

Closed

Description

@cliffhall

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

  1. added this to the v2.3.0 milestone on Nov 4, 2026
  2. added
    bugSomething isn't working
    server-sequentialthinkingReference implementation for the Sequential Thinking MCP server - src/sequentialthinking
    on Nov 4, 2026
  3. self-assigned this
    on Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingserver-sequentialthinkingReference implementation for the Sequential Thinking MCP server - src/sequentialthinkingv2

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions