GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: render think tags as reasoning blocks + fix MCP MaxListeners overflow by erwinh22 · Pull Request #15382 · anomalyco/opencode

Conversation

@erwinh22

@erwinh22 erwinh22 commented Feb 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Summary

Two fixes in this PR:

1. Render <think> tags as reasoning blocks at display layer

Models like Kimi K2 Thinking embed reasoning in raw <think>...</think> tags within text parts. Previously these were displayed as raw HTML to the user.

Approach: Parse and render <think> / <thinking> tags at the display layer (TUI, Web UI, CLI) rather than stripping them from the message storage. This preserves the full model output for multi-turn context while giving users clean, styled reasoning blocks.

Changes:

  • packages/util/src/think.ts -- Shared utility: stripThinkTags(), splitThinkBlocks() with regex matching both <think> and <thinking> variants
  • packages/opencode/src/util/format.ts -- Same utilities for the core package (@/util/format path alias)
  • packages/opencode/src/cli/cmd/tui/routes/session/index.tsx -- TextPart renders think blocks with dim/italic/bordered styling matching ReasoningPart
  • packages/ui/src/components/message-part.tsx -- TextPartDisplay renders think blocks in <div data-component="reasoning-part">
  • packages/opencode/src/cli/cmd/run.ts -- CLI strips think tags from output, shows reasoning with --thinking flag

2. Fix MCP MaxListeners overflow with many servers

When 7+ stdio-based MCP servers are configured, the default Node.js EventEmitter limit of ~10 is exceeded. Each StdioClientTransport spawns a child process and adds listeners to its stdin/stdout/stderr pipes. The MCP protocol layer also sends many concurrent requests (getPrompt, listTools, etc.) that each add a drain listener.

Fix: Dynamically calculate the needed listener limit based on the number of configured local MCP servers and increase both EventEmitter.defaultMaxListeners and process stream limits before connecting.

Changes:

  • packages/opencode/src/mcp/index.ts -- Count local MCP servers, set EventEmitter.defaultMaxListeners and process stream limits proportionally

Related Issues

  • Fixes Support parsing <think> and <thinking> tags as reasoning blocks #11439 (think tag rendering regression from removal of extractReasoningMiddleware)
  • Related: MiniMax M2 <think> tags #4033, GLM 4.7 thinking process not properly formatted - missing leading tags #7779

Testing

  • Type-check passes: bun turbo typecheck -- 0 errors in opencode and ui packages
  • Tested with Kimi K2 Thinking via NVIDIA NIM -- thinking content renders correctly in TUI
  • Tested with 7 MCP servers connected -- no MaxListeners overflow warnings

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@erwinh22
fix: render <think> tags as reasoning blocks at display layer
5fb6ea5
Models that emit <think>/<thinking> tags (e.g. kimi-k2-thinking via
NVIDIA NIM) currently display raw tag content in the UI instead of
rendering it as collapsible reasoning blocks.

The extractReasoningMiddleware was intentionally removed in PR anomalyco#11270
because stripping tags at the middleware layer prevents them from being
stored in messages, breaking multi-turn LLM context.

This fix takes the rendering-layer approach: tags are preserved in
storage for faithful multi-turn context, but parsed and rendered as
reasoning blocks at display time in all three rendering surfaces:

- TUI: TextPart in session/index.tsx uses splitThinkBlocks() to
  separate reasoning from display text, rendering reasoning with the
  same dim/italic styling as native ReasoningPart
- Web UI: TextPartDisplay in message-part.tsx renders extracted
  reasoning in a reasoning-part div above the text content
- CLI: run.ts strips think tags from text output and shows reasoning
  with dim/italic styling when --thinking flag is set

Shared utility functions (stripThinkTags, splitThinkBlocks) are added
to both @opencode-ai/util/think (for web UI) and the core
packages/opencode/src/util/format.ts (for TUI and CLI).

Fixes anomalyco#15380
Relates to anomalyco#11439
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Feb 27, 2026
@github-actions

github-actions Bot commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Feb 27, 2026
Thinking models: raw <think> tag content displayed instead of being collapsed #15380
Closed
Support parsing <think> and <thinking> tags as reasoning blocks #11439
Closed
@erwinh22
fix: increase MaxListeners for stdio MCP transports
c92846c
Each StdioClientTransport spawns a child process and adds listeners to
its stdin/stdout/stderr pipes. The MCP protocol layer also sends many
concurrent requests (getPrompt, listTools, etc.) that each add a
'drain' listener on the child process's stdin. With 7+ MCP servers,
the default Node.js EventEmitter limit of ~10 is easily exceeded,
causing MaxListeners overflow warnings and potential crashes.

Dynamically calculate the needed limit based on the number of configured
local (stdio) MCP servers and increase both EventEmitter.defaultMaxListeners
and process stream limits before connecting.
@erwinh22
erwinh22 force-pushed the fix/think-tag-rendering branch from bb4e9f4 to c92846c Compare February 27, 2026 17:18
@erwinh22 erwinh22 changed the title fix: render <think> tags as reasoning blocks at display layer fix: render think tags as reasoning blocks + fix MCP MaxListeners overflow Feb 27, 2026
@github-actions

github-actions Bot commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Feb 27, 2026
@github-actions github-actions Bot closed this Feb 27, 2026
@JDNdeveloper

JDNdeveloper commented Mar 3, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

It would be great to get this landed, it's been a pretty annoying UX issue when using qwen-3.5.

EDIT: I found a workaround in LM Studio at least: Settings -> Developer -> Experimental Settings -> When applicable, separate `reasoning_content` and `content` in API responses.

buzz, dominsights, tristonarmstrong, NbrTDB, and NicksPatties reacted with thumbs up emoji tristonarmstrong reacted with hooray emoji tristonarmstrong reacted with heart emoji tristonarmstrong reacted with rocket emoji
All reactions
  • 👍 5 reactions
  • 🎉 1 reaction
  • ❤️ 1 reaction
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tayroneoliveira2023 tayroneoliveira2023 mentioned this pull request Mar 10, 2026
[BUG] GLM-5 model pollutes context window with broken thinking output #16903
Closed
2 tasks done
This was referenced Apr 5, 2026
[Bug] GLM-5.1 thinking output corruption — repetition loop + tool call leak Cor-Incorporated/opencode#52
Closed
feat(opencode): add memory system and GLM thinking corruption fix Cor-Incorporated/opencode#56
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Support parsing <think> and <thinking> tags as reasoning blocks

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@erwinh22 @JDNdeveloper
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.