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): show a Local models action as under way from the click
Dongdong Chend3438abc47f0
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.mdindex 672a9c2f..29124f5b 100644--- a/apps/web/AGENTS.md+++ b/apps/web/AGENTS.md@@ -28,7 +28,10 @@ build:assets` to check the initial JS budget.code and enum label to English in `local-models-copy.ts`. Without `?computer=`the desktop app opensits own Computer. Only the Computer's owner can act; actions return at once- and progress arrives as `local-models` invalidation hints. A Computer's+ and progress arrives as `local-models` invalidation hints. From the click+ until a snapshot with another status or observation time, or a refusal, the+ row shows a requested load or download as started and spins the button of+ any other action, with the row's actions off. A Computer'sdetail on the Computers page links here and reads no model state itself.- `src/test`: unit-test support, including the in-process TeamHub test server.- `e2e`: Playwright product workflows; every spec runs on the real TeamHub anddiff --git a/apps/web/src/features/local-models/local-model-row.tsx b/apps/web/src/features/local-models/local-model-row.tsxindex fe108714..467fefbe 100644--- a/apps/web/src/features/local-models/local-model-row.tsx+++ b/apps/web/src/features/local-models/local-model-row.tsx@@ -20,7 +20,11 @@ import { cn } from "@/lib/cn";import { ModelFacts } from "./local-model-details";import { unavailableShortCopy } from "./local-models-copy";-import type { LocalModel, LocalModelsView } from "./local-models-queries";+import type {+ LocalModel,+ LocalModelAction,+ LocalModelsView,+} from "./local-models-queries";import {downloadPercent,downloadStatusDetail,@@ -92,6 +96,7 @@ export function ModelRow({disabled,entry,expanded,+ requested,view,...handlers}: Handlers & {@@ -99,10 +104,21 @@ export function ModelRow({disabled: boolean;entry: ModelEntry;expanded: boolean;+ /** An action asked for and not yet in a snapshot. */+ requested?: LocalModelAction;view: LocalModelsView;}) {const panelId = useId();- const { model, status } = entry;+ const { model } = entry;+ // A requested load or download reads as started at once; the snapshot that+ // follows says how it went.+ const status: ModelStatus =+ requested === "load"+ ? "loading"+ : requested === "download"+ ? "downloading"+ : entry.status;+ const started = status !== entry.status;const where = placeName(view, model.pool);const tag = statusTags[status];const progress = downloadPercent(model);@@ -114,7 +130,7 @@ export function ModelRow({: model.fit === "system"? `${download} · runs slower`: download,- downloading: downloadStatusDetail(model),+ downloading: started ? null : downloadStatusDetail(model),failed: null,idle: model.note ? "no room to load yet" : null,loaded: [@@ -129,11 +145,11 @@ export function ModelRow({const action = ({- available: ["Download", handlers.onDownload],- downloading: ["Cancel", handlers.onCancel],- failed: ["Retry", handlers.onLoad],- idle: ["Load", handlers.onLoad],- loaded: ["Unload", handlers.onUnload],+ available: ["Download", handlers.onDownload, "download"],+ downloading: ["Cancel", handlers.onCancel, "cancel"],+ failed: ["Retry", handlers.onLoad, "load"],+ idle: ["Load", handlers.onLoad, "load"],+ loaded: ["Unload", handlers.onUnload, "unload"],loading: null,unavailable: null,} as const@@ -205,6 +221,7 @@ export function ModelRow({aria-label={`${action[0]} ${model.name}`}className="px-2.5"disabled={disabled}+ loading={requested === action[2]}onClick={(event) => {stopRowClick(event);action[1]();@@ -233,7 +250,7 @@ export function ModelRow({/></Button></div>- {status === "downloading" ? (+ {entry.status === "downloading" ? (<div className="px-4 pb-3"><spanaria-label={`${model.name} download progress`}@@ -267,6 +284,7 @@ export function ModelRow({<ButtonclassName="mt-2"disabled={disabled}+ loading={requested === "remove"}onClick={handlers.onRemove}size="compact"tone="danger"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 63ff9c21..b0799be7 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@@ -166,6 +166,36 @@ function publishSnapshot(fixture: Fixture, view: LocalModelsView) {});}+/** One card's status line, without its model name. */+function statusOf(name: string) {+ return statuses()+ .find((line) => line.startsWith(`${name}: `))!+ .slice(name.length + 2);+}++/**+ * Holds every action request until the returned function answers it with+ * respond(), as a Computer that takes a while to decide.+ */+function holdActions(fixture: Fixture, respond: () => Response) {+ const held: (() => void)[] = [];+ fixture.runtime.server.on(+ "POST",+ actionPath,+ () => new Promise((resolve) => held.push(() => resolve(respond()))),+ );+ return () => {+ for (const release of held.splice(0)) release();+ };+}++function accepted(action: string) {+ return Response.json(+ { action, computer_id: "computer-lab", model_id: "held" },+ { status: 202 },+ );+}+function withModel(view: LocalModelsView,modelId: string,@@ -457,6 +487,7 @@ describe("LocalModelsPage", () => {publishSnapshot(fixture, {...labView(),models: labView().models.map((item) => ({ ...item, used_by: [] })),+ observed_at: "2026-11-13T10:00:05.000Z",});fireEvent.click(screen.getByRole("button", { name: "Qwen3 Coder 30B" }));await waitFor(() =>@@ -621,6 +652,92 @@ describe("LocalModelsPage", () => {);});+ it("shows a load as under way from the click until a snapshot reflects it", async () => {+ const fixture = setup();+ const answer = holdActions(fixture, () => accepted("load"));+ let reads = 0;+ fixture.runtime.server.on("GET", viewPath, ({ params }) => {+ reads += 1;+ return fixture.views[params.computerId!];+ });+ renderPage(fixture);+ await findModels();++ fireEvent.click(screen.getByRole("button", { name: "Load Gemma 3 27B" }));+ await waitFor(() => expect(statusOf("Gemma 3 27B")).toMatch(/^Loading/));+ const row = card("Gemma 3 27B");+ expect(+ within(row).queryByRole("button", { name: "Load Gemma 3 27B" }),+ ).toBeNull();+ expect(row.querySelector(".town-shimmer-text")).not.toBeNull();++ // Accepted, and the fresh read still carries the snapshot from before.+ const readsBefore = reads;+ answer();+ await waitFor(() => expect(reads).toBeGreaterThan(readsBefore));+ expect(statusOf("Gemma 3 27B")).toMatch(/^Loading/);++ publishSnapshot(+ fixture,+ withModel(labView(), "gemma3-27b:Q4_K_M", { state: "loaded" }),+ );+ await waitFor(() => expect(statusOf("Gemma 3 27B")).toMatch(/^Loaded/));+ });++ it("spins and disables the row's button while an unload is sent", async () => {+ const fixture = setup();+ const answer = holdActions(fixture, () => accepted("unload"));+ renderPage(fixture);+ await findModels();++ fireEvent.click(+ screen.getByRole("button", { name: "Unload Qwen3 Coder 30B" }),+ );+ fireEvent.click(+ within(+ screen.getByRole("dialog", { name: "Unload Qwen3 Coder 30B?" }),+ ).getByRole("button", { name: "Unload" }),+ );+ const unload = await screen.findByRole("button", {+ name: "Unload Qwen3 Coder 30B",+ });+ await waitFor(() => expect(unload).toHaveAttribute("aria-busy", "true"));+ expect(unload).toBeDisabled();++ answer();+ publishSnapshot(+ fixture,+ withModel(labView(), "qwen3-coder-30b:Q4_K_M", { state: "idle" }),+ );+ await waitFor(() =>+ expect(statusOf("Qwen3 Coder 30B")).toMatch(/^Downloaded/),+ );+ expect(+ screen.getByRole("button", { name: "Load Qwen3 Coder 30B" }),+ ).toBeEnabled();+ });++ it("puts the row back and explains when the Computer refuses", async () => {+ const fixture = setup();+ const answer = holdActions(fixture, () =>+ teamHubErrorResponse(409, "LOCAL_MODEL_NO_ROOM", "raw refusal detail"),+ );+ renderPage(fixture);+ await findModels();++ fireEvent.click(screen.getByRole("button", { name: "Load Gemma 3 27B" }));+ await waitFor(() => expect(statusOf("Gemma 3 27B")).toMatch(/^Loading/));++ answer();+ expect(await screen.findByRole("alert")).toHaveTextContent(+ "Gemma 3 27B: There isn't enough free memory to load it. Unload another model first.",+ );+ expect(statusOf("Gemma 3 27B")).toMatch(/^Downloaded/);+ expect(+ screen.getByRole("button", { name: "Load Gemma 3 27B" }),+ ).toBeEnabled();+ });+it("shows a refusal from the Computer as copy for its code", async () => {const fixture = setup();fixture.runtime.server.on("POST", actionPath, () =>diff --git a/apps/web/src/features/local-models/local-models-page.tsx b/apps/web/src/features/local-models/local-models-page.tsxindex 84b37576..ffeb4dc4 100644--- a/apps/web/src/features/local-models/local-models-page.tsx+++ b/apps/web/src/features/local-models/local-models-page.tsx@@ -33,6 +33,7 @@ import {localModelActionMutationKey,localModelsQueryKey,localModelsQueryOptions,+ type LocalModelAction,type LocalModelActionInput,type LocalModelsView,} from "./local-models-queries";@@ -281,6 +282,17 @@ function Library({code?: string;modelId: string;} | null>(null);+ // An action the Computer accepted, shown on its row until a snapshot moves+ // the model on: a different status or a newer snapshot.+ const [accepted, setAccepted] = useState<+ Record<+ string,+ { action: LocalModelAction; from?: ModelStatus; observedAt?: string }+ >+ >({});+ const entries = view.available ? modelEntries(view) : [];+ const find = (modelId: string) =>+ entries.find((entry) => entry.model.id === modelId);const mutationKey = localModelActionMutationKey(tenantId, computerId);const action = useMutation({mutationFn: (input: LocalModelActionInput) =>@@ -291,7 +303,21 @@ function Library({code: error instanceof TeamHubError ? error.code : undefined,modelId: input.modelId,}),- onMutate: () => setFailure(null),+ onMutate: (input) => {+ setFailure(null);+ return { from: find(input.modelId)?.status };+ },+ onSuccess: (_result, input, started) =>+ setAccepted((current) => ({+ ...current,+ [input.modelId]: {+ action: input.action,+ from: started?.from,+ observedAt: queryClient.getQueryData<LocalModelsView>(+ localModelsQueryKey(tenantId, computerId),+ )?.observed_at,+ },+ })),// The Computer answers at once; a fresh read shows what it started even// before its next snapshot hint.onSettled: () =>@@ -299,14 +325,24 @@ function Library({queryKey: localModelsQueryKey(tenantId, computerId),}),});- const pendingIds = new Set(- useMutationState({- filters: { mutationKey, status: "pending" },- select: (mutation) =>- (mutation.state.variables as LocalModelActionInput | undefined)- ?.modelId,- }),- );+ const sending = useMutationState({+ filters: { mutationKey, status: "pending" },+ select: (mutation) =>+ mutation.state.variables as LocalModelActionInput | undefined,+ });+ // The action each row shows as under way: one being sent, or one accepted+ // that no snapshot reflects yet.+ const requests = new Map<string, LocalModelAction>();+ for (const [modelId, request] of Object.entries(accepted)) {+ if (+ request.observedAt === view.observed_at &&+ request.from === find(modelId)?.status+ )+ requests.set(modelId, request.action);+ }+ for (const input of sending) {+ if (input) requests.set(input.modelId, input.action);+ }const offline = view.computer.status === "offline";const readOnly = !view.viewer_is_owner;// A dialog stays open across snapshots, so its confirm checks the model@@ -317,11 +353,8 @@ function Library({) =>!offline &&!readOnly &&- !pendingIds.has(entry.model.id) &&+ !requests.has(entry.model.id) &&actionStatuses[action].includes(entry.status);- const entries = view.available ? modelEntries(view) : [];- const find = (modelId: string) =>- entries.find((entry) => entry.model.id === modelId);const dialogEntry =dialog && dialog.kind !== "advanced" ? find(dialog.modelId) : undefined;const makeRoom =@@ -402,7 +435,7 @@ function Library({const modelId = entry.model.id;return (<ModelRow- disabled={offline || readOnly || pendingIds.has(modelId)}+ disabled={offline || readOnly || requests.has(modelId)}entry={entry}expanded={expandedId === modelId}key={modelId}@@ -416,6 +449,7 @@ function Library({)}onUnload={() => unload(entry)}+ requested={requests.get(modelId)}view={view}/>);