Skip to content

Slow start desktop, slow model response and 1 core pinned at 100% with vibe fixes #15600

Closed as not planned

Description

@GitmanIII

Description

High CPU Usage & Blocked Event Loop (3 Infinite Loops Identified)

Version: Found in v1.2.15 (and earlier builds)
Symptom: OpenCode Desktop and opencode-cli processes consume 100% of a single CPU core, leading to highly degraded performance, stuttering AI text generation, and stalled network requests (due to the main Node.js event loop being blocked).

Issue 1: Missing End-Of-File (EOF) handling in Rust Sidecar reader

Location: packages/desktop/src-tauri/src/cli.rs -> read_line()
Introduced in: 4025b655a (desktop: replicate tauri-plugin-shell logic)

Description:
The async loop responsible for reading stdout/stderr from the spawned CLI sidecar does not explicitly handle the Ok(None) case returned by lines.next_line().await when the output stream is exhausted or closed. This causes an infinite non-yielding loop in Tauri.

Fix:

        match line {
            Ok(Some(s)) => {
                let _ = tx.clone().send(wrapper(s)).await;
            }
            Ok(None) => break, // ADDED: Break on stream EOF
            Err(e) => {
                let tx_ = tx.clone();
                let _ = tx_.send(CommandEvent::Error(e.to_string())).await;
                break;
            }
        }

Issue 2: Zero-delay reconnection loop in Global Event Subscription

Location: packages/opencode/src/acp/agent.ts -> runEventSubscription()
Introduced in: bef1f6628 (fix(acp): use single global event subscription and route by sessionID)

Description:
The global event subscription is wrapped in a while (true) loop to ensure it reconnects if the event stream terminates. However, there is no backoff or sleep mechanism. If the stream closes instantly (e.g., due to an immediate disconnect or recurring error), the while loop spins unthrottled, locking the event loop.

Fix: Add a delay before restarting the loop iteration.

        for await (const event of events.stream) {
          if (this.eventAbort.signal.aborted) return
          const payload = (event as any)?.payload
          if (!payload) continue
          await this.handleEvent(payload as Event).catch((error) => {
            log.error("failed to handle event", { error, type: payload.type })
          })
        }
        // ADDED: Prevent CPU thrashing on instant disconnects
        await new Promise((resolve) => setTimeout(resolve, 1000))
      }

Issue 3: Empty string infinite loop in MultiOccurrenceReplacer

Location: packages/opencode/src/tool/edit.ts -> MultiOccurrenceReplacer()
Introduced in: f39a2b1f1 (integrate gemini-cli strategies for edit tool)

Description:
The generator function yields indexes of a find string. If the LLM hallucinates or triggers a call where the search string is empty (find === ""), content.indexOf(find, startIndex) will constantly return 0 (or startIndex). Because startIndex = index + find.length evaluates to startIndex + 0, the index never advances, causing a permanently blocked synchronous while (true) loop. This directly stalls the Node.js event loop, paralyzing all concurrent operations and AI responses.

Fix:

export const MultiOccurrenceReplacer: Replacer = function* (content, find) {
  if (find.length === 0) return // ADDED: Guard against empty search strings
  let startIndex = 0

  while (true) {
    const index = content.indexOf(find, startIndex)
    if (index === -1) break

    yield find
    startIndex = index + find.length
  }
}

Plugins

N/A

OpenCode version

v1.2.15

Steps to reproduce

Launch Opencode and observe launch times, model response and cpu usage.

Screenshot and/or share link

N/A

Operating System

Ubuntu 24.04

Terminal

GNOME

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    perfIndicates a performance issue or need for optimization
    on Mar 1, 2026
  2. changed the title [-]Slow start desktop, slow model response and 1 core pinned at 100%[/-] [+]Slow start desktop, slow model response and 1 core pinned at 100% with vibe fixes[/+] on Mar 1, 2026
  3. GitmanIII commented on Mar 1, 2026

    @GitmanIII
    Author

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    * **OpenCode version** is empty (`_No response_`) — please specify the exact version you tested this on
    
    * **Steps to reproduce** is empty (`_No response_`) — even if the bugs are code-level, a brief description of how you observed the symptoms (e.g., which action triggered the 100% CPU) would help
    
    * **Operating System** and **Terminal** are empty — system information helps maintainers reproduce and verify the fix
    

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

    This issue might be a duplicate of or related to existing issues. Please check:

    * [Auto-compaction infinite loop when assistant ended its turn (finish !== tool-calls) #15533](https://github.com/anomalyco/opencode/issues/15533): Auto-compaction infinite loop (different component, but related infinite loop bug)
    

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

    Updated issue with required info

  4. github-actions commented on Mar 1, 2026

    @github-actions
    Contributor

    Thanks for updating the issue with the required information! Everything looks good now — version, steps to reproduce, OS, and terminal are all filled in. Much appreciated!

  5. assigned and unassigned on Apr 26, 2026
  6. removed
    bugSomething isn't working
    perfIndicates a performance issue or need for optimization
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  7. github-actions commented on Jul 3, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions