Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
fix(bootstrap): only auto-start the backend for the local :8090 endpoint
KageBinarye4868a3e7f71
diff --git a/ix-cli/src/cli/__tests__/backend-autostart.test.ts b/ix-cli/src/cli/__tests__/backend-autostart.test.tsnew file mode 100644index 00000000..f374ab10--- /dev/null+++ b/ix-cli/src/cli/__tests__/backend-autostart.test.ts@@ -0,0 +1,38 @@+// Copyright 2026 Ix Infrastructure Inc.++import { afterEach, describe, expect, it } from "vitest";+import { canAutoStartBackend, ensureBackendAvailable } from "../bootstrap.js";++// An unreachable backend used to trigger `ix docker start` whatever the+// endpoint was. That command only ever starts the local compose on :8090, so+// for a remote or a second local backend it started unrelated containers and+// reported success while the configured endpoint stayed down.+describe("canAutoStartBackend", () => {+ it("allows the local default backend", () => {+ expect(canAutoStartBackend("http://localhost:8090")).toBe(true);+ expect(canAutoStartBackend("http://127.0.0.1:8090/")).toBe(true);+ });++ it("refuses a remote endpoint", () => {+ expect(canAutoStartBackend("https://ix.example.com")).toBe(false);+ expect(canAutoStartBackend("http://staging:8090")).toBe(false);+ });++ it("refuses a local backend on another port", () => {+ expect(canAutoStartBackend("http://localhost:9090")).toBe(false);+ });+});++describe("ensureBackendAvailable", () => {+ const saved = process.env.IX_ENDPOINT;+ afterEach(() => {+ if (saved === undefined) delete process.env.IX_ENDPOINT;+ else process.env.IX_ENDPOINT = saved;+ });++ it("names the unreachable endpoint instead of starting local containers", async () => {+ // Port 9 (discard) on loopback: nothing listens, the connection is refused.+ process.env.IX_ENDPOINT = "http://127.0.0.1:9";+ await expect(ensureBackendAvailable()).rejects.toThrow("Ix backend at http://127.0.0.1:9 is not reachable.");+ });+});diff --git a/ix-cli/src/cli/bootstrap.ts b/ix-cli/src/cli/bootstrap.tsindex e57fafd5..7fc63a74 100644--- a/ix-cli/src/cli/bootstrap.ts+++ b/ix-cli/src/cli/bootstrap.ts@@ -12,6 +12,7 @@ import { ixHome } from "./ix-home.js";import { stderr } from "./stderr.js";import { workspaceIdForPath } from "./system.js";import { readBackendHealth } from "./commands/upgrade.js";+import { isLocalEndpoint } from "./backend-version.js";export interface BootstrapResult {createdConfig: boolean;@@ -151,6 +152,23 @@ export function resolveWorkspaceId(cwd = process.cwd()): string | undefined {return (findWorkspaceForCwd(cwd) ?? getDefaultWorkspace())?.workspace_id;}+/**+ * Whether an unreachable `endpoint` is the backend `ix docker start` brings up.+ *+ * That command always starts the standalone compose on localhost:8090. For any+ * other endpoint -- a remote, a second local backend on another port -- it+ * starts containers the command then never talks to (and may collide with+ * someone else's on 8090), while the real endpoint stays down.+ */+export function canAutoStartBackend(endpoint: string): boolean {+ if (!isLocalEndpoint(endpoint)) return false;+ try {+ return new URL(endpoint).port === "8090";+ } catch {+ return false;+ }+}+/*** Ensure the backend is reachable. If not, auto-start via ix docker start.*/@@ -163,8 +181,14 @@ export async function ensureBackendAvailable(): Promise<void> {// ingest path, so without this it would never record at all.await readBackendHealth(client);} catch {+ if (!canAutoStartBackend(endpoint)) {+ throw new Error(`Ix backend at ${endpoint} is not reachable.`);+ }try {- execFileSync("ix", ["docker", "start"], { stdio: "inherit", timeout: 120000 });+ // This CLI's own entry point under this node, not `ix` off PATH: on+ // Windows `ix` is `ix.cmd`, which execFile cannot launch without a shell,+ // and PATH may name a different install.+ execFileSync(process.execPath, [process.argv[1], "docker", "start"], { stdio: "inherit", timeout: 120000 });} catch {throw new Error("Failed to start Ix backend. Run: ix docker start");}