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): replace a job waiting for the person on a new start
chendongdong144c7f94cd03
diff --git a/apps/linger-installer/AGENTS.md b/apps/linger-installer/AGENTS.mdindex a1a1900a..6448a220 100644--- a/apps/linger-installer/AGENTS.md+++ b/apps/linger-installer/AGENTS.md@@ -10,6 +10,9 @@ Only the authorized no-store login endpoint and explicit credentials view mayshow the user's password; redact events, diagnostics and persisted job snapshots.Browser closure never cancels installation. Repeated launches reuse the manager,instance mutations remain locked, and cancellation retains account/data/device.+A start returns the instance's running or queued job; a job that finished its+run and waits for the person (`waiting_user`, e.g. `LOCAL_MODELS_UNAVAILABLE`)+is canceled and replaced, so Try Again checks the computer again.An idle desktop-owned manager steps aside when the desktop relaunches the sameinstance with another checkout. Every installation runs natively from thesource checkout `--source-repo` names. Start failures print their real causediff --git a/apps/linger-installer/src/server/jobs.test.ts b/apps/linger-installer/src/server/jobs.test.tsindex cffb73e4..4ce9094f 100644--- a/apps/linger-installer/src/server/jobs.test.ts+++ b/apps/linger-installer/src/server/jobs.test.ts@@ -168,6 +168,63 @@ test("waiting-user jobs retry by rechecking and can be canceled after their operexpect((await jobs.cancel(retried!.id))?.state).toBe("canceled");});+test("a new start replaces a job waiting for the person and checks again", async () => {+ let runs = 0;+ const { jobs, dir } = await setup(async () => {+ runs++;+ return runs === 1+ ? {+ state: "action_required",+ code: 4,+ message: "No local model fits now",+ details: { code: "LOCAL_MODELS_UNAVAILABLE" },+ }+ : { state: "ready", code: 0, message: "Complete" };+ });+ const first = await jobs.start({ instance: "default" });+ await jobs.wait(first.id);+ expect(jobs.get(first.id)?.state).toBe("waiting_user");+ // Also after a restart, which keeps a local-model wait as it was.+ const restarted = new JobManager(dir, async () => {+ runs++;+ return { state: "ready", code: 0, message: "Complete" };+ });+ await restarted.load();+ expect(restarted.get(first.id)?.state).toBe("waiting_user");+ const second = await restarted.start({ instance: "default" });+ expect(second.id).not.toBe(first.id);+ await restarted.wait(second.id);+ expect(restarted.get(first.id)?.state).toBe("canceled");+ expect(restarted.get(second.id)?.state).toBe("succeeded");+ expect(runs).toBe(2);+});++test("concurrent starts replace a waiting job with one new job", async () => {+ let runs = 0;+ const { jobs } = await setup(async () => {+ runs++;+ return runs === 1+ ? {+ state: "action_required",+ code: 4,+ message: "No local model fits now",+ details: { code: "LOCAL_MODELS_UNAVAILABLE" },+ }+ : { state: "ready", code: 0, message: "Complete" };+ });+ const first = await jobs.start({ instance: "default" });+ await jobs.wait(first.id);+ const [a, b] = await Promise.all([+ jobs.start({ instance: "default" }),+ jobs.start({ instance: "default" }),+ ]);+ expect(a.id).not.toBe(first.id);+ expect(b.id).toBe(a.id);+ await jobs.wait(a.id);+ expect(runs).toBe(2);+ expect(jobs.get(a.id)?.state).toBe("succeeded");+});+test("shutdown cancels owned work and flushes final state before releasing ownership", async () => {const { jobs, dir } = await setup(async (_input, signal) => {await new Promise<void>((_resolve, reject) =>diff --git a/apps/linger-installer/src/server/jobs.ts b/apps/linger-installer/src/server/jobs.tsindex f803bfc0..0d9ccad6 100644--- a/apps/linger-installer/src/server/jobs.ts+++ b/apps/linger-installer/src/server/jobs.ts@@ -277,7 +277,16 @@ export class JobManager {record.job.preparation === input.preparation &&active(record.job),);- if (existing) return structuredClone(existing.job);+ // A job that ran to the end and now waits for the person mutates+ // nothing; a new start is their answer, so it replaces that job and+ // checks the computer again instead of returning the stale outcome.+ // cancel() marks it canceled before its first await and the new record+ // is set in the same step, so a concurrent start gets the new job back.+ const replaced =+ existing?.job.state === "waiting_user" && !existing.executing+ ? this.cancel(existing.job.id)+ : undefined;+ if (existing && !replaced) return structuredClone(existing.job);const id = randomUUID(),// Preserve successor order even when jobs are created within one clock tick.at = new Date(@@ -328,6 +337,7 @@ export class JobManager {};this.records.set(id, record);try {+ await replaced;await privateWrite(path.join(this.directory, `${id}.input.json`), input);await this.persist(id);} catch (error) {