Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@d3vr
Copy link
Contributor

@d3vr d3vr commented Dec 30, 2025

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
Copy link
Contributor Author

d3vr commented Dec 30, 2025

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
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
Collaborator

/review

@github-actions
Copy link
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
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