Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
PRD-9298 Fix desktop second-launch exit error on Linux (#6118)
Andrew Mikofalvyd8aa227a018c
diff --git a/.changeset/prd-9298-second-instance-exit.md b/.changeset/prd-9298-second-instance-exit.mdnew file mode 100644index 000000000..defa67f15--- /dev/null+++ b/.changeset/prd-9298-second-instance-exit.md@@ -0,0 +1,5 @@+---+"@inkeep/open-knowledge-desktop": patch+---++On Linux, opening OpenKnowledge while it is already running no longer prints a "sonic boom is not ready yet" error as the second launch exits.diff --git a/packages/desktop/src/main/desktop-logger.test.ts b/packages/desktop/src/main/desktop-logger.test.tsindex 18188990a..b3bd73c02 100644--- a/packages/desktop/src/main/desktop-logger.test.ts+++ b/packages/desktop/src/main/desktop-logger.test.ts@@ -1,11 +1,56 @@+import { spawnSync } from 'node:child_process';import { once } from 'node:events';-import { existsSync, mkdtempSync, rmSync } from 'node:fs';+import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';+import { pathToFileURL } from 'node:url';import pino from 'pino';import { afterEach, describe, expect, test, vi } from 'vitest';import { flushDesktopLogger, getLogger, getRootDesktopLogger } from './desktop-logger.ts';+describe('a process that exits in the same tick it first logs', () => {+ test('exits cleanly and the line reaches the log file', () => {+ const home = mkdtempSync(join(tmpdir(), 'ok-desktop-logs-exit-'));+ const loggerUrl = pathToFileURL(join(import.meta.dirname, 'desktop-logger.ts')).href;+ const { OK_CHANNEL: _channel, ...inheritedEnv } = process.env;+ try {+ const child = spawnSync(+ process.execPath,+ [+ '--conditions=development',+ '--input-type=module',+ '-e',+ `const { getLogger } = await import(${JSON.stringify(loggerUrl)});+ getLogger('exit-probe').info({}, 'logged before exit');+ process.exit(0);`,+ ],+ {+ encoding: 'utf-8',+ timeout: 20_000,+ env: {+ ...inheritedEnv,+ HOME: home,+ USERPROFILE: home,+ NODE_ENV: 'production',+ OK_LOG_LEVEL: 'info',+ },+ },+ );+ expect(child.stderr).not.toContain('sonic boom is not ready yet');+ expect(child.status, `signal=${child.signal}\n${child.stderr}`).toBe(0);+ const logFiles = readdirSync(home, { recursive: true, encoding: 'utf-8' }).filter((f) =>+ /desktop\.\d{4}-\d{2}-\d{2}\.log$/.test(f),+ );+ expect(logFiles).toHaveLength(1);+ expect(readFileSync(join(home, logFiles[0] as string), 'utf-8')).toContain(+ 'logged before exit',+ );+ } finally {+ rmSync(home, { recursive: true, force: true });+ }+ });+});+describe('flushDesktopLogger', () => {test('does not throw when called before any logging has initialized the destination', () => {expect(() => flushDesktopLogger()).not.toThrow();diff --git a/packages/desktop/src/main/desktop-logger.ts b/packages/desktop/src/main/desktop-logger.tsindex 0976e2fdf..f720f7d33 100644--- a/packages/desktop/src/main/desktop-logger.ts+++ b/packages/desktop/src/main/desktop-logger.ts@@ -1,4 +1,4 @@-import { mkdirSync, readdirSync, statSync, unlinkSync } from 'node:fs';+import { mkdirSync, openSync, readdirSync, statSync, unlinkSync } from 'node:fs';import { join } from 'node:path';import { okUserHomeDir } from '@inkeep/open-knowledge-core/server';import pino from 'pino';@@ -93,7 +93,7 @@ function getRootLogger(): pino.Logger {setTimeout(() => pruneLogsDir(desktopLogDirectory()), 5000);const filePath = join(desktopLogDirectory(), logFileName);- const dest = pino.destination({ dest: filePath, append: true, sync: false });+ const dest = pino.destination({ dest: openSync(filePath, 'a'), sync: false });rootDest = dest as unknown as { flushSync: () => void };rootLogger = pino(