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(installer): verify saved local accounts before readiness

Kilync2dfac6b0f03
diff --git a/packages/local-installation/AGENTS.md b/packages/local-installation/AGENTS.md
index fc628bc0..fe3b8b8e 100644
--- a/packages/local-installation/AGENTS.md
+++ b/packages/local-installation/AGENTS.md
@@ -11,6 +11,13 @@ stop unrelated processes, pull mutable images, or delete volumes as recovery.
Every installation runs natively from a Linger source checkout; Docker is not
used.
+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.
+
Each instance directory holds `user.env` (0600), the only file a person edits:
`COMPOSIO_API_KEY`, `SONIOX_API_KEY`, `XAI_API_KEY` and `TZ`
(`user-environment.ts`). Every mode merges it into the generated
diff --git a/packages/local-installation/src/account.test.ts b/packages/local-installation/src/account.test.ts
index 36fea7a1..a1a39e6b 100644
--- a/packages/local-installation/src/account.test.ts
+++ b/packages/local-installation/src/account.test.ts
@@ -69,7 +69,13 @@ it("creates the owner through stdin, confirms login and logs out before reusing
vi.mocked(fetch).mockClear();
provisionOwner.mockClear();
await ensureLocalAccount(f.instance, f.signal, owner);
- expect(fetch).not.toHaveBeenCalled();
+ expect(
+ vi
+ .mocked(fetch)
+ .mock.calls.map(
+ ([url]) => new URL(url instanceof Request ? url.url : url).pathname,
+ ),
+ ).toEqual(["/v0/auth/login", "/v0/auth/logout"]);
expect(provisionOwner).not.toHaveBeenCalled();
expect(
JSON.parse(await readFile(f.file, "utf8")).password === saved.password,
@@ -286,3 +292,104 @@ it("reads the server identity from the private instance files", async () => {
await chmod(keyFile, 0o644);
await expect(readLocalIdentity(f.instance)).rejects.toThrow(/private/);
});
+
+it("recreates a missing owner when the private file is already marked provisioned", async () => {
+ const f = await fixture();
+ const saved =
+ JSON.stringify(
+ {
+ email: "[email protected]",
+ password: "saved-private-password",
+ provisioned: true,
+ },
+ null,
+ 2,
+ ) + "\n";
+ await writeFile(f.file, saved, { mode: 0o600 });
+ let created = false;
+ vi.stubGlobal(
+ "fetch",
+ vi.fn(
+ async (url: string) =>
+ new Response(null, {
+ status: url.endsWith("/logout") ? 204 : created ? 200 : 401,
+ headers: created ? { "set-cookie": "session=test; HttpOnly" } : {},
+ }),
+ ),
+ );
+ provisionOwner.mockImplementation(async (email, password) => {
+ expect(email).toBe("[email protected]");
+ expect(password).toBe("saved-private-password");
+ created = true;
+ });
+ const result = await ensureLocalAccount(f.instance, f.signal, owner);
+ expect(created).toBe(true);
+ expect(provisionOwner).toHaveBeenCalledOnce();
+ expect(result.email).toBe("[email protected]");
+ expect(await readFile(f.file, "utf8")).toBe(saved);
+ expect(
+ vi
+ .mocked(fetch)
+ .mock.calls.map(
+ ([url]) => new URL(url instanceof Request ? url.url : url).pathname,
+ ),
+ ).toEqual(["/v0/auth/login", "/v0/auth/login", "/v0/auth/logout"]);
+});
+it("rejects a provisioned account with a stale password without replacing credentials", 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.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.",
+ );
+ expect(provisionOwner).toHaveBeenCalledOnce();
+ expect(fetch).toHaveBeenCalledTimes(2);
+ expect(await readFile(f.file, "utf8")).toBe(saved);
+});
+it("does not provision an already marked account when its login service fails", 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: 503 })),
+ );
+ await expect(ensureLocalAccount(f.instance, f.signal, owner)).rejects.toThrow(
+ "Local account login check failed (HTTP 503)",
+ );
+ expect(provisionOwner).not.toHaveBeenCalled();
+ expect(await readFile(f.file, "utf8")).toBe(saved);
+});
+it("preserves a provisioned account and hides details on a network failure", 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 () => {
+ throw new Error("server-private-secret");
+ }),
+ );
+ await expect(ensureLocalAccount(f.instance, f.signal, owner)).rejects.toThrow(
+ "The local account service is unavailable. Reopen Linger to retry; account credentials are preserved.",
+ );
+ expect(provisionOwner).not.toHaveBeenCalled();
+ expect(await readFile(f.file, "utf8")).toBe(saved);
+});
diff --git a/packages/local-installation/src/account.ts b/packages/local-installation/src/account.ts
index d81f901a..b8b1e93e 100644
--- a/packages/local-installation/src/account.ts
+++ b/packages/local-installation/src/account.ts
@@ -172,7 +172,6 @@ export async function ensureLocalAccount(
}
const email = account.email;
signal.throwIfAborted();
- if (account.provisioned) return { email, file, password: account.password };
async function post(route: string, body: unknown, cookie?: string) {
let response: Response;
try {
diff --git a/packages/local-installation/src/windows-state-security.test.ts b/packages/local-installation/src/windows-state-security.test.ts
index 330dc9f3..6797c32b 100644
--- a/packages/local-installation/src/windows-state-security.test.ts
+++ b/packages/local-installation/src/windows-state-security.test.ts
@@ -51,15 +51,22 @@ it("uses Windows SID/DACL validation for existing local account reads and reuse"
}),
{ mode: 0o644 },
);
+ vi.stubGlobal(
+ "fetch",
+ vi.fn(async () => new Response(null, { status: 200 })),
+ );
+ const provisionOwner = vi.fn<() => Promise<void>>();
expect((await readLocalLogin(instance)).email).toBe("[email protected]");
expect(
(
await ensureLocalAccount(instance, new AbortController().signal, {
- provisionOwner: async () => {},
+ provisionOwner,
})
).email,
).toBe("[email protected]");
expect(windowsPrivatePath).toHaveBeenCalledWith(file, "file");
+ expect(fetch).toHaveBeenCalledOnce();
+ expect(provisionOwner).not.toHaveBeenCalled();
});
it("checks the ACL before reusing a saved enrollment token", async () => {
const instance = await fixture();