Skip to content

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(desktop): show the low free memory warning before a local install

chendongdonga527fc3c5be9
diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.md
index f41ec8d5..66765272 100644
--- a/apps/desktop/AGENTS.md
+++ b/apps/desktop/AGENTS.md
@@ -117,8 +117,9 @@ Gateway and runs Agents. The daemon exits with the app.
Quick Install installs the `recommendation` of the localmodels setup
report (`installer.js --inspect`, run once as the setup window opens):
`local-models` is the planned model served by Pi, shown with the model,
- GPU, memory and download; otherwise the named runtime, with the tool's
- reason for no local model. The page adds no host rule of its own; while
+ GPU, memory and download, plus the tool's caveat when it has one (low free
+ memory, which the install's own plan can still fail on); otherwise the
+ named runtime, with the tool's reason for no local model. The page adds no host rule of its own; while
the check runs the button waits with a spinner and says what it waits for
(the first run downloads the localmodels tool, counted by `download`
event lines before the report), and Customize marks the
diff --git a/apps/desktop/src/main/local-server.test.ts b/apps/desktop/src/main/local-server.test.ts
index 1b08a6f3..f3fe6360 100644
--- a/apps/desktop/src/main/local-server.test.ts
+++ b/apps/desktop/src/main/local-server.test.ts
@@ -91,8 +91,9 @@ if (args.includes("--inspect")) {
process.exit(1);
}
process.stderr.write("Checked this computer in 1.5s.\n");
- const reasons = eligible ? [] : ["facts-unavailable"];
- const reasonMessages = eligible ? [] : ["nvidia-smi was not found"];
+ const lowMemory = eligible && fs.existsSync(path.join(home, "low-memory"));
+ const reasons = eligible ? (lowMemory ? ["free-memory-required"] : []) : ["facts-unavailable"];
+ const reasonMessages = eligible ? (lowMemory ? ["Close other programs before installing."] : []) : ["nvidia-smi was not found"];
const recommendation = eligible ? "local-models" : "codex";
process.stdout.write(JSON.stringify({ hardware, localModels: { eligible, reasons, reasonMessages, estimate }, recommendation }) + "\n");
process.exit(0);
@@ -1386,6 +1387,28 @@ describe("LocalServerModule", () => {
info.mockRestore();
});
+ it("keeps the tool's free-memory warning for an eligible computer", async () => {
+ const f = fixture({ checkout: "/src" }, {}, (home) => {
+ mkdirSync(home, { recursive: true });
+ writeFileSync(path.join(home, "low-memory"), "");
+ });
+ await f.host.start();
+ f.module.inspect();
+ await vi.waitFor(() =>
+ expect(f.module.status().localModels).toMatchObject({
+ state: "checked",
+ eligible: true,
+ reasons: [
+ {
+ code: "free-memory-required",
+ message: "Close other programs before installing.",
+ },
+ ],
+ recommendation: "local-models",
+ }),
+ );
+ });
+
it("approves the deployment of the chosen local model", async () => {
const api = installerApi([], {
state: "waiting_user",
@@ -1425,6 +1448,23 @@ describe("LocalServerModule", () => {
await f.host.stop("quit");
});
+ it("asks to free memory only when no local model fits", async () => {
+ const f = fixture(
+ withCheckout,
+ {},
+ checkout,
+ installerApi([], {
+ state: "waiting_user",
+ errorCode: "LOCAL_MODELS_UNAVAILABLE",
+ }),
+ );
+ await f.host.start();
+ await expect(f.module.begin({ runtime: "local" })).rejects.toThrow(
+ "Close other programs to free memory",
+ );
+ await f.host.stop("quit");
+ });
+
it("approves no local model the person did not choose", async () => {
const f = fixture(
withCheckout,
@@ -1437,9 +1477,9 @@ describe("LocalServerModule", () => {
}),
);
await f.host.start();
- await expect(f.module.begin({ runtime: "pi" })).rejects.toThrow(
- "can't run the local model",
- );
+ 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");
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.ts
index 44b3afe9..d1f1108a 100644
--- a/apps/desktop/src/main/local-server.ts
+++ b/apps/desktop/src/main/local-server.ts
@@ -111,8 +111,8 @@ export type LocalModelsCheck =
readonly gpu?: string;
// Present only when eligible.
readonly model?: LocalModel;
- // Why not, as the localmodels tool's code and words; present only
- // when not eligible.
+ // The localmodels tool's code and words for why not, or, when
+ // eligible, for what could still stop the install (free memory).
readonly reasons?: readonly SetupReason[];
// The localmodels tool's pick for this computer, which Quick Install
// installs; the page adds no rule of its own.
@@ -667,7 +667,7 @@ export class LocalServerModule implements Module {
},
}
: {}),
- ...(!eligible && reasons.length ? { reasons } : {}),
+ ...(reasons.length ? { reasons } : {}),
...(recommendation ? { recommendation } : {}),
};
}
@@ -2456,9 +2456,13 @@ export class InstallerApi {
}
if (!["queued", "running"].includes(job.state))
throw new Error(
- LOCAL_MODEL_FAILURES.has(job.errorCode ?? "")
- ? "This computer can't run the local model right now. Choose another AI runtime and try again."
- : job.message || "The installation stopped",
+ // 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."
+ : LOCAL_MODEL_FAILURES.has(job.errorCode ?? "")
+ ? "This computer can't run the local model right now. Choose another AI runtime and try again."
+ : job.message || "The installation stopped",
);
await delay(this.#pollMs, undefined, { signal });
job = await this.#json<Job>(`/api/jobs/${encodeURIComponent(job.id)}`);
diff --git a/apps/desktop/src/shared/setup.ts b/apps/desktop/src/shared/setup.ts
index aaa2db29..f00d8c3a 100644
--- a/apps/desktop/src/shared/setup.ts
+++ b/apps/desktop/src/shared/setup.ts
@@ -109,8 +109,8 @@ export type SetupLocalModelsCheck =
readonly diskBytes: number | null;
readonly memoryBytes: number | null;
};
- // Why not, as the localmodels tool's code and words; when not
- // eligible.
+ // The localmodels tool's code and words for why not, or, when
+ // eligible, for what could still stop the install (free memory).
readonly reasons?: readonly {
readonly code: string;
readonly message?: string;
diff --git a/apps/desktop/src/shell/setup.html b/apps/desktop/src/shell/setup.html
index 6d39be75..1e79becf 100644
--- a/apps/desktop/src/shell/setup.html
+++ b/apps/desktop/src/shell/setup.html
@@ -2258,7 +2258,10 @@
gigabytes(model.downloadBytes) + " download",
]
.filter(Boolean)
- .join(" · ")
+ .join(" · ") +
+ (models.reasons?.[0]?.message
+ ? ". " + models.reasons[0].message
+ : "")
: models.state === "checked" && !models.eligible
? "No local model: " +
(models.reasons?.[0]?.message ||