Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(ok): bind the dev-launched server to IPv4 loopback so its MCP can reach it (#3169)
serafin-garcia658d33d5e878
diff --git a/.changeset/dev-server-loopback-bind.md b/.changeset/dev-server-loopback-bind.mdnew file mode 100644index 000000000..566b3ee5d--- /dev/null+++ b/.changeset/dev-server-loopback-bind.md@@ -0,0 +1,5 @@+---+"@inkeep/open-knowledge": patch+---++Agents can now reach a project opened from a development build of the desktop app. The dev launch path bound its server to `localhost`, which macOS resolves IPv6-first — so the server listened on `[::1]` while the MCP server, the agent keepalive, and `ok ps` all dial numeric IPv4 loopback. Nothing was listening at the address they called, so tool calls against that project failed and the agent's connection retried forever, even though the editor window itself worked normally. Development launches now bind the same numeric IPv4 loopback address that `ok start` already uses, so a signed release and any number of local development builds can run side by side with each project reachable by its own agent.diff --git a/packages/desktop/src/main/window-manager.ts b/packages/desktop/src/main/window-manager.tsindex 5c114c817..8134ddbc9 100644--- a/packages/desktop/src/main/window-manager.ts+++ b/packages/desktop/src/main/window-manager.ts@@ -28,6 +28,7 @@import { readFileSync, realpathSync } from 'node:fs';import { basename, dirname, join, resolve } from 'node:path';import {+ DEFAULT_SERVER_HOST,DEFAULT_SIGTERM_GRACE_MS,DEFAULT_SIGTERM_POLL_MS,SPAWN_ERROR_LOG,@@ -1816,7 +1817,15 @@ export class WindowManager {contentDir: projectPath,projectDir: projectPath,port: 0,- host: 'localhost',+ // Numeric IPv4 loopback, NOT `localhost`. macOS resolves `localhost`+ // IPv6-first, so `listen(port, 'localhost')` binds `[::1]` only —+ // while every dialer (the MCP shim, keepalive WS, `ok ps`) uses+ // `DEFAULT_SERVER_HOST`, which is numeric IPv4. The mismatch made a+ // dev-launched project's server unreachable to its own MCP: the+ // keepalive WS errored and reconnected forever while the window+ // itself worked fine. `ok start` already resolves to this constant,+ // so this keeps the dev boot path on the same address as every other.+ host: DEFAULT_SERVER_HOST,didEnsureGit: opts.didEnsureGit === true,consentVersion: opts.consentVersion ?? 1,// Conditional spread (matches `localOpCliArgs` below) keeps thediff --git a/packages/desktop/tests/main/window-manager.test.ts b/packages/desktop/tests/main/window-manager.test.tsindex 18ea54960..13ddf955a 100644--- a/packages/desktop/tests/main/window-manager.test.ts+++ b/packages/desktop/tests/main/window-manager.test.ts@@ -2,6 +2,7 @@ import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';import { setTimeout as wait } from 'node:timers/promises';+import { DEFAULT_SERVER_HOST } from '@inkeep/open-knowledge-core';import { beforeEach, describe, expect, test, vi } from 'vitest';import type { ShowGateRegistry } from '../../src/main/show-gate.ts';import {@@ -266,7 +267,7 @@ describe('WindowManager', () => {contentDir: '/tmp/test-project',projectDir: '/tmp/test-project',port: 0,- host: 'localhost',+ host: '127.0.0.1',didEnsureGit: false,consentVersion: 1,// dirname(rendererEntryPath) — the React-shell dist dir the utility@@ -288,6 +289,30 @@ describe('WindowManager', () => {expect(env.windows[0]?.loadFile).toHaveBeenCalledWith('/fake/renderer/index.html');});+ test('createProjectWindow binds the utility server to numeric IPv4 loopback, never a hostname', async () => {+ // macOS resolves `localhost` IPv6-first, so `listen(port, 'localhost')`+ // binds `[::1]` ONLY. Every dialer — the MCP shim, the keepalive WS, and+ // `ok ps` — uses DEFAULT_SERVER_HOST, which is numeric IPv4. Passing a+ // hostname here makes a dev-launched project's server unreachable to its+ // own MCP: the keepalive errors and reconnects forever while the window+ // itself works fine, because the window talks to the utility in-process+ // and never dials. Assert the literal AND the constant so neither side+ // can drift into a name.+ const wm = new WindowManager(env.deps);+ const promise = wm.createProjectWindow({ projectPath: '/tmp/loopback-bind' });++ const utility = env.utilities[0];+ if (!utility) throw new Error('utility not forked');+ const payload = (utility.postMessage as ReturnType<typeof vi.fn>).mock.calls[0]?.[0] as {+ opts: { host: string };+ };+ expect(payload.opts.host).toBe('127.0.0.1');+ expect(payload.opts.host).toBe(DEFAULT_SERVER_HOST);++ utility.fire({ type: 'ready', port: 51999, apiOrigin: 'http://127.0.0.1:51999' });+ await promise;+ });+test('createProjectWindow forwards localOpCliArgs into the utility init IPC payload', async () => {// localOpCliArgs must reach the utility init payload so// the API server can spawn the CLI in packaged builds (where open-knowledge@@ -342,7 +367,7 @@ describe('WindowManager', () => {contentDir: '/tmp/dev-mode-project',projectDir: '/tmp/dev-mode-project',port: 0,- host: 'localhost',+ host: '127.0.0.1',didEnsureGit: false,consentVersion: 1,},