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): handle native login input failures
Afloatb9fc31ebc8d1
diff --git a/apps/linger-installer/AGENTS.md b/apps/linger-installer/AGENTS.mdindex 215f8bec..b092ea92 100644--- a/apps/linger-installer/AGENTS.md+++ b/apps/linger-installer/AGENTS.md@@ -18,6 +18,8 @@ it prevents execution after those writes, and shutdown drains that initial savebefore returning, just as it waits for an executing job. An initial input-savefailure is reported by start without interrupting shutdown's remaining cleanup;storage failures for retained jobs still propagate.+A closed native sign-in input reports failure without stopping the installer;+retry starts a new owned login process.A start returns the instance's running or queued job; a job that finished itsrun and waits for the person (`waiting_user`, e.g. `LOCAL_MODELS_UNAVAILABLE`)is canceled and replaced, so Try Again checks the computer again.diff --git a/apps/linger-installer/src/server/runtime-login-stdin.test.ts b/apps/linger-installer/src/server/runtime-login-stdin.test.tsnew file mode 100644index 00000000..b70019cd--- /dev/null+++ b/apps/linger-installer/src/server/runtime-login-stdin.test.ts@@ -0,0 +1,90 @@+import { expect, it } from "vitest";+import { mkdtemp, writeFile, rm } from "node:fs/promises";+import { tmpdir } from "node:os";+import path from "node:path";+import { execFile } from "node:child_process";+import { createRequire } from "node:module";+import { promisify } from "node:util";++const execute = promisify(execFile);++it(+ "a closed native login stdin reports failure without crashing the manager and permits retry",+ { timeout: 15000 },+ async () => {+ const home = await mkdtemp(path.join(tmpdir(), "runtime-stdin-"));+ try {+ const native = path.join(home, "native.cjs");+ const codes = path.join(home, "codes.txt");+ const repeat = path.join(home, "repeat-url");+ const repeated = path.join(home, "repeated-url");+ await writeFile(+ native,+ `+const fs = require('node:fs');+if (process.argv[2] === 'closed') fs.closeSync(0);+else process.stdin.on('data', (chunk) => fs.appendFileSync(${JSON.stringify(codes)}, chunk));+console.log('https://claude.com/cai/oauth/authorize?state=fixture');+if (process.argv[2] === 'closed') {+ const timer = setInterval(() => {+ if (!fs.existsSync(${JSON.stringify(repeat)})) return;+ clearInterval(timer);+ process.stdout.write('https://claude.com/cai/oauth/authorize?state=after-error\\n', () => fs.writeFileSync(${JSON.stringify(repeated)}, 'done'));+ }, 10);+}+setTimeout(() => process.exit(0), 5000);+`,+ );+ const program = path.join(home, "manager.mts");+ await writeFile(+ program,+ `+import assert from 'node:assert/strict';+import { readFile, writeFile } from 'node:fs/promises';+import { setTimeout as delay } from 'node:timers/promises';+import { RuntimeLoginManager } from ${JSON.stringify(new URL("./runtime-login.ts", import.meta.url).href)};+let mode = 'closed';+const manager = new RuntimeLoginManager(async () => ({+ runtime: 'claude', executable: process.execPath, installed: true, ready: false, loginCommand: 'unused',+ descriptor: {+ runtime: 'claude', executable: process.execPath, argvPrefix: [], installed: true, authenticated: false, authMode: null,+ loginCommand: { executable: process.execPath, args: [${JSON.stringify(native)}, mode], env: {} },+ },+}), 'linux');+const input = { instance: 'default', home: ${JSON.stringify(home)}, root: ${JSON.stringify(home)}, runtime: 'claude' };+async function waitFor(check) {+ for (let n = 0; n < 200; n++) { if (await check()) return; await delay(10); }+ throw new Error('fixture did not become ready');+}+try {+ await manager.start(input);+ await waitFor(async () => (await manager.status(input)).acceptsCode);+ let failure;+ try { await manager.start(input, 'fixture-code'); } catch (error) { failure = error; }+ assert.match(failure?.message ?? '', /Native sign-in could not accept the authorization code/);+ await waitFor(async () => (await manager.status(input)).state === 'failed');+ await writeFile(${JSON.stringify(repeat)}, 'repeat');+ await waitFor(async () => (await readFile(${JSON.stringify(repeated)}, 'utf8').catch(() => '')) === 'done');+ await delay(0);+ assert.equal((await manager.status(input)).state, 'failed', 'later output must not revive a login whose stdin failed');+ mode = 'open';+ await manager.start(input);+ await waitFor(async () => (await manager.status(input)).acceptsCode);+ await manager.start(input, 'retry-code');+ await waitFor(async () => (await readFile(${JSON.stringify(codes)}, 'utf8').catch(() => '')) === 'retry-code\\n');+ console.log('manager survived and retried');+} finally { manager.close(); }+`,+ );+ const result = await execute(+ process.execPath,+ ["--import", createRequire(import.meta.url).resolve("tsx"), program],+ { timeout: 12000, windowsHide: true },+ );+ expect(result.stdout.trim()).toBe("manager survived and retried");+ expect(result.stderr).toBe("");+ } finally {+ await rm(home, { recursive: true, force: true });+ }+ },+);diff --git a/apps/linger-installer/src/server/runtime-login.ts b/apps/linger-installer/src/server/runtime-login.tsindex b2aea3f0..98a17577 100644--- a/apps/linger-installer/src/server/runtime-login.ts+++ b/apps/linger-installer/src/server/runtime-login.ts@@ -79,14 +79,25 @@ export class RuntimeLoginManager {async start(input: Input, code?: string): Promise<Snapshot> {if (code !== undefined) {const session = this.sessions.get(input.instance);+ const stdin = session?.child.stdin;if (session?.runtime !== input.runtime ||!session.snapshot.acceptsCode ||- !session.child.stdin?.writable ||+ !stdin?.writable ||!/^[A-Za-z0-9._~+/#=-]{1,4096}$/.test(code))throw new Error("Invalid authorization code or inactive login");- session.child.stdin.write(code + "\n");+ await new Promise<void>((resolve, reject) => {+ stdin.write(code + "\n", (error) => {+ if (error)+ reject(+ new Error(+ "Native sign-in could not accept the authorization code. Retry or sign in later.",+ ),+ );+ else resolve();+ });+ });return structuredClone(session.snapshot);}if (this.closed) return { state: "idle" };@@ -158,6 +169,7 @@ export class RuntimeLoginManager {this.sessions.set(input.instance, session);let output = "";const receive = (chunk: Buffer) => {+ if (session.snapshot.state === "failed") return;output = stripVTControlCharacters(output + chunk.toString()).slice(-16384,);@@ -201,6 +213,7 @@ export class RuntimeLoginManager {};};child.once("error", failed);+ child.stdin?.on("error", failed);child.once("close", () => {clearTimeout(session.timer);output = "";