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): unpack the current source when resume finds a Simplex-era checkout

claude-opus-5-5-medium51c6a67b5960
diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.md
index 555f3c07..51bdcd44 100644
--- a/apps/desktop/AGENTS.md
+++ b/apps/desktop/AGENTS.md
@@ -166,8 +166,10 @@ Gateway and runs Agents. The daemon exits with the app.
file and renamed, so a power loss leaves the old record or none) and, while
the window still uses that origin and the computer is enrolled, restarts the
services on launch with `installer.js --resume`, which also restarts them
- when the instance's `user.env` changed. A source folder removed since is
- unpacked again from the app's package first. A Quick Install that stopped
+ when the instance's `user.env` changed. A source folder removed since, or
+ one the installer no longer accepts as a Linger checkout (such as one the
+ earlier Simplex app unpacked), is unpacked again from the app's package
+ first and replaces the recorded one. A Quick Install that stopped
before the computer enrolled is not resumed: setup shows again and Install
finishes it, reusing a finished job only while its origin answers (a stopped
server gets a new job, which starts the services again). The start failure
diff --git a/apps/desktop/src/main/local-server.test.ts b/apps/desktop/src/main/local-server.test.ts
index b657365a..45342c16 100644
--- a/apps/desktop/src/main/local-server.test.ts
+++ b/apps/desktop/src/main/local-server.test.ts
@@ -125,6 +125,10 @@ const sourceArchive = (root: string) => {
const tree = path.join(root, "tree", "linger-1.0.0", "scripts");
mkdirSync(tree, { recursive: true });
writeFileSync(path.join(tree, "source-native.mjs"), "");
+ writeFileSync(
+ path.join(path.dirname(tree), "package.json"),
+ JSON.stringify({ name: "linger" }),
+ );
const file = path.join(root, "linger.tar.gz");
execFileSync("tar", [
"-czf",
@@ -140,6 +144,13 @@ const sourceArchive = (root: string) => {
};
};
+// A source package an earlier app unpacked into `directory`, named `name`.
+const unpackedSource = (directory: string, name = "linger") => {
+ mkdirSync(path.join(directory, "scripts"), { recursive: true });
+ writeFileSync(path.join(directory, "scripts/source-native.mjs"), "");
+ writeFileSync(path.join(directory, "package.json"), JSON.stringify({ name }));
+};
+
const DONE = {
state: "waiting_user",
errorCode: "RUNTIME_AUTH_REQUIRED",
@@ -2285,7 +2296,7 @@ describe("LocalServerModule after a restart", () => {
enrolled,
(home) => {
const sources = path.join(home, "desktop", "source");
- mkdirSync(path.join(sources, "previous"), { recursive: true });
+ unpackedSource(path.join(sources, "previous"));
writeFileSync(
path.join(home, "desktop", "local-server.json"),
JSON.stringify({
@@ -2431,6 +2442,48 @@ describe("LocalServerModule after a restart", () => {
await f.host.stop("quit");
});
+ it("moves to the source package when the earlier Simplex app unpacked the one in use", async () => {
+ const root = tempDirectory();
+ const archive = sourceArchive(root);
+ const legacy = (home: string) =>
+ path.join(home, "desktop", "source", "simplex");
+ const f = fixture(
+ {
+ sourceArchive: {
+ url: "https://cdn.example/linger.tar.gz",
+ sha256: archive.sha256,
+ },
+ fetch: (async () => new Response(archive.bytes)) as typeof fetch,
+ },
+ enrolled,
+ (home) => {
+ unpackedSource(legacy(home), "simplexai-coworkspace");
+ writeFileSync(
+ path.join(home, "desktop", "local-server.json"),
+ JSON.stringify({
+ home,
+ repo: legacy(home),
+ origin: "http://localhost:3000",
+ }),
+ );
+ },
+ );
+ await f.host.start();
+ await vi.waitFor(() => expect(f.module.status().phase).toBe("ready"));
+ const sources = path.join(f.home, "desktop", "source");
+ const current = path.join(sources, archive.sha256.slice(0, 16));
+ const args = installerArgs(f.home);
+ expect(args[args.indexOf("--source-repo") + 1]).toBe(current);
+ expect(
+ JSON.parse(
+ readFileSync(path.join(f.home, "desktop", "local-server.json"), "utf8"),
+ ),
+ ).toMatchObject({ repo: current });
+ expect(readdirSync(sources)).toEqual([path.basename(current)]);
+ expect(f.module.sourceUpdateAvailable()).toBe(false);
+ await f.host.stop("quit");
+ });
+
it("forgets the installation and its enrollment when the person sets up again", async () => {
const f = fixture({}, enrolled, (home) => {
record(home);
@@ -2848,7 +2901,10 @@ describe("LocalServerModule on Windows", () => {
mkdirSync(path.join(source, hash), { recursive: true });
writeFileSync(path.join(source, hash, "half"), "");
await f.module.begin();
- expect(readdirSync(path.join(source, hash)).sort()).toEqual(["scripts"]);
+ expect(readdirSync(path.join(source, hash)).sort()).toEqual([
+ "package.json",
+ "scripts",
+ ]);
expect(f.module.status().phase).toBe("ready");
await f.host.stop("quit");
});
diff --git a/apps/desktop/src/main/local-server.ts b/apps/desktop/src/main/local-server.ts
index 7d679c24..fb6242c0 100644
--- a/apps/desktop/src/main/local-server.ts
+++ b/apps/desktop/src/main/local-server.ts
@@ -34,6 +34,7 @@ import {
import { downloadVerified } from "@linger/local-installation/download";
import { latestLegacyBackup } from "@linger/local-installation/legacy-database";
import { legacyMigrationPending } from "@linger/local-installation/home";
+import { validateSourceRepository } from "@linger/local-installation/source-checkout";
import type { LegacyInstanceSkipped } from "@linger/local-installation/legacy-migration";
import {
type SetupChoice,
@@ -2034,12 +2035,16 @@ export class LocalServerModule implements Module {
// The window would show the server as unreachable until it is back.
if (!(await this.#reachable(record.origin))) windows?.showStarting();
const newer = this.#newerSource(record);
- // A source folder removed since (by hand, or a cleanup that an uninstall
- // left half done) is unpacked again from this app's package.
+ // A source folder the installer no longer runs is unpacked again from
+ // this app's package: one removed since (by hand, or a cleanup that an
+ // uninstall left half done), or one the earlier Simplex app unpacked.
const repo =
this.#options.sourceArchive &&
!this.#options.checkout &&
- !existsSync(record.repo)
+ !(await validateSourceRepository(record.repo).then(
+ () => true,
+ () => false,
+ ))
? await this.#ensureSource(record.home, signal)
: record.repo;
await this.#runResume(record, repo, signal);