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): stop rename retries after cancellation

Afloata2ac68a65849
diff --git a/packages/local-installation/AGENTS.md b/packages/local-installation/AGENTS.md
index 4c7c68f5..66de30b4 100644
--- a/packages/local-installation/AGENTS.md
+++ b/packages/local-installation/AGENTS.md
@@ -216,6 +216,8 @@ leaves the partial file intact for the next attempt.
Move a freshly downloaded or unpacked file or folder into place with
`renameRetrying` from `fs-retry.ts`: on Windows antivirus and indexing hold
new files for a moment, and a plain rename then fails with EPERM.
+Cancellation is checked before every rename attempt, including after a
+retry wait, so a cancelled installation cannot publish the waiting file.
Setting `LINGER_LOCALMODELS_DEV_PYTHON` and `LINGER_LOCALMODELS_DEV_MODULE_DIR`
to absolute paths runs a local `localmodels` checkout instead of fetching the
diff --git a/packages/local-installation/src/fs-retry.test.ts b/packages/local-installation/src/fs-retry.test.ts
index 7257756b..0eef9478 100644
--- a/packages/local-installation/src/fs-retry.test.ts
+++ b/packages/local-installation/src/fs-retry.test.ts
@@ -1,4 +1,11 @@
-import { mkdir, mkdtemp, readdir, rm, writeFile } from "node:fs/promises";
+import {
+ mkdir,
+ mkdtemp,
+ readdir,
+ rename,
+ rm,
+ writeFile,
+} from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { afterEach, expect, it } from "vitest";
@@ -121,6 +128,45 @@ it("stops waiting when aborted", async () => {
).rejects.toThrow(/aborted/i);
});
+it("does not move a file when already aborted", async () => {
+ const root = await mkdtemp(path.join(tmpdir(), "linger-rename-"));
+ roots.push(root);
+ const from = path.join(root, "kit.partial");
+ const to = path.join(root, "kit");
+ await writeFile(from, "verified bytes");
+ const reason = new Error("Installation cancelled.");
+
+ await expect(
+ renameRetrying(from, to, { signal: AbortSignal.abort(reason) }),
+ ).rejects.toBe(reason);
+ expect(await readdir(root)).toEqual(["kit.partial"]);
+});
+
+it("does not publish a file after cancellation during a Windows retry wait", async () => {
+ const root = await mkdtemp(path.join(tmpdir(), "linger-rename-"));
+ roots.push(root);
+ const from = path.join(root, "kit.partial");
+ const to = path.join(root, "kit");
+ await writeFile(from, "verified bytes");
+ const controller = new AbortController();
+ const reason = new Error("Installation cancelled.");
+ let attempts = 0;
+
+ await expect(
+ renameRetrying(from, to, {
+ platform: "win32",
+ signal: controller.signal,
+ rename: async (source, destination) => {
+ if (++attempts === 1) throw locked();
+ await rename(source, destination);
+ },
+ sleep: async () => controller.abort(reason),
+ }),
+ ).rejects.toBe(reason);
+ expect(attempts).toBe(1);
+ expect(await readdir(root)).toEqual(["kit.partial"]);
+});
+
it("renames a real folder under a non-ASCII path", async () => {
const root = await mkdtemp(path.join(tmpdir(), "linger-rename-"));
roots.push(root);
diff --git a/packages/local-installation/src/fs-retry.ts b/packages/local-installation/src/fs-retry.ts
index b083b2bd..3aa256a3 100644
--- a/packages/local-installation/src/fs-retry.ts
+++ b/packages/local-installation/src/fs-retry.ts
@@ -34,6 +34,7 @@ export async function renameRetrying(
const started = now();
let wait = 50;
for (let attempt = 1; ; attempt++) {
+ options.signal?.throwIfAborted();
try {
await move(from, to);
return;