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): allow the installer runtime probe to finish
Codex3f842799ce78
diff --git a/apps/desktop/src/main/local-server.test.ts b/apps/desktop/src/main/local-server.test.tsindex 7b996c1d..308d91b1 100644--- a/apps/desktop/src/main/local-server.test.ts+++ b/apps/desktop/src/main/local-server.test.ts@@ -4164,6 +4164,97 @@ describe("legacyMigrationResult", () => {});});+it("allows a slow installer runtime lookup and keeps the login deadline", async () => {+ // Native AbortSignal.timeout uses a timer outside Vitest's fake clock.+ vi.useFakeTimers();+ const timeout = vi.spyOn(AbortSignal, "timeout").mockImplementation((ms) => {+ const controller = new AbortController();+ setTimeout(+ () => controller.abort(new DOMException("timed out", "TimeoutError")),+ ms,+ );+ return controller.signal;+ });+ try {+ const runtime = { setupChoice: "pi", environment: {} };+ const signals = new Map<string, AbortSignal>();+ let responseMs = 125_000;+ const api = await InstallerApi.open(+ "http://127.0.0.1:9/#token=abc",+ (input, options) => {+ const pathname = new URL(String(input)).pathname;+ if (pathname === "/api/session")+ return Promise.resolve(+ new Response("{}", {+ headers: {+ "set-cookie": "linger_installer_session=s1; Path=/api",+ },+ }),+ );+ const signal = options!.signal!;+ signals.set(pathname, signal);+ return new Promise((resolve, reject) => {+ const reply = setTimeout(+ () => resolve(Response.json(runtime)),+ responseMs,+ );+ signal.addEventListener(+ "abort",+ () => {+ clearTimeout(reply);+ reject(signal.reason);+ },+ { once: true },+ );+ });+ },+ 1,+ );+ const controller = new AbortController();+ const requests = Promise.allSettled([+ api.runtime(controller.signal),+ api.login(),+ ]);+ await vi.advanceTimersByTimeAsync(59_999);+ expect(signals.get(`/api/instances/${LOCAL_INSTANCE}/login`)?.aborted).toBe(+ false,+ );+ await vi.advanceTimersByTimeAsync(1);+ expect(signals.get(`/api/instances/${LOCAL_INSTANCE}/login`)?.aborted).toBe(+ true,+ );+ expect(+ signals.get(`/api/instances/${LOCAL_INSTANCE}/runtime`)?.aborted,+ ).toBe(false);+ await vi.advanceTimersByTimeAsync(65_000);+ expect(await requests).toEqual([+ { status: "fulfilled", value: runtime },+ {+ status: "rejected",+ reason: expect.objectContaining({ name: "TimeoutError" }),+ },+ ]);++ const cancelled = api+ .runtime(controller.signal)+ .catch((error: unknown) => error);+ controller.abort(new Error("Desktop stopped"));+ expect(await cancelled).toBe(controller.signal.reason);++ responseMs = 181_000;+ const overdue = api+ .runtime(new AbortController().signal)+ .catch((error: unknown) => error);+ await vi.advanceTimersByTimeAsync(180_000);+ expect(await overdue).toMatchObject({+ message: "The installer timed out while reading the selected runtime.",+ });+ } finally {+ timeout.mockRestore();+ vi.useRealTimers();+ }+});+describe("InstallerApi polling", () => {const reset = () =>new TypeError("fetch failed", {diff --git a/apps/desktop/src/main/local-server.ts b/apps/desktop/src/main/local-server.tsindex bd3b1f77..b5f5d4ba 100644--- a/apps/desktop/src/main/local-server.ts+++ b/apps/desktop/src/main/local-server.ts@@ -1095,7 +1095,9 @@ export class LocalServerModule implements Module {.prewarmAssets(job.origin);// The desktop's Computer runs the runtime this installer set up, with// its profile, rather than whatever its PATH finds.- const runtime = await installer.runtime();+ const runtime = await this.#timed("installer_runtime", () =>+ installer.runtime(signal),+ );const preferredRuntime = setupRuntime(runtime.setupChoice);this.#ctx?.config.update({runtimeEnvironment: runtime.environment,@@ -1200,7 +1202,7 @@ export class LocalServerModule implements Module {signal: AbortSignal,): Promise<LocalRuntime | { readonly byok: SetupByokConfig } | undefined> {const runtime =- setupRuntime((await installer.runtime()).setupChoice) ?? "pi";+ setupRuntime((await installer.runtime(signal)).setupChoice) ?? "pi";this.#signInInstaller = installer;this.#switchTo = undefined;this.#switchByok = undefined;@@ -2938,6 +2940,9 @@ export interface Reconnect {}const RECONNECT: Reconnect = { windowMs: 60_000, maxBackoffMs: 5_000 };+// The runtime lookup runs a 120-second harness probe, with private file and+// pinned tool checks before and after it.+const INSTALLER_RUNTIME_TIMEOUT_MS = 180_000;const TRANSIENT_CODES = new Set(["ECONNRESET",@@ -3213,8 +3218,25 @@ export class InstallerApi {// The runtime the installation set up, with the paths of its executable// and profile.- runtime(): Promise<InstanceRuntime> {- return this.#json(`/api/instances/${LOCAL_INSTANCE}/runtime`);+ async runtime(signal: AbortSignal): Promise<InstanceRuntime> {+ const deadline = AbortSignal.timeout(INSTALLER_RUNTIME_TIMEOUT_MS);+ try {+ return await this.#json(+ `/api/instances/${LOCAL_INSTANCE}/runtime`,+ undefined,+ "GET",+ AbortSignal.any([signal, deadline]),+ );+ } catch (error) {+ if (!signal.aborted && deadline.aborted)+ throw new Error(+ "The installer timed out while reading the selected runtime.",+ {+ cause: error,+ },+ );+ throw error;+ }}// The runtime's sign-in: checks it, or with `start` begins the runtime's@@ -3240,6 +3262,7 @@ export class InstallerApi {pathname: string,body?: unknown,method = body === undefined ? "GET" : "POST",+ signal = AbortSignal.timeout(60_000),): Promise<Response> {return this.#fetch(new URL(pathname, this.#origin), {method,@@ -3251,7 +3274,7 @@ export class InstallerApi {...(body === undefined ? {} : { "content-type": "application/json" }),},redirect: "error",- signal: AbortSignal.timeout(60_000),+ signal,...(body === undefined ? {} : { body: JSON.stringify(body) }),});}@@ -3260,8 +3283,9 @@ export class InstallerApi {pathname: string,body?: unknown,method?: string,+ signal?: AbortSignal,): Promise<T> {- const response = await this.#call(pathname, body, method);+ const response = await this.#call(pathname, body, method, signal);if (!response.ok) {const error = (await response.json().catch(() => null)) as {message?: string;