[PR #6926] fix(desktop): add single-instance protection to prevent multiple app spawns #12167

Closed
opened 2026-02-16 18:17:05 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6926

State: closed
Merged: No


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
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6926 **State:** closed **Merged:** No --- ## 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
yindo added the pull-request label 2026-02-16 18:17:05 -05:00
yindo closed this issue 2026-02-16 18:17:05 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12167