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): say why a local model deployment stopped
chendongdong9127dd1dcb4d
diff --git a/apps/desktop/src/main/local-server.test.ts b/apps/desktop/src/main/local-server.test.tsindex b214a0aa..ddfbf7a2 100644--- a/apps/desktop/src/main/local-server.test.ts+++ b/apps/desktop/src/main/local-server.test.ts@@ -1570,12 +1570,17 @@ describe("LocalServerModule", () => {state: "waiting_user",errorCode: "LOCAL_MODELS_APPROVAL_REQUIRED",localModelsPlan: { planId: "a".repeat(64) },+ message: "Review the plan before installing.",}),);await f.host.start();const failure = f.module.begin({ runtime: "pi" });await expect(failure).rejects.toThrow("can't run the local model");await expect(failure).rejects.not.toThrow("free memory");+ // The installer's own reason follows the advice.+ await expect(failure).rejects.toThrow(+ "Choose another AI runtime and try again. (Review the plan before installing.)",+ );expect(f.api.retried).toEqual([]);expect(f.module.status().phase).toBe("failed");await f.host.stop("quit");diff --git a/apps/desktop/src/main/local-server.ts b/apps/desktop/src/main/local-server.tsindex 8b3c2577..f1469212 100644--- a/apps/desktop/src/main/local-server.ts+++ b/apps/desktop/src/main/local-server.ts@@ -2636,9 +2636,9 @@ export class InstallerApi {// Only the planner finding no model that fits can be helped by// freeing memory; free memory is what it measures at that moment.job.errorCode === "LOCAL_MODELS_UNAVAILABLE"- ? "This computer can't run the local model right now. Close other programs to free memory, or choose another AI runtime, and try again."+ ? `This computer can't run the local model right now. Close other programs to free memory, or choose another AI runtime, and try again.${job.message ? ` (${job.message})` : ""}`: LOCAL_MODEL_FAILURES.has(job.errorCode ?? "")- ? "This computer can't run the local model right now. Choose another AI runtime and try again."+ ? `This computer can't run the local model right now. Choose another AI runtime and try again.${job.message ? ` (${job.message})` : ""}`: job.message || "The installation stopped",);await delay(this.#pollMs, undefined, { signal });diff --git a/packages/local-installation/src/local-models.test.ts b/packages/local-installation/src/local-models.test.tsindex a0946f55..98dbf118 100644--- a/packages/local-installation/src/local-models.test.ts+++ b/packages/local-installation/src/local-models.test.ts@@ -169,6 +169,27 @@ test("applies exactly the approved saved plan and binds only the upstream verifi),).toEqual(f.binding);});+test("reports why the planner refused and logs its output", async () => {+ const f = await fixture();+ const events: string[] = [];+ f.call.mockImplementation(async () => ({+ code: 2,+ stdout: "",+ stderr: "stack: no verified LLM fits this computer\n",+ }));+ const result = await prepareLocalModels(+ f.instance,+ { ...f.options, onEvent: (event) => events.push(event.message ?? "") },+ { localmodels: f.call },+ );+ expect(result).toMatchObject({+ details: { code: "LOCAL_MODELS_UNAVAILABLE" },+ message: expect.stringContaining(+ "stack: no verified LLM fits this computer",+ ),+ });+ expect(events.join("\n")).toContain("localmodels stack plan exited with");+});test("never records a successful binding when apply fails", async () => {const f = await fixture();await prepareLocalModels(f.instance, f.options, { localmodels: f.call });@@ -189,6 +210,29 @@ test("never records a successful binding when apply fails", async () => {stat(path.join(f.home, "runtime/localmodels/binding.json")),).rejects.toThrow();});+test("reports why a deployment stopped, from output that is not captured", async () => {+ const f = await fixture();+ await prepareLocalModels(f.instance, f.options, { localmodels: f.call });+ const original = f.call.getMockImplementation()!;+ f.call.mockImplementation(async (...a) => {+ if (a[1][1] !== "apply") return original(...a);+ a[2]!.onOutput!(+ '{"event":"progress","component":"llm","phase":"download","done":1,"total":2}\n',+ );+ a[2]!.onOutput!("stack: port 8080 is held by another program\n");+ return { code: 1, stdout: "", stderr: "" };+ });+ const result = await prepareLocalModels(+ f.instance,+ { ...f.options, localModelsApproval: f.id },+ { localmodels: f.call },+ );+ expect(result).toMatchObject({+ details: { code: "LOCAL_MODELS_RECOVERY_REQUIRED" },+ message:+ "Local model installation or verification did not finish: stack: port 8080 is held by another program Existing resources were preserved.",+ });+});test("forwards actual split JSONL byte counters but never raw output", async () => {const f = await fixture();await prepareLocalModels(f.instance, f.options, { localmodels: f.call });diff --git a/packages/local-installation/src/local-models.ts b/packages/local-installation/src/local-models.tsindex d24d302f..cabc2020 100644--- a/packages/local-installation/src/local-models.ts+++ b/packages/local-installation/src/local-models.ts@@ -10,6 +10,7 @@ import {type Instance,} from "./instance.js";import type { InstallOutcome, InstallerEvent } from "./events.js";+import { localmodelsFailure } from "./localmodels-failure.js";import { runLocalmodels } from "./localmodels-tool.js";import {readSetupChoice,@@ -279,12 +280,31 @@ export async function prepareLocalModels((await readGpuSharing(instance)) ??DEFAULT_GPU_SHARING;const invoke = dependencies.localmodels ?? runLocalmodels;+ // Says why localmodels refused: its cause in the outcome, its redacted+ // output in the installer log.+ const refused = (+ code: string,+ text: string,+ args: string[],+ result: { code: number; stdout: string; stderr: string },+ ) => {+ const { cause, log } = localmodelsFailure(args, result);+ for (const message of log)+ options.onEvent({ kind: "log", stage: "runtime", message });+ return action(+ code,+ `${text}${cause ? `: ${cause}` : "."} Existing resources were preserved.`,+ );+ };const command = async (args: string[]) => {let buffer = "";- return invoke(home, args, {+ // The end of an uncaptured run's output, without its byte counters.+ let tail = "";+ const captured = !(args[0] === "stack" && args[1] === "apply");+ const result = await invoke(home, args, {signal: options.signal,timeoutMs: args[1] === "apply" ? undefined : 120000,- capture: !(args[0] === "stack" && args[1] === "apply"),+ capture: captured,onEvent: options.onEvent,onOutput: (chunk) => {buffer += chunk;@@ -298,13 +318,20 @@ export async function prepareLocalModels(try {event = JSON.parse(line);} catch {+ if (!captured) tail = `${tail}${line}\n`.slice(-8000);continue;}+ if (+ !captured &&+ (event as { event?: unknown } | null)?.event !== "progress"+ )+ tail = `${tail}${line}\n`.slice(-8000);const progress = stackProgress(event);if (progress) options.onEvent(progress);}},});+ return captured ? result : { ...result, stderr: tail };};if (!saved && options.localModelsApproval)return action(@@ -328,9 +355,11 @@ export async function prepareLocalModels("--json",]);if (result.code !== 0)- return action(+ return refused("LOCAL_MODELS_UNAVAILABLE",- "The upstream planner could not create a local model plan. Existing resources were preserved.",+ "The upstream planner could not create a local model plan",+ ["stack", "plan"],+ result,);const generated = await readPrivate(temporary);if (!generated)@@ -423,9 +452,11 @@ export async function prepareLocalModels("--jsonl",]);if (applied.code !== 0)- return action(+ return refused("LOCAL_MODELS_RECOVERY_REQUIRED",- "Local model installation or verification did not finish. Existing resources were preserved.",+ "Local model installation or verification did not finish",+ ["stack", "apply"],+ applied,);const observed = await observe();if (!observed?.ready)