Skip to content

Conversation

@usvimal
Copy link
Contributor

@usvimal usvimal commented Jan 5, 2026

Summary

  • Adds tauri-plugin-single-instance to prevent multiple desktop app instances
  • Fixes orphaned sidecar cleanup - kills the sidecar process on startup timeout before exiting

Problem

Opening the OpenCode desktop app would spawn orphaned opencode-cli serve processes that accumulate over time, even from a single launch attempt. Users reported 100+ orphaned processes consuming system resources.

Root Cause

When the sidecar fails to start within 7 seconds (e.g., due to module loading errors like the @tarquinen/opencode-dcp Bun compatibility issue), the app would:

  1. Show "Startup Failed" dialog
  2. Call app.exit(1)
  3. But never kill the spawned sidecar process - leaving it orphaned

Each failed launch attempt would leave another orphaned process. The random port allocation (TcpListener::bind("127.0.0.1:0")) meant each orphan ran on a different port.

Solution

  1. Kill sidecar on startup failure: Added child.kill() before showing the failure dialog and exiting
  2. Single-instance guard: Added tauri-plugin-single-instance to prevent concurrent launches (secondary fix)

Changes

  • packages/desktop/src-tauri/Cargo.toml: Added tauri-plugin-single-instance = "2"
  • packages/desktop/src-tauri/src/lib.rs:
    • Initialize single-instance plugin with window focus callback
    • Kill sidecar process on startup timeout before exiting

@usvimal usvimal requested a review from adamdotdevin as a code owner January 5, 2026 09:15
@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2026

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

Results

No duplicate PRs found

The searches returned only the PR #6926 itself (which is the PR being analyzed). No other open PRs are addressing:

  • Single-instance protection for the desktop app
  • Multiple app spawn prevention
  • Sidecar process orphaning issues
  • Window focus on secondary launch attempts

Conclusion: This PR appears to be unique and addresses a new issue. It's safe to proceed without concerns about duplicates.

…nce protection

Two fixes for the desktop app spawning orphaned processes:

1. Add tauri-plugin-single-instance to prevent multiple app instances from
   running simultaneously. When a second instance is launched, the existing
   window is focused instead of spawning a new process.

2. Kill the sidecar process on startup timeout before exiting. Previously,
   if the sidecar failed to start within 7 seconds, the app would exit but
   leave the spawned sidecar process running as an orphan. This would
   accumulate orphaned processes each time the app was launched and failed.

Root cause: When the sidecar fails to start (e.g., due to module errors),
the app would exit without cleaning up, leaving the process running.
Repeated launch attempts would spawn more orphaned processes.
@adamdotdevin
Copy link
Contributor

Closing as we merged #6966

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.

2 participants