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): convert the chosen install location before resuming it

claude-opus-5-5-medium90bedf1966d6
diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.md
index 51bdcd44..e29c3796 100644
--- a/apps/desktop/AGENTS.md
+++ b/apps/desktop/AGENTS.md
@@ -260,14 +260,15 @@ Gateway and runs Agents. The daemon exits with the app.
(logged as `desktop.legacy_user_data_kept`); one without a credential is set
aside as `Linger.before-move-<time>`, so the Computer keeps its identity.
LocalServer runs `installer.js --migrate` when an instance record still
- carries a `simplex-` project name, before it reads
- `desktop/local-server.json`
+ carries a `simplex-` project name, in the default home and in the home
+ `desktop/local-server.json` names when the person chose another install
+ location, before it resumes
(`packages/local-installation/src/legacy-migration.ts`). Instances the
installer left unconverted are logged as
- `local_server.legacy_instance_skipped` with their reason and do not hold
- the app back; only when `desktop` itself stayed unconverted, or the
- installer could not run, LocalServer enters the failed state with that
- reason, and Retry runs the migration again. There is
+ `local_server.legacy_instance_skipped` with their home and reason and do
+ not hold the app back; only when `desktop` in the home in use stayed
+ unconverted, or the installer could not run there, LocalServer enters the
+ failed state with that reason, and Retry runs the migration again. There is
no downgrade path: an older build reads neither the converted instances nor
the moved data folder. The bundle ID and
Windows AppUserModelID are `com.simplexai.linger.desktop.preview`. The
diff --git a/apps/desktop/src/main/local-server.test.ts b/apps/desktop/src/main/local-server.test.ts
index 45342c16..18440a42 100644
--- a/apps/desktop/src/main/local-server.test.ts
+++ b/apps/desktop/src/main/local-server.test.ts
@@ -72,6 +72,21 @@ if (args.includes("--user-keys")) {
process.stdout.write(JSON.stringify({ saved: names }) + "\n");
process.exit(0);
}
+if (args.includes("--migrate")) {
+ // Converts every legacy instance record, except a "desktop" that
+ // migrate-skips holds back.
+ const holds = fs.existsSync(path.join(home, "migrate-skips"));
+ const instances = path.join(home, "instances");
+ for (const name of fs.existsSync(instances) ? fs.readdirSync(instances) : []) {
+ if (holds && name === "desktop") continue;
+ const file = path.join(instances, name, "instance.json");
+ const record = JSON.parse(fs.readFileSync(file, "utf8"));
+ fs.writeFileSync(file, JSON.stringify({ ...record, project: record.project.replace(/^simplex-/, "linger-") }));
+ }
+ const skipped = holds ? [{ instance: "desktop", reason: "Its Computer is running 1 task(s)." }] : [];
+ process.stdout.write(JSON.stringify({ skipped }) + "\n");
+ process.exit(0);
+}
fs.mkdirSync(path.join(home, "installer"), { recursive: true });
fs.writeFileSync(path.join(home, "installer", "args.json"), JSON.stringify(args));
if (args.includes("--inspect")) {
@@ -151,6 +166,21 @@ const unpackedSource = (directory: string, name = "linger") => {
writeFileSync(path.join(directory, "package.json"), JSON.stringify({ name }));
};
+// An instance record an earlier Simplex app wrote under `home`.
+const legacyInstance = (home: string, name = "desktop") => {
+ mkdirSync(path.join(home, "instances", name), { recursive: true });
+ writeFileSync(
+ path.join(home, "instances", name, "instance.json"),
+ JSON.stringify({ mode: "source-native", project: `simplex-${name}-1` }),
+ );
+};
+const instanceProject = (home: string, name = "desktop") =>
+ (
+ JSON.parse(
+ readFileSync(path.join(home, "instances", name, "instance.json"), "utf8"),
+ ) as { project: string }
+ ).project;
+
const DONE = {
state: "waiting_user",
errorCode: "RUNTIME_AUTH_REQUIRED",
@@ -2484,6 +2514,100 @@ describe("LocalServerModule after a restart", () => {
await f.host.stop("quit");
});
+ it("converts and resumes an earlier Simplex installation in a location the person chose", async () => {
+ const root = tempDirectory();
+ const archive = sourceArchive(root);
+ const chosen = path.join(root, "chosen");
+ const legacy = path.join(chosen, "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) => {
+ // The default home holds only the record and a setup that never
+ // finished.
+ legacyInstance(home);
+ legacyInstance(chosen);
+ unpackedSource(legacy, "simplexai-coworkspace");
+ mkdirSync(path.join(home, "desktop"), { recursive: true });
+ writeFileSync(
+ path.join(home, "desktop", "local-server.json"),
+ JSON.stringify({
+ home: chosen,
+ repo: legacy,
+ origin: "http://localhost:3000",
+ }),
+ );
+ },
+ );
+ await f.host.start();
+ await vi.waitFor(() => expect(f.module.status().phase).toBe("ready"));
+ expect(instanceProject(f.home)).toBe("linger-desktop-1");
+ expect(instanceProject(chosen)).toBe("linger-desktop-1");
+ const current = path.join(
+ chosen,
+ "desktop",
+ "source",
+ archive.sha256.slice(0, 16),
+ );
+ const args = installerArgs(chosen);
+ expect(args).toContain("--resume");
+ expect(args[args.indexOf("--home") + 1]).toBe(chosen);
+ expect(args[args.indexOf("--source-repo") + 1]).toBe(current);
+ expect(existsSync(path.join(f.home, "desktop", "source"))).toBe(false);
+ expect(
+ JSON.parse(
+ readFileSync(path.join(f.home, "desktop", "local-server.json"), "utf8"),
+ ),
+ ).toEqual({ home: chosen, repo: current, origin: "http://localhost:3000" });
+ expect(readdirSync(path.dirname(current))).toEqual([
+ path.basename(current),
+ ]);
+ await f.host.stop("quit");
+ });
+
+ it("holds the app back only for the instance in use when a conversion is skipped", async () => {
+ const chosen = path.join(tempDirectory(), "chosen");
+ const setup = (skips: string) => (home: string) => {
+ legacyInstance(home);
+ legacyInstance(chosen);
+ writeFileSync(
+ path.join(skips === "default" ? home : chosen, "migrate-skips"),
+ "",
+ );
+ mkdirSync(path.join(home, "desktop"), { recursive: true });
+ writeFileSync(
+ path.join(home, "desktop", "local-server.json"),
+ JSON.stringify({
+ home: chosen,
+ repo: "/source",
+ origin: "http://localhost:3000",
+ }),
+ );
+ };
+ const unused = fixture({}, enrolled, setup("default"));
+ await unused.host.start();
+ await vi.waitFor(() => expect(unused.module.status().phase).toBe("ready"));
+ expect(instanceProject(unused.home)).toBe("simplex-desktop-1");
+ await unused.host.stop("quit");
+
+ rmSync(chosen, { recursive: true });
+ const used = fixture({}, enrolled, setup("chosen"));
+ await used.host.start();
+ await vi.waitFor(() => expect(used.module.status().phase).toBe("failed"));
+ expect(used.module.status().message).toMatch(
+ /could not convert this computer's installation.*running 1 task/,
+ );
+ expect(used.showStartFailed).toHaveBeenCalledOnce();
+ expect(existsSync(path.join(chosen, "installer", "args.json"))).toBe(false);
+ await used.host.stop("quit");
+ });
+
it("forgets the installation and its enrollment when the person sets up again", async () => {
const f = fixture({}, enrolled, (home) => {
record(home);
diff --git a/apps/desktop/src/main/local-server.ts b/apps/desktop/src/main/local-server.ts
index fb6242c0..7ef8be21 100644
--- a/apps/desktop/src/main/local-server.ts
+++ b/apps/desktop/src/main/local-server.ts
@@ -449,13 +449,21 @@ export class LocalServerModule implements Module {
async start(ctx: ModuleContext): Promise<void> {
this.#ctx = ctx;
- const migrationFailure = await this.#migrateLegacyHome(ctx);
// After a reboot the local services are gone; start them again while the
// window still points at them. A record of a Quick Install that stopped
// before this computer connected (the app quit or the computer went off
// during its last steps) is not resumed: setup shows instead, and its
// Install finishes that installation.
let record = await this.#readRecord();
+ // The record stays in the default home, but the installation it names
+ // may be in a location the person chose; that home converts too, and
+ // only its own instance holds the app back.
+ const inUse = record?.home ?? this.#options.home;
+ let migrationFailure: string | undefined;
+ for (const home of new Set([this.#options.home, inUse])) {
+ const failure = await this.#migrateLegacyHome(ctx, home);
+ if (home === inUse) migrationFailure = failure;
+ }
if (record) this.#home = record.home;
const config = ctx.config.get();
const resumes =
@@ -1241,26 +1249,30 @@ export class LocalServerModule implements Module {
}
// An install from before the rename keeps legacy names in its instance
- // records; the bundled installer converts them once, before a record is
- // read. Returns why this computer's instance stayed unconverted, for the
- // person to see; other instances it left behind are only logged.
- async #migrateLegacyHome(ctx: ModuleContext): Promise<string | undefined> {
+ // records; the bundled installer converts them once, before the services
+ // start. Returns why this computer's instance in `home` stayed
+ // unconverted, for the person to see; other instances it left behind are
+ // only logged.
+ async #migrateLegacyHome(
+ ctx: ModuleContext,
+ home: string,
+ ): Promise<string | undefined> {
if (
- !(await legacyMigrationPending(this.#options.home)) ||
+ !(await legacyMigrationPending(home)) ||
!existsSync(this.#installerScript())
)
return undefined;
const outcome = await new Promise<LegacyMigrationRun>((resolve) => {
const child = spawn(
process.execPath,
- [this.#installerScript(), "--home", this.#options.home, "--migrate"],
+ [this.#installerScript(), "--home", home, "--migrate"],
{
stdio: ["ignore", "pipe", "pipe"],
windowsHide: true,
env: {
...process.env,
ELECTRON_RUN_AS_NODE: "1",
- LINGER_HOME: this.#options.home,
+ LINGER_HOME: home,
},
},
);
@@ -1280,14 +1292,18 @@ export class LocalServerModule implements Module {
const { failure, skipped } = legacyMigrationResult(outcome, LOCAL_INSTANCE);
for (const entry of skipped)
ctx.log.warn("local_server.legacy_instance_skipped", {
+ home,
instance: entry.instance,
reason: entry.reason,
});
if (failure) {
- ctx.log.warn("local_server.home_migration_failed", { error: failure });
+ ctx.log.warn("local_server.home_migration_failed", {
+ home,
+ error: failure,
+ });
return failure;
}
- ctx.log.info("local_server.home_migrated", {});
+ ctx.log.info("local_server.home_migrated", { home });
return undefined;
}