Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

fix: pass relaunch owner to open launcher

wyt74415c0fb0c3
diff --git a/src/main/index.ts b/src/main/index.ts
index b40fb062..3cae2dfd 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -38,6 +38,7 @@ import { app, BrowserWindow, Menu, Notification, ipcMain, nativeImage, net, prot
// rather than in index.ts body (esbuild CJS hoists imports → body runs
// after paths.ts loads, which is too late to set the env var).
import './install-data-root.cjs';
+import { resolveCliCommand } from './features/local_agents/spawn-command';
import { desktopPlatform, osVersion, preferredSystemLanguage } from './system_info';
import {
hardenedWebPreferences,
@@ -417,23 +418,32 @@ function registerIpc(): void {
// The relaunch button shells out to run.sh / run.cmd instead of using
// `app.relaunch()` so we can reuse `scripts/ensure-deps.cjs` for
// dependency self-healing — otherwise pulling new code + relaunching
- // crashes immediately due to missing packages. The shell script handles
- // ensure-deps + killing the old electron + npm start; here we just
- // detach-spawn it and call `app.exit(0)`.
+ // crashes immediately due to missing packages. The shell script receives
+ // this process as its explicit owner, waits for it to exit, then starts the
+ // replacement without touching any other Electron process.
ipcMain.handle('orkas.relaunch', () => {
- const isWin = process.platform === 'win32';
- const script = path.join(paths.PC_ROOT, isWin ? 'run.cmd' : 'run.sh');
- const [cmd, args] = isWin
- ? ['cmd.exe', ['/c', script]] as const
- : ['bash', [script]] as const;
- const child = spawn(cmd, args, {
+ const isWindows = process.platform === 'win32';
+ const script = path.join(paths.PC_ROOT, isWindows ? 'run.cmd' : 'run.sh');
+ const resolved = isWindows
+ ? resolveCliCommand(script, [], process.platform, process.env)
+ : { command: 'bash', args: [script], windowsVerbatimArguments: undefined };
+ // install-data-root.cjs must resolve the workspace again in the
+ // replacement process. Inheriting the current resolved roots would
+ // short-circuit that boot decision.
+ const childEnv = { ...process.env };
+ delete childEnv.ORKAS_WORKSPACE_ROOT;
+ delete childEnv.CORE_AGENT_AUTH_DIR;
+ childEnv.ORKAS_RELAUNCH_OWNER_PID = String(process.pid);
+ const child = spawn(resolved.command, resolved.args, {
cwd: paths.PC_ROOT,
detached: true,
stdio: 'ignore',
windowsHide: true,
+ windowsVerbatimArguments: resolved.windowsVerbatimArguments,
+ env: childEnv,
});
child.unref();
- log.info('relaunch via shell script', { script });
+ log.info('relaunch via shell script');
app.exit(0);
return { ok: true };
});
diff --git a/test/main/index-process.test.ts b/test/main/index-process.test.ts
index 75f1dd57..d7969290 100644
--- a/test/main/index-process.test.ts
+++ b/test/main/index-process.test.ts
@@ -19,17 +19,39 @@ describe('main process child-process ownership', () => {
);
});
- it('keeps the open-build relaunch command detached and hidden', () => {
+ it('passes the exact old-process owner before launching the replacement', () => {
const source = fs.readFileSync(
path.resolve(process.cwd(), 'src/main/index.ts'),
'utf8',
);
- const relaunchStart = source.indexOf('const child = spawn');
+ const relaunchStart = source.indexOf("ipcMain.handle('orkas.relaunch'");
expect(relaunchStart).toBeGreaterThan(-1);
- const relaunchBlock = source.slice(relaunchStart, relaunchStart + 500);
+ const relaunchBlock = source.slice(relaunchStart, relaunchStart + 1_800);
+
+ expect(relaunchBlock).toContain('resolveCliCommand');
+ expect(relaunchBlock).toContain('delete childEnv.ORKAS_WORKSPACE_ROOT');
+ expect(relaunchBlock).toContain('delete childEnv.CORE_AGENT_AUTH_DIR');
+ expect(relaunchBlock).toContain(
+ 'childEnv.ORKAS_RELAUNCH_OWNER_PID = String(process.pid)',
+ );
expect(relaunchBlock).toContain('detached: true');
expect(relaunchBlock).toContain("stdio: 'ignore'");
expect(relaunchBlock).toContain('windowsHide: true');
+ expect(relaunchBlock).toContain('windowsVerbatimArguments: resolved.windowsVerbatimArguments');
+ expect(relaunchBlock).toContain('env: childEnv');
expect(relaunchBlock).toContain('child.unref()');
+
+ const shellLauncher = fs.readFileSync(
+ path.resolve(process.cwd(), 'run.sh'),
+ 'utf8',
+ );
+ const windowsLauncher = fs.readFileSync(
+ path.resolve(process.cwd(), 'run.cmd'),
+ 'utf8',
+ );
+ expect(shellLauncher).toContain('ORKAS_RELAUNCH_OWNER_PID');
+ expect(shellLauncher).not.toMatch(/pkill[^\n]+electron\/dist/i);
+ expect(windowsLauncher).toContain('ORKAS_RELAUNCH_OWNER_PID');
+ expect(windowsLauncher).not.toMatch(/taskkill[^\n]+electron\.exe/i);
});
});
diff --git a/test/main/platform-process-coverage.test.ts b/test/main/platform-process-coverage.test.ts
index f8adf1a2..ec5d2d10 100644
--- a/test/main/platform-process-coverage.test.ts
+++ b/test/main/platform-process-coverage.test.ts
@@ -56,7 +56,7 @@ const PROCESS_OWNER_SUITE: Record<string, ProcessOwner> = {
},
'src/main/index.ts': {
suite: 'test/main/index-process.test.ts',
- evidence: 'spawn',
+ evidence: 'ORKAS_RELAUNCH_OWNER_PID',
},
'src/main/features/video_studio.ts': {
suite: 'test/main/features/video_studio_native_qa.test.ts',