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(installer): keep changed-password owners ready on resume
Kilyn7a75869c7ba9
diff --git a/packages/local-installation/AGENTS.md b/packages/local-installation/AGENTS.mdindex fe3b8b8e..54ed177a 100644--- a/packages/local-installation/AGENTS.md+++ b/packages/local-installation/AGENTS.md@@ -11,12 +11,15 @@ stop unrelated processes, pull mutable images, or delete volumes as recovery.Every installation runs natively from a Linger source checkout; Docker is notused.-The account file records provisioning history, not current database readiness.-Every installation verifies the saved credentials before reporting the account-ready. On HTTP 401, use the existing idempotent owner command and confirm login:-it can recreate a missing owner after a database replacement, but never resets-an existing password or replaces saved credentials. Other login failures stop-without provisioning.+The account file records provisioning history, not current database readiness+or a promise that its saved password is still current. On HTTP 401, the existing+idempotent owner command establishes whether this email owns the deployment and+can recreate a missing owner without resetting a password. Confirm login after+it: a provisioned owner whose password was deliberately changed remains ready+when the owner command succeeded and login still returns 401. This grants no+session and does not replace saved credentials. A failed owner command, other+login errors, or an unprovisioned account whose login fails must not be treated+as a changed password.Each instance directory holds `user.env` (0600), the only file a person edits:`COMPOSIO_API_KEY`, `SONIOX_API_KEY`, `XAI_API_KEY` and `TZ`@@ -70,8 +73,9 @@ migration, which refuses a database that already holds one. A database fromthe desktop app before the rename has `public.accounts` but no applied 852row in `goose_db_version`, so it can never migrate (`legacy-database.ts`).Once the database is up, Native checks for that; for such a database it-stops PostgreSQL, marks `local-account.json` as not provisioned (so the-account step creates the owner again with the same email and password) and+stops PostgreSQL, marks `local-account.json` as not provisioned (so private+login/enrollment reads refuse it until the account step confirms the owner in+the replacement database) andmoves `data/agent`, `data/artifacts`, `computer-enrollment.token` and, last,`native/postgres-data` into `simplex-backup-<UTC time>` in the instance,deleting nothing. The database moves last so that a run stopped partwaydiff --git a/packages/local-installation/src/account.test.ts b/packages/local-installation/src/account.test.tsindex a1a39e6b..40bf276e 100644--- a/packages/local-installation/src/account.test.ts+++ b/packages/local-installation/src/account.test.ts@@ -335,7 +335,7 @@ it("recreates a missing owner when the private file is already marked provisione),).toEqual(["/v0/auth/login", "/v0/auth/login", "/v0/auth/logout"]);});-it("rejects a provisioned account with a stale password without replacing credentials", async () => {+it("keeps an existing provisioned owner ready after the user changes their password", async () => {const f = await fixture();const saved = JSON.stringify({email: "[email protected]",@@ -348,9 +348,13 @@ it("rejects a provisioned account with a stale password without replacing credenvi.fn(async () => new Response("server-private-secret", { status: 401 })),);provisionOwner.mockResolvedValue(undefined);- await expect(ensureLocalAccount(f.instance, f.signal, owner)).rejects.toThrow(- "Local account sign-in failed after creation (HTTP 401). Credentials are preserved; existing accounts will not be reset.",- );+ await expect(+ ensureLocalAccount(f.instance, f.signal, owner),+ ).resolves.toEqual({+ email: "[email protected]",+ password: "saved-private-password",+ file: f.file,+ });expect(provisionOwner).toHaveBeenCalledOnce();expect(fetch).toHaveBeenCalledTimes(2);expect(await readFile(f.file, "utf8")).toBe(saved);@@ -393,3 +397,68 @@ it("preserves a provisioned account and hides details on a network failure", asyexpect(provisionOwner).not.toHaveBeenCalled();expect(await readFile(f.file, "utf8")).toBe(saved);});++it("does not trust a provisioned marker when owner confirmation and login both fail", async () => {+ const f = await fixture();+ const saved = JSON.stringify({+ email: "[email protected]",+ password: "saved-private-password",+ provisioned: true,+ });+ await writeFile(f.file, saved, { mode: 0o600 });+ vi.stubGlobal(+ "fetch",+ vi.fn(async () => new Response("server-private-secret", { status: 401 })),+ );+ provisionOwner.mockRejectedValue(new Error("private-owner-command-failure"));+ await expect(ensureLocalAccount(f.instance, f.signal, owner)).rejects.toThrow(+ "Local account sign-in failed after creation (HTTP 401). Credentials are preserved; existing accounts will not be reset.",+ );+ expect(await readFile(f.file, "utf8")).toBe(saved);+});+it.each([429, 503])(+ "does not accept a provisioned owner when the confirmation login fails with %s",+ async (status) => {+ const f = await fixture();+ const saved = JSON.stringify({+ email: "[email protected]",+ password: "saved-private-password",+ provisioned: true,+ });+ await writeFile(f.file, saved, { mode: 0o600 });+ let calls = 0;+ vi.stubGlobal(+ "fetch",+ vi.fn(+ async () =>+ new Response(null, { status: ++calls === 1 ? 401 : status }),+ ),+ );+ provisionOwner.mockResolvedValue(undefined);+ await expect(+ ensureLocalAccount(f.instance, f.signal, owner),+ ).rejects.toThrow(+ `Local account sign-in failed after creation (HTTP ${status}). Credentials are preserved; existing accounts will not be reset.`,+ );+ expect(await readFile(f.file, "utf8")).toBe(saved);+ },+);+it("does not report an existing provisioned owner ready after cancellation", async () => {+ const f = await fixture();+ const controller = new AbortController();+ const saved = JSON.stringify({+ email: "[email protected]",+ password: "saved-private-password",+ provisioned: true,+ });+ await writeFile(f.file, saved, { mode: 0o600 });+ vi.stubGlobal(+ "fetch",+ vi.fn(async () => new Response(null, { status: 401 })),+ );+ provisionOwner.mockImplementation(async () => controller.abort());+ await expect(+ ensureLocalAccount(f.instance, controller.signal, owner),+ ).rejects.toThrow();+ expect(await readFile(f.file, "utf8")).toBe(saved);+});diff --git a/packages/local-installation/src/account.ts b/packages/local-installation/src/account.tsindex b8b1e93e..072fc6d8 100644--- a/packages/local-installation/src/account.ts+++ b/packages/local-installation/src/account.ts@@ -94,8 +94,8 @@ interface LocalAccount {provisioned: boolean;}-// For a database made again from nothing: the next account step creates-// the owner again with the saved email and password.+// Blocks private login reads during database replacement until the account+// step has established the owner in the new database.export async function unprovisionLocalAccount(root: string): Promise<void> {const file = path.join(root, "local-account.json");const text = await readPrivate(file);@@ -124,6 +124,7 @@ export async function ensureLocalAccount(options: {email?: string;password?: string;+ // Resolves only when this email owns the deployment; never resets a password.provisionOwner: (email: string, password: string) => Promise<void>;},): Promise<{ email: string; file: string; password: string }> {@@ -210,8 +211,10 @@ export async function ensureLocalAccount(if (login.ok) return complete(login);if (login.status !== 401)throw new Error(`Local account login check failed (HTTP ${login.status})`);+ let ownerConfirmed = false;try {await options.provisionOwner(email, account.password);+ ownerConfirmed = true;} catch {// The command can fail after commit. Never expose diagnostics containing// private input; confirm ownership using the persisted password instead.@@ -222,6 +225,12 @@ export async function ensureLocalAccount(password: account.password,});if (confirmed.ok) return complete(confirmed);+ // An existing owner may have changed the password in Settings. The local+ // command confirms the owner exists, not that the saved password is current.+ if (account.provisioned && ownerConfirmed && confirmed.status === 401) {+ signal.throwIfAborted();+ return { email, file, password: account.password };+ }throw new Error(`Local account sign-in failed after creation (HTTP ${confirmed.status}). Credentials are preserved; existing accounts will not be reset.`,);diff --git a/packages/local-installation/src/legacy-database.test.ts b/packages/local-installation/src/legacy-database.test.tsindex 115768ca..f332fcb5 100644--- a/packages/local-installation/src/legacy-database.test.ts+++ b/packages/local-installation/src/legacy-database.test.ts@@ -3,6 +3,7 @@ import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";import { tmpdir } from "node:os";import path from "node:path";import { fileURLToPath } from "node:url";+import { readLocalLogin } from "./account.js";import { afterEach, describe, expect, it } from "vitest";import {latestLegacyBackup,@@ -131,6 +132,9 @@ describe("setAsideLegacyData", () => {expect(JSON.parse(await readFile(path.join(root, "local-account.json"), "utf8")),).toEqual({ ...account, provisioned: false });+ await expect(readLocalLogin({ root })).rejects.toThrow(+ "The local account file is invalid or the account has not been created.",+ );expect(await latestLegacyBackup(root)).toBe(backup);});