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(local-installation): retry a runtime install once after a Windows version probe failure

shoudi zheng5e50acd43dfd
diff --git a/packages/local-installation/src/managed-runtimes.test.ts b/packages/local-installation/src/managed-runtimes.test.ts
index bf707625..0423a51e 100644
--- a/packages/local-installation/src/managed-runtimes.test.ts
+++ b/packages/local-installation/src/managed-runtimes.test.ts
@@ -293,3 +293,81 @@ it("names the upstream cause of a failed Harness apply and logs its output", asy
});
expect(events.join("\n")).toContain("HARNESS_DOWNLOAD_FAILED");
});
+
+function applyFailing(failures: string[]) {
+ return vi.fn(async (_home: string, args: string[]) => {
+ if (args[1] === "plan")
+ await writeFile(
+ args[args.indexOf("--out") + 1]!,
+ JSON.stringify({
+ schema: "localmodels.harness-plan/v1",
+ id: "a".repeat(64),
+ runtime: "pi",
+ }),
+ );
+ const code = args[1] === "apply" ? failures.shift() : undefined;
+ return {
+ code: code ? 1 : 0,
+ stdout: code
+ ? JSON.stringify({ schema: "localmodels.harness-error/v1", code })
+ : args[1] === "status"
+ ? JSON.stringify(status("pi", true))
+ : "",
+ stderr: "",
+ };
+ });
+}
+const applies = (localmodels: ReturnType<typeof applyFailing>) =>
+ localmodels.mock.calls.filter(([, args]) => args[1] === "apply");
+
+it("retries a Windows Runtime version execution failure once", async () => {
+ const options = { ...(await fixture()), platform: "win32" as const };
+ const localmodels = applyFailing(["RUNTIME_VERSION_EXECUTION_FAILED"]);
+ expect(
+ await installNativeRuntime("pi", options, { localmodels }),
+ ).toMatchObject({ state: "ready" });
+ expect(applies(localmodels)).toHaveLength(2);
+ expect(applies(localmodels)[1]![1]).toEqual(applies(localmodels)[0]![1]);
+ expect(options.onEvent).toHaveBeenCalledWith(
+ expect.objectContaining({ kind: "log", stage: "runtime" }),
+ );
+});
+
+it("surfaces the second Windows Runtime version execution failure", async () => {
+ const options = { ...(await fixture()), platform: "win32" as const };
+ const localmodels = applyFailing([
+ "RUNTIME_VERSION_EXECUTION_FAILED",
+ "RUNTIME_VERSION_EXECUTION_FAILED",
+ ]);
+ await expect(
+ installNativeRuntime("pi", options, { localmodels }),
+ ).rejects.toMatchObject({ code: "RUNTIME_VERSION_EXECUTION_FAILED" });
+ expect(applies(localmodels)).toHaveLength(2);
+});
+
+it.each([
+ ["linux", "RUNTIME_VERSION_EXECUTION_FAILED"],
+ ["win32", "RUNTIME_VERSION_MISMATCH"],
+] as const)("does not retry on %s for %s", async (platform, code) => {
+ const options = { ...(await fixture()), platform };
+ const localmodels = applyFailing([code]);
+ await expect(
+ installNativeRuntime("pi", options, { localmodels }),
+ ).rejects.toMatchObject({ code });
+ expect(applies(localmodels)).toHaveLength(1);
+});
+
+it("does not retry once the install is cancelled during the wait", async () => {
+ const controller = new AbortController();
+ const options = {
+ ...(await fixture()),
+ signal: controller.signal,
+ platform: "win32" as const,
+ onEvent: vi.fn(() => controller.abort()),
+ };
+ const localmodels = applyFailing(["RUNTIME_VERSION_EXECUTION_FAILED"]);
+ await expect(
+ installNativeRuntime("pi", options, { localmodels }),
+ ).rejects.toThrow();
+ expect(applies(localmodels)).toHaveLength(1);
+});
diff --git a/packages/local-installation/src/managed-runtimes.ts b/packages/local-installation/src/managed-runtimes.ts
index c7a25ba8..634c5fa1 100644
--- a/packages/local-installation/src/managed-runtimes.ts
+++ b/packages/local-installation/src/managed-runtimes.ts
@@ -1,5 +1,6 @@
import { mkdtemp, readFile, rm, realpath } from "node:fs/promises";
import path from "node:path";
+import { setTimeout as delay } from "node:timers/promises";
import { readSetupChoice } from "./setup-selection.js";
import { privateDirectory } from "./instance.js";
import { runLocalmodels } from "./localmodels-tool.js";
@@ -240,23 +241,47 @@ export async function installNativeRuntime(
!/^[a-f0-9]{64}$/.test(plan.id)
)
throw unavailable();
- options.signal.throwIfAborted();
- const applied = await tool(
- options.home,
- ["harness", "apply", file, "--approve", plan.id, "--jsonl"],
- {
- signal: options.signal,
- env: options.env,
- timeoutMs: 20 * 60000,
- onEvent: options.onEvent,
- },
- );
- if (applied.code !== 0)
- throw unavailable({
- args: ["harness", "apply"],
- result: applied,
- onEvent: options.onEvent,
+ const apply = async () => {
+ options.signal.throwIfAborted();
+ const applied = await tool(
+ options.home,
+ ["harness", "apply", file, "--approve", plan.id, "--jsonl"],
+ {
+ signal: options.signal,
+ env: options.env,
+ timeoutMs: 20 * 60000,
+ onEvent: options.onEvent,
+ },
+ );
+ if (applied.code !== 0)
+ throw unavailable({
+ args: ["harness", "apply"],
+ result: applied,
+ onEvent: options.onEvent,
+ });
+ };
+ try {
+ await apply();
+ } catch (error) {
+ // On Windows the kit's version probe right after unpacking can fail
+ // to spawn the fresh executable (antivirus still holds it), which it
+ // reports as an execution failure. One later attempt usually succeeds;
+ // it downloads again because the kit discards its stage on failure.
+ if (
+ (options.platform ?? process.platform) !== "win32" ||
+ options.signal.aborted ||
+ (error as { code?: string })?.code !==
+ "RUNTIME_VERSION_EXECUTION_FAILED"
+ )
+ throw error;
+ options.onEvent?.({
+ kind: "log",
+ stage: "runtime",
+ message: `The ${runtime} version check failed right after install; retrying once.\n`,
});
+ await delay(3_000, undefined, { signal: options.signal });
+ await apply();
+ }
const state = await inspectRuntime(runtime, options, dependencies);
if (!state.installed) throw unavailable();
return {