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(local-models): clear preselected unloads after recheck and unify guidance rules
Dongdong Chen36ff023a6af7
diff --git a/apps/web/src/features/local-models/local-model-details.tsx b/apps/web/src/features/local-models/local-model-details.tsxindex 4a9f5aeb..61f276f8 100644--- a/apps/web/src/features/local-models/local-model-details.tsx+++ b/apps/web/src/features/local-models/local-model-details.tsx@@ -24,6 +24,7 @@ import {downloadStopped,formatGigabytes,isModelOnComputer,+ memoryReclaimable,modelCapabilities,modelSourceLabel,parametersLabel,@@ -110,21 +111,7 @@ export function ModelFacts({const parameters = parametersLabel(model);const speed = speedLabel(model);const sourceUrl = safeModelSourceUrl(model.source_url);- const externalBytes = view.pools.reduce(- (sum, item) => sum + poolOtherBytes(item),- 0,- );- const maxHardware = Math.max(- view.computer.host?.ram_total_bytes ?? 0,- ...(view.computer.host?.gpus.map((gpu) => gpu.total_bytes) ?? [0]),- ...view.pools.map((item) => item.total_bytes),- 0,- );- const reclaimable =- externalBytes > 0 &&- model.availability.reason?.code === "MEMORY_INSUFFICIENT" &&- model.availability.reason.need_bytes !== undefined &&- model.availability.reason.need_bytes <= maxHardware;+ const reclaimable = memoryReclaimable(view, model);const availableNeedsRoom =status === "available" &&pool !== undefined &&diff --git a/apps/web/src/features/local-models/local-model-dialogs.tsx b/apps/web/src/features/local-models/local-model-dialogs.tsxindex 1f61f160..f8e36a51 100644--- a/apps/web/src/features/local-models/local-model-dialogs.tsx+++ b/apps/web/src/features/local-models/local-model-dialogs.tsx@@ -60,8 +60,9 @@ export function MakeRoomDialog({view: LocalModelsView;}) {const [selected, setSelected] = useState(() => makeRoomSelection(check));- const chosen = new Set(selected);const roomFreeNow = check.freeBytes >= check.needBytes;+ const effectiveSelected = roomFreeNow ? [] : selected;+ const chosen = new Set(effectiveSelected);const enough = roomFreeNow || makesRoom(check, chosen);const otherBytes = poolOtherBytes(check.pool);const unifiedFitsHardware =@@ -88,10 +89,10 @@ export function MakeRoomDialog({<Button onClick={onClose}>Cancel</Button><Buttondisabled={disabled || !enough}- onClick={() => onConfirm(selected)}+ onClick={() => onConfirm(effectiveSelected)}tone="primary">- {selected.length ? "Unload and load" : "Load"}+ {effectiveSelected.length ? "Unload and load" : "Load"}</Button></>}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 22e0c587..00e30ea9 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@@ -1849,6 +1849,100 @@ describe("Model source", () => {).toBeInTheDocument();});+ it("clears preselected agent unloads after Recheck memory shows enough room", async () => {+ const busyMac = macView({+ models: [+ macView().models[0]!,+ modelView(+ localModel({+ download_bytes: gb(20),+ fit: "unified",+ id: "gemma3-27b:Q4_K_M",+ memory_bytes: gb(30),+ name: "Gemma 3 27B",+ pool: "unified",+ state: "idle",+ }),+ ),+ ],+ pools: [+ {+ holders: [+ {+ bytes: gb(14.3),+ id: "gpt-oss-20b:Q4_K_M",+ kind: "model",+ name: "GPT-OSS 20B",+ },+ ],+ id: "unified",+ kind: "unified",+ total_bytes: gb(51.2),+ used_bytes: gb(34.3),+ },+ ],+ });+ const fixture = setup([busyMac]);+ await renderPage(fixture);+ await findModels();++ fireEvent.click(screen.getByRole("button", { name: "Load Gemma 3 27B" }));+ const dialog = screen.getByRole("dialog", { name: "Make room to load" });+ expect(+ within(dialog).getByRole("checkbox", { name: /GPT-OSS 20B/ }),+ ).toBeChecked();+ expect(dialog).toHaveTextContent(+ "Another Me can't answer until their model is loaded again.",+ );+ expect(+ within(dialog).getByRole("button", { name: "Unload and load" }),+ ).toBeEnabled();++ fireEvent.click(+ within(dialog).getByRole("button", { name: "Recheck memory" }),+ );+ await waitFor(() => expect(fixture.refreshes).toEqual(["computer-mac"]));++ // Closing the external app frees 20 GB so 36.9 GB is free without unloading GPT-OSS 20B.+ publishSnapshot(fixture, {+ ...busyMac,+ observed_at: "2026-11-13T10:07:00.000Z",+ pools: [+ {+ holders: [+ {+ bytes: gb(14.3),+ id: "gpt-oss-20b:Q4_K_M",+ kind: "model",+ name: "GPT-OSS 20B",+ },+ ],+ id: "unified",+ kind: "unified",+ total_bytes: gb(51.2),+ used_bytes: gb(14.3),+ },+ ],+ });++ await waitFor(() =>+ expect(dialog).toHaveTextContent(+ "Enough memory is free now (36.9 GB available).",+ ),+ );+ expect(dialog).not.toHaveTextContent("Another Me can't answer");+ fireEvent.click(within(dialog).getByRole("button", { name: "Load" }));+ await waitFor(() =>+ expect(fixture.actions).toEqual([+ {+ body: { action: "load" },+ computerId: "computer-mac",+ modelId: "gemma3-27b:Q4_K_M",+ },+ ]),+ );+ });+it("lets the owner choose a loaded larger model in SwitchToLocalNotice and Use for Agents", async () => {const small = localModel({id: "spark-4b:Q4_K_M",diff --git a/apps/web/src/features/local-models/local-models-page.tsx b/apps/web/src/features/local-models/local-models-page.tsxindex a1350fd8..5c95eb1f 100644--- a/apps/web/src/features/local-models/local-models-page.tsx+++ b/apps/web/src/features/local-models/local-models-page.tsx@@ -54,7 +54,6 @@ import {modelEntries,poolFreeBytes,poolOf,- poolRoomCheck,type ModelEntry,type ModelStatus,} from "./local-models-rules";@@ -557,12 +556,7 @@ function Library({: undefined;const makeRoom =dialog?.kind === "makeRoom" && dialogEntry- ? (poolRoomCheck(- view,- dialogPool,- dialogEntry.model.memory_bytes,- dialogEntry.model.id,- ) ??+ ? (loadCheck(view, dialogEntry.model) ??(dialogPool? {freeBytes: poolFreeBytes(dialogPool),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 ccf0eaab..2991c6f2 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@@ -12,6 +12,7 @@ import {makeRoomSelection,makesRoom,memoryGuidance,+ memoryReclaimable,memorySummary,modelCapabilities,modelEntries,@@ -20,7 +21,6 @@ import {placeName,poolLabel,poolOtherBytes,- poolRoomCheck,safeModelSourceUrl,speedLabel,usedByBadge,@@ -108,51 +108,114 @@ describe("local models rules", () => {used_bytes: gb(18),};expect(poolOtherBytes(busyGpu)).toBe(gb(14));- expect(poolRoomCheck(labView(), busyGpu, gb(8))?.freeBytes).toBe(gb(6));-- // A game holds 14 GB on a 24 GB card, so a 14 GB model is marked MEMORY_INSUFFICIENT.- const blockedDownload = labView({+ const eightGbAvailableView = labView({models: [modelView(localModel({- availability: {- downloadable: false,- reason: {- code: "MEMORY_INSUFFICIENT",- have_bytes: gb(6),- need_bytes: gb(14),- },- },- fit: "none",- id: "qwen3.8-27b:IQ3_S",- name: "Qwen3.8 27B",- pool: undefined,+ id: "small:Q4",+ memory_bytes: gb(5),+ name: "Small",+ pool: "gpu:0",}),),],pools: [busyGpu],});- expect(memoryGuidance(blockedDownload)).toMatchObject({- gpu: true,- kind: "blocked_download",- otherBytes: gb(14),- });+ expect(memoryGuidance(eightGbAvailableView)).toBeNull();- const blockedLoad = labView({+ const constrainedGpuView = labView({models: [modelView(localModel({- id: "gemma3-12b:Q4_K_M",- memory_bytes: gb(10),- name: "Gemma 3 12B",- note: { code: "NO_ROOM_TO_LOAD" },+ id: "medium:Q4",+ memory_bytes: gb(12),+ name: "Medium",pool: "gpu:0",- state: "idle",}),),],pools: [busyGpu],});+ expect(memoryGuidance(constrainedGpuView)).toMatchObject({+ gpu: true,+ kind: "constrained_pool",+ otherBytes: gb(14),+ });++ // A game holds 14 GB on a 24 GB card, so a 14 GB model is marked MEMORY_INSUFFICIENT.+ const blockedDownloadModel = localModel({+ availability: {+ downloadable: false,+ reason: {+ code: "MEMORY_INSUFFICIENT",+ have_bytes: gb(6),+ need_bytes: gb(14),+ },+ },+ fit: "none",+ id: "qwen3.8-27b:IQ3_S",+ name: "Qwen3.8 27B",+ pool: undefined,+ });+ const blockedDownload = labView({+ models: [modelView(blockedDownloadModel)],+ pools: [busyGpu],+ });+ expect(memoryReclaimable(blockedDownload, blockedDownloadModel)).toBe(true);+ expect(memoryGuidance(blockedDownload)).toMatchObject({+ gpu: true,+ kind: "blocked_download",+ otherBytes: gb(14),+ });++ // On an 8 GB GPU + 64 GB RAM host, a 40 GB GPU-pool miss cannot fit by closing browser GPU tabs.+ const smallGpuBusy = labView({+ computer: {+ ...labView().computer,+ host: {+ ...labView().computer.host!,+ gpus: [+ {+ free_bytes: gb(4),+ index: 0,+ name: "RTX 4060",+ total_bytes: gb(8),+ },+ ],+ ram_total_bytes: gb(64),+ },+ },+ pools: [{ ...gpuPool(0, 8), used_bytes: gb(4) }],+ });+ const fortyGbModel = localModel({+ availability: {+ downloadable: false,+ reason: {+ code: "MEMORY_INSUFFICIENT",+ have_bytes: gb(4),+ need_bytes: gb(40),+ },+ },+ fit: "none",+ id: "huge:Q4",+ name: "Huge 40B",+ pool: undefined,+ });+ expect(memoryReclaimable(smallGpuBusy, fortyGbModel)).toBe(false);++ const blockedLoadModel = localModel({+ id: "gemma3-12b:Q4_K_M",+ memory_bytes: gb(10),+ name: "Gemma 3 12B",+ note: { code: "NO_ROOM_TO_LOAD" },+ pool: "gpu:0",+ state: "idle",+ });+ const blockedLoad = labView({+ models: [modelView(blockedLoadModel)],+ pools: [busyGpu],+ });+ expect(loadCheck(blockedLoad, blockedLoadModel)?.freeBytes).toBe(gb(6));expect(memoryGuidance(blockedLoad)).toMatchObject({gpu: true,kind: "blocked_load",diff --git a/apps/web/src/features/local-models/local-models-rules.ts b/apps/web/src/features/local-models/local-models-rules.tsindex 96988d8b..8d10247b 100644--- a/apps/web/src/features/local-models/local-models-rules.ts+++ b/apps/web/src/features/local-models/local-models-rules.ts@@ -186,6 +186,27 @@ function maxHardwareCapacity(view: LocalModelsView) {);}+/**+ * Whether an unavailable model failed only because external apps currently+ * hold memory on hardware that could otherwise fit it.+ */+export function memoryReclaimable(+ view: LocalModelsView,+ model: LocalModel,+): boolean {+ const reason = model.availability.reason;+ if (+ reason?.code !== "MEMORY_INSUFFICIENT" ||+ reason.need_bytes === undefined+ ) {+ return false;+ }+ return (+ view.pools.some((pool) => poolOtherBytes(pool) > 0) &&+ reason.need_bytes <= maxHardwareCapacity(view)+ );+}+/*** Whether external apps hold enough GPU or system memory that closing them* and rechecking could let a larger model download or load.@@ -227,16 +248,10 @@ export function memoryGuidance(view: LocalModelsView): MemoryGuidance | null {};}- const hardwareMax = maxHardwareCapacity(view);- const blockedDownload = modelEntries(view).some((entry) => {- const reason = entry.model.availability.reason;- return (- entry.status === "unavailable" &&- reason?.code === "MEMORY_INSUFFICIENT" &&- reason.need_bytes !== undefined &&- reason.need_bytes <= hardwareMax- );- });+ const blockedDownload = modelEntries(view).some(+ (entry) =>+ entry.status === "unavailable" && memoryReclaimable(view, entry.model),+ );if (blockedDownload) {return {freeBytes: summary.freeBytes,@@ -257,10 +272,7 @@ export function memoryGuidance(view: LocalModelsView): MemoryGuidance | null {);});const twoGigabytes = 2 * 1024 ** 3;- if (- otherBytes >= twoGigabytes &&- (constrainedAvailable || externalPools.length > 0)- ) {+ if (otherBytes >= twoGigabytes && constrainedAvailable) {return {freeBytes: summary.freeBytes,gpu: top.pool.kind === "gpu" || summary.gpu,@@ -280,43 +292,26 @@ export interface LoadCheck {loaded: ModelEntry[];}-/**- * Why a model cannot load into `pool` now, or `null` when that pool reports- * room for `needBytes`.- */-export function poolRoomCheck(+/** Why a model cannot load now, or `null` when its pool reports room for it. */+export function loadCheck(view: LocalModelsView,- pool: LocalModelPool | undefined,- needBytes: number,- excludeModelId?: string,+ model: LocalModel,): LoadCheck | null {- if (!pool || poolFreeBytes(pool) >= needBytes) return null;+ const pool = poolOf(view, model.pool);+ if (!pool || poolFreeBytes(pool) >= model.memory_bytes) return null;return {freeBytes: poolFreeBytes(pool),loaded: modelEntries(view).filter((entry) =>entry.status === "loaded" &&entry.model.pool === pool.id &&- entry.model.id !== excludeModelId,+ entry.model.id !== model.id,),- needBytes,+ needBytes: model.memory_bytes,pool,};}-/** Why a model cannot load now, or `null` when its pool reports room for it. */-export function loadCheck(- view: LocalModelsView,- model: LocalModel,-): LoadCheck | null {- return poolRoomCheck(- view,- poolOf(view, model.pool),- model.memory_bytes,- model.id,- );-}-function freedBytes(entries: ModelEntry[]) {return entries.reduce((sum, entry) => sum + entry.model.memory_bytes, 0);}@@ -515,10 +510,6 @@ export function modelSourceLabel(url: string) {return `${parsed.host}${parsed.pathname.replace(/\/+$/, "")}`;}-/**- * The model a switch to Local model runs: a loaded one, else one on disk. None- * when the Computer has no model downloaded yet.- *//** Candidate local models on disk ordered loaded-first, recommended, then largest. */export function localSwitchTargets(view: LocalModelsView): LocalModel[] {return view.models@@ -535,6 +526,10 @@ export function localSwitchTargets(view: LocalModelsView): LocalModel[] {});}+/**+ * The model a switch to Local model runs by default: a loaded one, else one+ * on disk. None when the Computer has no model downloaded yet.+ */export function localSwitchTarget(view: LocalModelsView) {return localSwitchTargets(view)[0];}