Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
fix(local-installation): reserve saved LiveKit ports during initialization
Afloatf37fdbdbc111
diff --git a/packages/local-installation/AGENTS.md b/packages/local-installation/AGENTS.mdindex 31ad1b58..4c7c68f5 100644--- a/packages/local-installation/AGENTS.md+++ b/packages/local-installation/AGENTS.md@@ -46,7 +46,9 @@ the environment file.Every port the installer chooses (`ports.ts`) must be free on both127.0.0.1 and ::1 with nothing answering there: `localhost` resolves to ::1first on macOS, and a program on ::1 alone would answer for a service that-bound 127.0.0.1 without an error. The web static host listens on both. Each+bound 127.0.0.1 without an error. The web static host listens on both.+Creating an instance also reserves other instances' saved LiveKit HTTP and RTC+ports, even while their voice services are stopped. Eachstart re-checks a stopped service's ports and moves one another program tookto a free port, persisted in `instance.json` or `livekit.env`, so the servicerestarts with the new environment. The web port is the product origindiff --git a/packages/local-installation/src/instance.test.ts b/packages/local-installation/src/instance.test.tsindex 455775bc..27429c62 100644--- a/packages/local-installation/src/instance.test.ts+++ b/packages/local-installation/src/instance.test.ts@@ -4,6 +4,7 @@ import path from "node:path";import net from "node:net";import { parseEnv } from "node:util";import { afterEach, expect, it } from "vitest";+import { prepareLiveKitSettings } from "./native-livekit.js";import {type Instance,initializeInstance,@@ -177,6 +178,24 @@ it("does not assign another stopped instance explicit port", async () => {initializeInstance({ name: "second", home: root, port: first.port }),).rejects.toThrow(/port/i);});+it.each(["httpPort", "rtcPort"] as const)(+ "keeps a stopped instance's LiveKit %s reserved when creating another instance",+ async (key) => {+ const root = await home();+ const first = await initializeInstance({ name: "first", home: root });+ const settings = await prepareLiveKitSettings(+ first.root,+ new Set([first.port]),+ );+ const settingsFile = path.join(first.root, "livekit.env");+ const saved = await readFile(settingsFile, "utf8");+ await expect(+ initializeInstance({ name: "second", home: root, port: settings[key] }),+ ).rejects.toThrow("Port is reserved by another instance");+ expect(await loadInstance({ name: "second", home: root })).toBeUndefined();+ expect(await readFile(settingsFile, "utf8")).toBe(saved);+ },+);it("isolates the Compose project when two homes use the same instance name", async () => {const firstHome = await mkdtemp(path.join(tmpdir(), "linger-first-"));const secondHome = await mkdtemp(path.join(tmpdir(), "linger-second-"));diff --git a/packages/local-installation/src/instance.ts b/packages/local-installation/src/instance.tsindex bf08ddc2..77f15a48 100644--- a/packages/local-installation/src/instance.ts+++ b/packages/local-installation/src/instance.ts@@ -8,6 +8,7 @@ import {} from "./private-files.js";import { LEGACY_PROJECT_PREFIX, lingerHome } from "./home.js";import { freePort, portFree } from "./ports.js";+import { readLiveKitSettings } from "./native-livekit.js";import path from "node:path";import { DatabaseSync } from "node:sqlite";import { parseEnv } from "node:util";@@ -206,6 +207,10 @@ export async function initializeInstance(reserved.add(other.port);for (const port of Object.values(other.source?.ports ?? {}))reserved.add(port);+ const livekit = await readLiveKitSettings(other.root).catch(+ () => undefined,+ );+ if (livekit) reserved.add(livekit.httpPort).add(livekit.rtcPort);}}if (options.port !== undefined && reserved.has(options.port))