fix: render think tags as reasoning blocks + fix MCP MaxListeners overflow#21873
Closed
saurav-shakya wants to merge 1 commit intoanomalyco:devfrom
Closed
fix: render think tags as reasoning blocks + fix MCP MaxListeners overflow#21873saurav-shakya wants to merge 1 commit intoanomalyco:devfrom
saurav-shakya wants to merge 1 commit intoanomalyco:devfrom
Conversation
…rflow Two fixes in this commit: ### 1. Render <think> tags as reasoning blocks at display layer Models like GLM-5 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 - 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 anomalyco#16903 (GLM-5 thinking output pollution) - Fixes anomalyco#11439 (think tag rendering regression from removal of extractReasoningMiddleware) - Related: anomalyco#4033, anomalyco#7779
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential duplicate found:
This PR appears to address the same two fixes: rendering |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Author
This was referenced Apr 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue for this PR
Closes #16903
Type of change
What does this PR do?
GLM-5 model pollutes context window with broken thinking output. Raw
<think>tags leak into the UI as garbled?characters, breaking TUI layout and status indicators.Think-tag fix:
splitThinkBlocks()/stripThinkTags()utilities inpackages/util/src/think.tsandpackages/opencode/src/util/format.tsTextPartnow extracts reasoning and renders it as a dimmed/bordered block (only when thinking display is enabled)TextPartDisplayrenders extracted reasoning in areasoning-partdivrun.tsstrips think tags from output; shows reasoning with--thinkingflagMCP MaxListeners fix (related):
EventEmitterlimit of 10 is easily exceededEventEmitter.defaultMaxListeners+ per-stream limits before connectingHow did you verify your code works?
Tested locally with GLM-5 model. Verified
<think>tags no longer leak into TUI/web rendered output and reasoning blocks display correctly. MCP fix verified with multiple local MCP servers — no more MaxListeners warnings.Screenshots / recordings
N/A — TUI text rendering change; reasoning blocks render with dim/italic styling behind a left border.
Checklist