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(web): resume a stopped model download instead of loading it
shoudi zhengc96f009e3e13
diff --git a/apps/web/src/features/local-models/local-model-details.tsx b/apps/web/src/features/local-models/local-model-details.tsxindex 99a7ca8c..951873dc 100644--- a/apps/web/src/features/local-models/local-model-details.tsx+++ b/apps/web/src/features/local-models/local-model-details.tsx@@ -20,6 +20,7 @@ import type { LocalModelPool, LocalModelsView } from "./local-models-queries";import {agentNames,contextLabel,+ downloadStopped,formatGigabytes,modelCapabilities,modelSourceLabel,@@ -77,10 +78,14 @@ export function ModelFacts({view: LocalModelsView;}) {const { model, status } = entry;- const onComputer = status !== "available" && status !== "unavailable";+ // A stopped download holds only a partial file, so it reads like a model+ // not yet on the Computer.+ const stopped = downloadStopped(model);+ const onComputer =+ status !== "available" && status !== "unavailable" && !stopped;const pool = poolOf(view, model.pool);const plannedPlace =- status === "available" ? placeName(view, model.pool) : undefined;+ status === "available" || stopped ? placeName(view, model.pool) : undefined;const capabilities = modelCapabilities(model);const parameters = parametersLabel(model);const speed = speedLabel(model);@@ -144,7 +149,7 @@ export function ModelFacts({</Fact>) : null}{model.error ? (- <Fact label="Last load">+ <Fact label={stopped ? "Last download" : "Last load"}><span className="text-app-danger">{modelErrorCopy(model.error.code)}</span>diff --git a/apps/web/src/features/local-models/local-model-row.tsx b/apps/web/src/features/local-models/local-model-row.tsxindex 467fefbe..343e8ef5 100644--- a/apps/web/src/features/local-models/local-model-row.tsx+++ b/apps/web/src/features/local-models/local-model-row.tsx@@ -28,6 +28,7 @@ import type {import {downloadPercent,downloadStatusDetail,+ downloadStopped,formatGigabytes,placeName,rowBadges,@@ -119,8 +120,11 @@ export function ModelRow({? "downloading": entry.status;const started = status !== entry.status;+ const stopped = status === "failed" && downloadStopped(model);const where = placeName(view, model.pool);- const tag = statusTags[status];+ const tag = stopped+ ? { ...statusTags.failed, label: "Download stopped" }+ : statusTags[status];const progress = downloadPercent(model);const download = formatGigabytes(model.download_bytes);const badges = rowBadges(model);@@ -147,15 +151,21 @@ export function ModelRow({{available: ["Download", handlers.onDownload, "download"],downloading: ["Cancel", handlers.onCancel, "cancel"],- failed: ["Retry", handlers.onLoad, "load"],+ failed: stopped+ ? (["Resume download", handlers.onDownload, "download"] as const)+ : (["Retry", handlers.onLoad, "load"] as const),idle: ["Load", handlers.onLoad, "load"],loaded: ["Unload", handlers.onUnload, "unload"],loading: null,unavailable: null,} as const)[status];+ // A stopped download has no record to remove; discarding it deletes the+ // kept partial instead.const removable =- status === "loaded" || status === "idle" || status === "failed";+ status === "loaded" ||+ status === "idle" ||+ (status === "failed" && !stopped);return (<article@@ -292,6 +302,18 @@ export function ModelRow({Remove from computer</Button>) : null}+ {stopped ? (+ <Button+ className="mt-2"+ disabled={disabled}+ loading={requested === "cancel"}+ onClick={handlers.onCancel}+ size="compact"+ tone="danger"+ >+ Discard download+ </Button>+ ) : null}</div>) : null}</article>diff --git a/apps/web/src/features/local-models/local-models-copy.ts b/apps/web/src/features/local-models/local-models-copy.tsindex 6080c3b7..f72d7c12 100644--- a/apps/web/src/features/local-models/local-models-copy.ts+++ b/apps/web/src/features/local-models/local-models-copy.ts@@ -66,7 +66,7 @@ const modelErrors: Record<Schemas["LocalModelErrorCode"], string> = {PLATFORM_UNSUPPORTED: "This model doesn't run on this computer.",};-/** Why the last load of a model failed. */+/** Why the last load or download of a model failed. */export function modelErrorCopy(code: Schemas["LocalModelErrorCode"]) {return modelErrors[code];}diff --git a/apps/web/src/features/local-models/local-models-page.test.tsx b/apps/web/src/features/local-models/local-models-page.test.tsxindex c34a95cc..b1b30e16 100644--- a/apps/web/src/features/local-models/local-models-page.test.tsx+++ b/apps/web/src/features/local-models/local-models-page.test.tsx@@ -418,6 +418,124 @@ describe("LocalModelsPage", () => {);});+ it.each(["DOWNLOAD_FAILED", "NETWORK_UNAVAILABLE"] as const)(+ "resumes a download that stopped with %s instead of loading it",+ async (code) => {+ const fixture = setup([+ withModel(macView(), "llama3.3-70b:Q4_K_M", {+ error: { code, detail: "retries exhausted" },+ }),+ ]);+ renderPage(fixture);+ await findModels();++ expect(statusOf("Llama 3.3 70B")).toBe("Download stopped");+ expect(+ screen.queryByRole("button", { name: "Retry Llama 3.3 70B" }),+ ).toBeNull();+ fireEvent.click(+ screen.getByRole("button", { name: "Resume download Llama 3.3 70B" }),+ );+ await waitFor(() =>+ expect(fixture.actions).toEqual([+ {+ body: { action: "download" },+ computerId: "computer-mac",+ modelId: "llama3.3-70b:Q4_K_M",+ },+ ]),+ );+ },+ );++ it("shows a resumed download as under way from the click", async () => {+ const fixture = setup([+ withModel(macView(), "llama3.3-70b:Q4_K_M", {+ error: { code: "DOWNLOAD_FAILED" },+ }),+ ]);+ const answer = holdActions(fixture, () => accepted("download"));+ renderPage(fixture);+ await findModels();++ fireEvent.click(+ screen.getByRole("button", { name: "Resume download Llama 3.3 70B" }),+ );+ await waitFor(() =>+ expect(statusOf("Llama 3.3 70B")).toMatch(/^Downloading/),+ );+ answer();+ });++ it("discards a stopped download instead of removing it", async () => {+ const fixture = setup([+ withModel(macView(), "llama3.3-70b:Q4_K_M", {+ error: { code: "DOWNLOAD_FAILED" },+ }),+ ]);+ renderPage(fixture);+ await findModels();++ fireEvent.click(screen.getByRole("button", { name: "Llama 3.3 70B" }));+ const details = screen.getByRole("region", {+ name: "Llama 3.3 70B details",+ });+ expect(details).toHaveTextContent("Last download");+ expect(+ within(details).queryByRole("button", { name: "Remove from computer" }),+ ).toBeNull();+ fireEvent.click(+ within(details).getByRole("button", { name: "Discard download" }),+ );+ await waitFor(() =>+ expect(fixture.actions).toEqual([+ {+ body: { action: "cancel" },+ computerId: "computer-mac",+ modelId: "llama3.3-70b:Q4_K_M",+ },+ ]),+ );+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();+ });++ it("retries a model that failed to load with a load and still offers Remove", async () => {+ const fixture = setup([+ withModel(macView(), "llama3.3-70b:Q4_K_M", {+ error: { code: "ENGINE_START_FAILED" },+ memory_bytes: gb(10),+ }),+ ]);+ renderPage(fixture);+ await findModels();++ expect(statusOf("Llama 3.3 70B")).toBe("Couldn't load");+ fireEvent.click(screen.getByRole("button", { name: "Llama 3.3 70B" }));+ const details = screen.getByRole("region", {+ name: "Llama 3.3 70B details",+ });+ expect(details).toHaveTextContent("Last load");+ expect(+ within(details).getByRole("button", { name: "Remove from computer" }),+ ).toBeEnabled();+ expect(+ within(details).queryByRole("button", { name: "Discard download" }),+ ).toBeNull();++ fireEvent.click(+ screen.getByRole("button", { name: "Retry Llama 3.3 70B" }),+ );+ await waitFor(() =>+ expect(fixture.actions).toEqual([+ {+ body: { action: "load" },+ computerId: "computer-mac",+ modelId: "llama3.3-70b:Q4_K_M",+ },+ ]),+ );+ });+it("loads at once when the pool has room", async () => {const fixture = setup();renderPage(fixture);diff --git a/apps/web/src/features/local-models/local-models-page.tsx b/apps/web/src/features/local-models/local-models-page.tsxindex ffeb4dc4..745e734b 100644--- a/apps/web/src/features/local-models/local-models-page.tsx+++ b/apps/web/src/features/local-models/local-models-page.tsx@@ -38,6 +38,7 @@ import {type LocalModelsView,} from "./local-models-queries";import {+ downloadStopped,formatGigabytes,loadCheck,memorySummary,@@ -52,7 +53,10 @@ type Dialog =| { kind: "remove"; modelId: string }| { kind: "unload"; modelId: string };-/** The model states each confirmed action applies to, as the row offers it. */+/**+ * The model states each confirmed action applies to, as the row offers it. A+ * stopped download is failed too but offers none of them.+ */const actionStatuses: Record<"load" | "remove" | "unload", ModelStatus[]> = {load: ["idle", "failed"],remove: ["loaded", "idle", "failed"],@@ -354,6 +358,7 @@ function Library({!offline &&!readOnly &&!requests.has(entry.model.id) &&+ !downloadStopped(entry.model) &&actionStatuses[action].includes(entry.status);const dialogEntry =dialog && dialog.kind !== "advanced" ? find(dialog.modelId) : undefined;diff --git a/apps/web/src/features/local-models/local-models-rules.test.ts b/apps/web/src/features/local-models/local-models-rules.test.tsindex 0fe272e0..f3a9b273 100644--- a/apps/web/src/features/local-models/local-models-rules.test.ts+++ b/apps/web/src/features/local-models/local-models-rules.test.ts@@ -3,6 +3,7 @@ import { describe, expect, it } from "vitest";import {downloadPercent,downloadStatusDetail,+ downloadStopped,formatGigabytes,loadCheck,makeRoomSelection,@@ -248,3 +249,35 @@ describe("local models rules", () => {expect(modelSourceLabel(safe!)).toBe("huggingface.co/Qwen/Qwen3-4B");});});++describe("downloadStopped", () => {+ const model = (fields: Parameters<typeof localModel>[0]) =>+ localModel(fields);++ it("is true only for a failed model with a download error code", () => {+ const base = { id: "m", name: "M", state: "failed" as const };+ expect(+ downloadStopped(model({ ...base, error: { code: "DOWNLOAD_FAILED" } })),+ ).toBe(true);+ expect(+ downloadStopped(+ model({ ...base, error: { code: "NETWORK_UNAVAILABLE" } }),+ ),+ ).toBe(true);+ expect(+ downloadStopped(+ model({ ...base, error: { code: "ENGINE_START_FAILED" } }),+ ),+ ).toBe(false);+ expect(downloadStopped(model(base))).toBe(false);+ expect(+ downloadStopped(+ model({+ ...base,+ error: { code: "DOWNLOAD_FAILED" },+ state: "downloading",+ }),+ ),+ ).toBe(false);+ });+});diff --git a/apps/web/src/features/local-models/local-models-rules.ts b/apps/web/src/features/local-models/local-models-rules.tsindex b560ffd2..e1cf2363 100644--- a/apps/web/src/features/local-models/local-models-rules.ts+++ b/apps/web/src/features/local-models/local-models-rules.ts@@ -39,6 +39,22 @@ export function modelStatus(model: LocalModel): ModelStatus {return model.availability.downloadable ? "available" : "unavailable";}+/**+ * Whether a failed model is a download that stopped rather than a load that+ * failed. The library reports a failed model without a record only for a+ * download job that ended and kept its partial, and gives it one of these+ * download codes; such a model resumes with download and is discarded with+ * cancel, while load and remove are refused. Decided by the structured code,+ * never by the error detail.+ */+export function downloadStopped(model: LocalModel): boolean {+ return (+ model.state === "failed" &&+ (model.error?.code === "DOWNLOAD_FAILED" ||+ model.error?.code === "NETWORK_UNAVAILABLE")+ );+}+const fitOrder: Record<LocalModel["fit"], number> = {gpu: 0,none: 2,