From 91984e9dcac8998d2190aaa2c0a63e459b76dcb9 Mon Sep 17 00:00:00 2001 From: David Kaya Date: Sun, 22 Mar 2026 18:09:35 +0100 Subject: [PATCH] refactor: remove unneeded sidecar refresh restart logic Drop the refresh-time sidecar restart workaround and its helper/tests now that the verified fix is in the sidecar subprocess launcher itself. This keeps the runtime simpler and leaves only the changes required for correct Copilot version detection. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/main/KopayaAppService.ts | 7 +----- src/main/sidecar/sidecarProcess.ts | 39 +++--------------------------- src/main/sidecar/sidecarRefresh.ts | 10 -------- tests/main/sidecarRefresh.test.ts | 31 ------------------------ 4 files changed, 4 insertions(+), 83 deletions(-) delete mode 100644 src/main/sidecar/sidecarRefresh.ts delete mode 100644 tests/main/sidecarRefresh.test.ts diff --git a/src/main/KopayaAppService.ts b/src/main/KopayaAppService.ts index a7241b3..64bdc93 100644 --- a/src/main/KopayaAppService.ts +++ b/src/main/KopayaAppService.ts @@ -496,12 +496,7 @@ export class KopayaAppService extends EventEmitter { } private async loadSidecarCapabilities(forceRefresh = false): Promise { - if (forceRefresh) { - this.sidecarCapabilities = await this.sidecar.refreshCapabilities(); - return this.sidecarCapabilities; - } - - if (!this.sidecarCapabilities) { + if (forceRefresh || !this.sidecarCapabilities) { this.sidecarCapabilities = await this.sidecar.describeCapabilities(); } diff --git a/src/main/sidecar/sidecarProcess.ts b/src/main/sidecar/sidecarProcess.ts index a6f2c6e..307d447 100644 --- a/src/main/sidecar/sidecarProcess.ts +++ b/src/main/sidecar/sidecarProcess.ts @@ -1,5 +1,4 @@ import { app } from 'electron'; -import { once } from 'node:events'; import { spawn, type ChildProcessWithoutNullStreams } from 'node:child_process'; import type { @@ -13,10 +12,6 @@ import type { } from '@shared/contracts/sidecar'; import type { ChatMessageRecord } from '@shared/domain/session'; import { createSidecarEnvironment } from '@main/sidecar/sidecarEnvironment'; -import { - shouldHandleSidecarExit, - shouldRestartSidecarOnCapabilityRefresh, -} from '@main/sidecar/sidecarRefresh'; import { markRunTurnPendingErrored, shouldHandleRunTurnEvent, @@ -51,14 +46,6 @@ export class SidecarClient { return command; } - async refreshCapabilities(): Promise { - if (shouldRestartSidecarOnCapabilityRefresh(this.hasActiveRunTurn())) { - await this.dispose(); - } - - return this.describeCapabilities(); - } - async validatePattern(pattern: ValidatePatternCommand['pattern']): Promise { return this.dispatch({ type: 'validate-pattern', @@ -76,28 +63,12 @@ export class SidecarClient { } async dispose(): Promise { - const sidecar = this.process; - if (!sidecar) { + if (!this.process) { return; } - if (sidecar.exitCode !== null || sidecar.signalCode !== null) { - return; - } - - const exitPromise = once(sidecar, 'exit'); - sidecar.kill(); - await exitPromise; - } - - hasActiveRunTurn(): boolean { - for (const pending of this.pending.values()) { - if (pending.kind === 'run-turn') { - return true; - } - } - - return false; + this.process.kill(); + this.process = undefined; } private async ensureProcess(): Promise { @@ -131,10 +102,6 @@ export class SidecarClient { }); childProcess.on('exit', (code) => { - if (!shouldHandleSidecarExit(this.process?.pid, childProcess.pid)) { - return; - } - const error = new Error(`The .NET sidecar exited unexpectedly with code ${code ?? 'unknown'}.`); for (const pending of this.pending.values()) { pending.reject(error); diff --git a/src/main/sidecar/sidecarRefresh.ts b/src/main/sidecar/sidecarRefresh.ts deleted file mode 100644 index aba1b69..0000000 --- a/src/main/sidecar/sidecarRefresh.ts +++ /dev/null @@ -1,10 +0,0 @@ -export function shouldRestartSidecarOnCapabilityRefresh(hasActiveRunTurn: boolean): boolean { - return !hasActiveRunTurn; -} - -export function shouldHandleSidecarExit( - activeProcessId: number | undefined, - exitingProcessId: number | undefined, -): boolean { - return activeProcessId !== undefined && exitingProcessId !== undefined && activeProcessId === exitingProcessId; -} diff --git a/tests/main/sidecarRefresh.test.ts b/tests/main/sidecarRefresh.test.ts deleted file mode 100644 index f26698f..0000000 --- a/tests/main/sidecarRefresh.test.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { describe, expect, test } from 'bun:test'; - -import { - shouldHandleSidecarExit, - shouldRestartSidecarOnCapabilityRefresh, -} from '@main/sidecar/sidecarRefresh'; - -describe('shouldRestartSidecarOnCapabilityRefresh', () => { - test('restarts the sidecar when no run-turn is active', () => { - expect(shouldRestartSidecarOnCapabilityRefresh(false)).toBe(true); - }); - - test('keeps the existing sidecar when a run-turn is active', () => { - expect(shouldRestartSidecarOnCapabilityRefresh(true)).toBe(false); - }); -}); - -describe('shouldHandleSidecarExit', () => { - test('handles exit events from the currently active sidecar process', () => { - expect(shouldHandleSidecarExit(1234, 1234)).toBe(true); - }); - - test('ignores exit events from a stale sidecar process', () => { - expect(shouldHandleSidecarExit(1234, 5678)).toBe(false); - }); - - test('ignores exit events when either process id is missing', () => { - expect(shouldHandleSidecarExit(undefined, 5678)).toBe(false); - expect(shouldHandleSidecarExit(1234, undefined)).toBe(false); - }); -});