Skip to content

Fix: High CPU / memory leak when filtering model list window to empty results - #6435

Merged
rekram1-node merged 1 commit into
anomalyco:devfrom
d3vr:dev
Dec 30, 2025
Merged

rekram1-node merged 1 commit into
anomalyco:devfrom
d3vr:dev

Conversation

@d3vr

@d3vr d3vr commented Dec 30, 2025 •

Copy link
Copy Markdown
Contributor

Resolves #6433

When filtering the model selection list in the TUI to a point where no results match (resulting in an empty list), the application enters a CPU and memory spiral, causing 100% CPU usage and rapid memory consumption until the process crashes.

The Fix
Implemented a conditional rendering guard in packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx.

  • Change: Wrapped the <scrollbox> component in a <Show when={grouped().length > 0}> block.
  • Result: When the result list is empty, the ScrollBox component is completely unmounted from the render tree. This prevents the upstream ScrollBoxRenderable from ever encountering the hazardous 0-height state, effectively bypassing the infinite loop.

Verification

  • Confirmed that typing a filter that yields no results now displays "No results found" without spiking CPU/memory or crashing.
  • Confirmed that clearing the filter restores the list correctly.
2025-12-30-102356_1073x495_scrot

@d3vr

d3vr commented Dec 30, 2025

Copy link
Copy Markdown
Contributor Author

Root Cause Analysis
The issue originates in the upstream @opentui/core library's ScrollBoxRenderable component:

  1. When the filtered list is empty, our DialogSelect component passes a height of 0 to the ScrollBox.
  2. Inside @opentui/core, the ScrollBoxRenderable listens to onSizeChange events to recalculate scrollbar properties.
  3. The recalculateBarProps method contains a workaround that unconditionally schedules a re-render on the next tick: process.nextTick(() => this.requestRender()).
  4. With a height of 0, the layout engine repeatedly fires onSizeChange (or oscillates), triggering an infinite recursive loop of Layout -> Size Change -> Schedule Render -> Layout.

(DISCLAIMER: I'm not sure this is actually the cause, I'm not too familiar with the opentui codebase, this is Gemini 3 Pro's analysis)

@d3vr d3vr changed the title Fix: Infinite Layout Loop in DialogSelect when Filtering to Empty Results Fix: High CPU / memory leak when filtering model list window to empty results Dec 30, 2025
@coleleavitt

Copy link
Copy Markdown
Contributor

I can one up this I was getting scenarios of using 70GBs of ram but it might be a unrelated memory leak, would it even be feasible for developers to write opencode in Rust?

@rekram1-node

Copy link
Copy Markdown
Collaborator

/review

@github-actions

Copy link
Copy Markdown
Contributor

lgtm

@rekram1-node
rekram1-node merged commit b378458 into anomalyco:dev Dec 30, 2025
2 checks passed
hk9890 pushed a commit to hk9890/opencode that referenced this pull request Jan 1, 2026
@LIHUA919 LIHUA919 mentioned this pull request Jan 18, 2026
triklozoid pushed a commit to triklozoid/opencode that referenced this pull request Feb 2, 2026
Rwanbt pushed a commit to Rwanbt/unifia that referenced this pull request May 5, 2026
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
Rwanbt pushed a commit to Rwanbt/unifia that referenced this pull request Jun 14, 2026
MarsQiu007 referenced this pull request in MarsQiu007/openNovel Jul 31, 2026
meSingh pushed a commit to meSingh/opencode that referenced this pull request Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Filtering the model list and resulting in an empty list causes a memory leak + high cpu spiral

3 participants