Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review: stop dropping measured resident size, and never overwrite an unreadable store (#4539)

[._.]/ Adam Eivy51a4358fe48a
diff --git a/client/src/components/settings/LocalModelAssessments.test.jsx b/client/src/components/settings/LocalModelAssessments.test.jsx
index 9def1063ef..ee594f2dc6 100644
--- a/client/src/components/settings/LocalModelAssessments.test.jsx
+++ b/client/src/components/settings/LocalModelAssessments.test.jsx
@@ -43,6 +43,8 @@ const rankedEntry = (overrides = {}) => ({
samplesRun: 3,
samplesOk: 3,
},
+ residentGb: 5,
+ params: '7B',
assessedAt: '2026-01-01T00:00:00.000Z',
explanation: '120 chars/s measured, ran at up to 4,096 tokens of context.',
...overrides,
@@ -68,6 +70,9 @@ describe('LocalModelAssessments', () => {
expect(await screen.findByText('example-model:7b')).toBeInTheDocument();
expect(screen.getByText('120 chars/s')).toBeInTheDocument();
expect(screen.getByText('4k tokens')).toBeInTheDocument();
+ // Resident size is measured by /api/ps and must survive into the ranked
+ // entry — rendering "not measured" here would hide a real measurement.
+ expect(screen.getByText('5.0 GB')).toBeInTheDocument();
expect(screen.getByText('Fits')).toBeInTheDocument();
});
diff --git a/server/lib/localModelAssessment.js b/server/lib/localModelAssessment.js
index f34d25368a..902de05557 100644
--- a/server/lib/localModelAssessment.js
+++ b/server/lib/localModelAssessment.js
@@ -332,6 +332,11 @@ export function rankByIntent(assessments, intent = 'balanced') {
coverage,
scores,
performance: assessment?.performance || null,
+ // The measured footprint feeds the memory axis, so it has to travel WITH
+ // the ranked entry — a consumer that renders it from the entry alone would
+ // otherwise show "not measured" for every model /api/ps actually measured.
+ residentGb: Number.isFinite(assessment?.residentGb) ? assessment.residentGb : null,
+ params: assessment?.params ?? null,
assessedAt: assessment?.assessedAt || null,
explanation: explainAssessment(assessment, resolvedIntent),
});
diff --git a/server/lib/localModelAssessment.test.js b/server/lib/localModelAssessment.test.js
index cf80dcea47..52b3e1584f 100644
--- a/server/lib/localModelAssessment.test.js
+++ b/server/lib/localModelAssessment.test.js
@@ -279,6 +279,20 @@ describe('rankByIntent', () => {
expect(ranked[0].coverage).toBeGreaterThan(ranked[1].coverage);
});
+ it('carries the measured resident size into the ranked entry', () => {
+ // The memory axis is scored FROM residentGb, so dropping it from the entry
+ // makes a consumer render "not measured" for a value that was measured.
+ const models = [assessment('example-model:7b', 'fits', { meanCharsPerSecond: 120, contextDegradation: 1 }, { residentGb: 5, params: '7B' })];
+ const { ranked } = rankByIntent(models, 'balanced');
+ expect(ranked[0].residentGb).toBe(5);
+ expect(ranked[0].params).toBe('7B');
+ });
+
+ it('keeps residentGb null when it was never measured', () => {
+ const models = [assessment('example-model:7b', 'fits', { meanCharsPerSecond: 120, contextDegradation: 1 })];
+ expect(rankByIntent(models, 'balanced').ranked[0].residentGb).toBeNull();
+ });
+
it('is empty and safe on no input', () => {
expect(rankByIntent(undefined, 'balanced')).toEqual({ intent: 'balanced', ranked: [], excluded: [] });
});
diff --git a/server/services/localModelAssessments.js b/server/services/localModelAssessments.js
index bb2f6602ec..f673dac369 100644
--- a/server/services/localModelAssessments.js
+++ b/server/services/localModelAssessments.js
@@ -47,6 +47,7 @@
*/
import { join } from 'path';
+import { rename } from 'fs/promises';
import os from 'os';
import { PATHS, atomicWrite, ensureDir, tryReadFile, safeJSONParse } from '../lib/fileUtils.js';
import { getAvailableMemoryGb } from '../lib/localMemory.js';
@@ -159,6 +160,16 @@ export async function loadAssessments() {
return (await loadStore()).assessments;
}
+// Move an unparseable store aside so a fresh one can be written without losing
+// whatever the old file held. Best-effort: if the rename fails there is nothing
+// further to preserve, and refusing the write outright would leave assessments
+// permanently unusable.
+async function quarantineStore(reason) {
+ const parked = `${ASSESSMENTS_FILE}.corrupt-${Date.now()}`;
+ const moved = await rename(ASSESSMENTS_FILE, parked).then(() => true).catch(() => false);
+ console.error(`❌ Local LLM: ${reason} — ${moved ? `parked the old file as ${parked.split('/').pop()}` : 'could not park the old file'}`);
+}
+
async function loadStore() {
const raw = await tryReadFile(ASSESSMENTS_FILE);
// Never read = an empty store, not an error: the file simply doesn't exist
@@ -176,7 +187,13 @@ async function loadStore() {
const assessmentKey = (backend, modelId) => `${backend}:${modelId}`;
async function saveAssessment(assessment) {
- const { assessments } = await loadStore();
+ const { assessments, readError } = await loadStore();
+ // An unreadable store reports zero assessments, and writing on top of that
+ // would replace every prior measurement with this one record — a read failure
+ // silently destroying data the user spent minutes of compute on. Quarantine
+ // the unreadable file instead: nothing is lost, and the feature keeps working
+ // rather than wedging on a file the user has no way to repair from the UI.
+ if (readError) await quarantineStore(readError);
const key = assessmentKey(assessment.backend, assessment.modelId);
// One record per (backend, model): the newest measurement supersedes the old
// one. History is not kept — a stale reading from a different memory state is
@@ -193,7 +210,10 @@ async function saveAssessment(assessment) {
* so the caller can 404 rather than reporting a phantom success.
*/
export async function deleteAssessment(backend, modelId) {
- const { assessments } = await loadStore();
+ const { assessments, readError } = await loadStore();
+ // Same hazard as saveAssessment: rewriting from an empty in-memory list would
+ // wipe the file. A delete against an unreadable store has nothing to remove.
+ if (readError) return { deleted: false };
const key = assessmentKey(backend, modelId);
const next = assessments.filter((a) => assessmentKey(a?.backend, a?.modelId) !== key);
if (next.length === assessments.length) return { deleted: false };
diff --git a/server/services/localModelAssessments.test.js b/server/services/localModelAssessments.test.js
index c17f36f4de..2ab1fa2a53 100644
--- a/server/services/localModelAssessments.test.js
+++ b/server/services/localModelAssessments.test.js
@@ -7,7 +7,7 @@
*/
import { describe, it, expect, beforeEach, afterAll, vi } from 'vitest';
-import { rmSync, existsSync } from 'fs';
+import { rmSync, existsSync, mkdirSync, writeFileSync, readdirSync } from 'fs';
import { join } from 'path';
import { createTempDataRoot, makePathsProxy } from '../lib/mockPathsDataRoot.js';
@@ -321,6 +321,37 @@ describe('cancellation', () => {
});
});
+describe('an unreadable store', () => {
+ const corrupt = () => {
+ mkdirSync(join(tempRoot, 'local-llm'), { recursive: true });
+ writeFileSync(STORE, '{ this is not json');
+ };
+
+ it('reports the read error instead of claiming nothing was assessed', async () => {
+ corrupt();
+ expect((await svc.getAssessmentReport()).readError).toBeTruthy();
+ });
+
+ it('parks the bad file rather than overwriting it with a single new record', async () => {
+ corrupt();
+ runLocalLlmTest.mockResolvedValue(okRun());
+ await svc.runAssessment({ backend: 'ollama', modelId: 'example-model:7b', contextTokens: [512] });
+
+ // Writing straight through would have replaced whatever the old file held
+ // with just this record — a read failure destroying minutes of measured
+ // compute. The old bytes survive alongside a fresh, working store.
+ const parked = readdirSync(join(tempRoot, 'local-llm')).filter((f) => f.includes('.corrupt-'));
+ expect(parked).toHaveLength(1);
+ expect(await svc.loadAssessments()).toHaveLength(1);
+ });
+
+ it('refuses to rewrite the file on a delete it cannot read', async () => {
+ corrupt();
+ expect(await svc.deleteAssessment('ollama', 'example-model:7b')).toEqual({ deleted: false });
+ expect(existsSync(STORE)).toBe(true);
+ });
+});
+
describe('deleteAssessment', () => {
it('removes a record and reports that it did', async () => {
runLocalLlmTest.mockResolvedValue(okRun());