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 saurav-shakya · Pull Request #21873 · anomalyco/opencode

Conversation

@saurav-shakya

@saurav-shakya saurav-shakya commented Apr 10, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Issue for this PR

Closes #16903

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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:

  • Added splitThinkBlocks() / stripThinkTags() utilities in packages/util/src/think.ts and packages/opencode/src/util/format.ts
  • TUI TextPart now extracts reasoning and renders it as a dimmed/bordered block (only when thinking display is enabled)
  • Web UI TextPartDisplay renders extracted reasoning in a reasoning-part div
  • CLI run.ts strips think tags from output; shows reasoning with --thinking flag
  • GLM-5 temperature set to 1.0 for stability

MCP MaxListeners fix (related):

  • With 7+ local MCP servers, the default EventEmitter limit of 10 is easily exceeded
  • Dynamically calculates the needed limit from the local MCP server count and raises EventEmitter.defaultMaxListeners + per-stream limits before connecting

How 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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sorry, something went wrong.

Uh oh!

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

All reactions
@saurav-shakya
fix: render think tags as reasoning blocks + fix MCP MaxListeners ove…
fc36b7c
…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
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Apr 10, 2026
@github-actions

github-actions Bot commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential duplicate found:

  • PR fix: render think tags as reasoning blocks + increase MCP MaxListeners #15389 - "fix: render think tags as reasoning blocks + increase MCP MaxListeners"
    fix: render think tags as reasoning blocks + increase MCP MaxListeners #15389

This PR appears to address the same two fixes: rendering <think> tags as reasoning blocks and handling MCP MaxListeners issues. The title and scope match PR #21873 closely. You should check whether #15389 is still open and if it has already been merged or if these represent duplicate efforts.

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 Apr 10, 2026
@github-actions

github-actions Bot commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

All reactions

Sorry, something went wrong.

Uh oh!

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

@saurav-shakya GitHub Codespaces

saurav-shakya commented Apr 10, 2026

Copy link
Copy Markdown
Author

Closing as duplicate of #15389 which implements the same think tag rendering and MCP MaxListeners fixes. Please update #15389 to also close #16903 (GLM-5 issue).

All reactions

Sorry, something went wrong.

Uh oh!

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

@saurav-shakya saurav-shakya closed this Apr 10, 2026
This was referenced Apr 15, 2026
fix(sse): prevent memory leak from zombie SSE connections #22550
Closed
fix(sse): prevent memory leak from zombie SSE connections #22551
Closed
fix(sse): prevent memory leak from zombie SSE connections #22552
Closed
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.

[BUG] GLM-5 model pollutes context window with broken thinking output

Uh oh!

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

1 participant

@saurav-shakya
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.