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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: index fine-tune checkpoints as they land and surface unreadable records (#5664)
Adam Eivy518e2424d2af
diff --git a/server/services/voice/fineTuning.js b/server/services/voice/fineTuning.jsindex 7352743674..9564765e7b 100644--- a/server/services/voice/fineTuning.js+++ b/server/services/voice/fineTuning.js@@ -14,7 +14,7 @@ import { mkdir, readdir } from 'node:fs/promises';import { join } from 'node:path';import { spawn } from '../../lib/childProcess.js';import { ServerError } from '../../lib/errorHandler.js';-import { atomicWrite, readJSONFile } from '../../lib/fileUtils.js';+import { atomicWrite, readJSONFileStrict } from '../../lib/fileUtils.js';import { safeChildProcessOptions } from '../../lib/processEnv.js';import { closeJobAfterDelay } from '../../lib/sseUtils.js';import {@@ -64,13 +64,22 @@ const persistJob = (jobState) => {/*** Resolve a job from memory, falling back to its on-disk record. Returns null- * when neither exists.+ * only when the record is genuinely absent — a present-but-unreadable record+ * throws instead, because reporting 404 would tell the operator their run is+ * gone while its checkpoints are still sitting on disk.*/async function loadJob(jobId, profileId) {const active = activeJobs.get(jobId);if (active) return active;if (!profileId) return null;- return readJSONFile(jobRecordPath(profileId, jobId), null);+ const { ok, value } = await readJSONFileStrict(jobRecordPath(profileId, jobId), null);+ if (!ok) {+ throw new ServerError('Fine-tuning job record is unreadable', {+ status: 500,+ code: 'JOB_RECORD_UNREADABLE',+ });+ }+ return value;}/**@@ -225,6 +234,11 @@ export async function startFineTuningJob({loss: event.loss,createdAt: new Date().toISOString(),});+ // Checkpoints are the promotable artifact, so index each one as it+ // lands — a restart mid-training must not orphan the ones already+ // written. Step/loss progress deliberately is not persisted: it+ // arrives every step and is worthless once the process is gone.+ persistJob(jobState);} else if (event.stage === 'completed') {jobState.status = 'completed';jobState.progress = 100;diff --git a/server/services/voice/fineTuning.test.js b/server/services/voice/fineTuning.test.jsindex 63ea503755..876fde8dfb 100644--- a/server/services/voice/fineTuning.test.js+++ b/server/services/voice/fineTuning.test.js@@ -187,6 +187,26 @@ describe('fineTuning', () => {expect(promoted).toMatchObject({ kind: 'fine-tuned', approval: { status: 'approved' } });});+ it('reports an unreadable job record as an error rather than a missing job', async () => {+ queryMock.mockResolvedValue({ rows: [{ data: PROFILE }] });+ await seedSourceAudio();++ const { jobId } = await startFineTuningJob({+ profileId: PROFILE.id,+ epochs: 2,+ checkpointInterval: 20,+ });+ await waitForTerminalJobRecord(jobId);+ await writeFile(jobRecordPath(jobId), '{ truncated');++ // A corrupt record must not read as "no such job" — the checkpoints it+ // indexes are still on disk.+ vi.resetModules();+ const restarted = await import('./fineTuning.js');+ await expect(restarted.getFineTuningJobStatus(jobId, PROFILE.id))+ .rejects.toMatchObject({ code: 'JOB_RECORD_UNREADABLE' });+ });+it('evicts the in-memory job entry after the grace window and keeps serving from disk', async () => {vi.useFakeTimers({ shouldAdvanceTime: true });try {