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: refuse Qwen fine-tuning and placeholder checkpoint promotion without a real adapter (#8857)
[._.]/ Adam Eivyf467d30dd18d
diff --git a/client/src/components/universe/CharacterDetailEditor.jsx b/client/src/components/universe/CharacterDetailEditor.jsxindex 228e94ca06..63f603a87a 100644--- a/client/src/components/universe/CharacterDetailEditor.jsx+++ b/client/src/components/universe/CharacterDetailEditor.jsx@@ -1146,7 +1146,7 @@ function VoiceProfileSection({ universeId, entry, disabled }) {{activeTab === 'finetune' && (<div className="space-y-2">- <p className="text-[10px] text-gray-400">Optional character voice fine-tuning. Checkpointed and cancellable; never assumes the last checkpoint is best.</p>+ <p className="text-[10px] text-gray-400">Optional character voice fine-tuning. Requires a supported Qwen training adapter; without one the request is refused and no checkpoint is created.</p><div className="flex gap-2"><label className="block text-[10px] text-gray-400 flex-1">Epochsdiff --git a/docs/features/voice.md b/docs/features/voice.mdindex 0fd1eb06b1..780cc5da07 100644--- a/docs/features/voice.md+++ b/docs/features/voice.md@@ -368,6 +368,9 @@ streaming qualification. Without that opt-in, AuK remains studio-only and theexisting interactive fallback is retained. The production planner checks theinteractive route rather than treating every approved studio voice as live-ready.-The separate Qwen runtime supports verified local inference but has no training adapter and is excluded from+The separate Qwen runtime supports verified local inference but has no training adapter. Its probe reports+`training_adapter: null`, so starting fine-tuning returns `503 QWEN3_TRAINING_UNAVAILABLE` before any job+record or process exists, and checkpoints recorded by earlier placeholder runners (no producing adapter) are+refused with `409 CHECKPOINT_UNVERIFIED` rather than promoted. The runtime is excluded fromVoice Studio assignment until repaired (issue #8857). Voice Studio does notclaim a Qwen runtime is working merely because its metadata exists.diff --git a/scripts/qwen3_tts_runner.py b/scripts/qwen3_tts_runner.pyindex 49cfbef496..44a429f512 100755--- a/scripts/qwen3_tts_runner.py+++ b/scripts/qwen3_tts_runner.py@@ -174,6 +174,9 @@ def probe_runtime(models_dir: Path | None = None) -> dict:"mps_available": False,"vram_gb": None,"models": {},+ # Name of a real training adapter once one exists. Inference readiness+ # never implies training support; PortOS refuses fine-tuning while null.+ "training_adapter": None,}try:diff --git a/scripts/qwen3_tts_runner.test.js b/scripts/qwen3_tts_runner.test.jsindex 9715ba17fb..b9c8683f08 100644--- a/scripts/qwen3_tts_runner.test.js+++ b/scripts/qwen3_tts_runner.test.js@@ -367,7 +367,7 @@ core.metal.is_available = lambda: Falseunavailable = runner.probe_runtime()print(json.dumps({"status": status, "unavailable": unavailable}))`);- expect(result.status).toMatchObject({ ok: true, device: 'mlx', error: null, torch_installed: false });+ expect(result.status).toMatchObject({ ok: true, device: 'mlx', error: null, torch_installed: false, training_adapter: null });expect(result.unavailable).toMatchObject({ ok: false });});});diff --git a/server/services/voice/fineTuning.js b/server/services/voice/fineTuning.jsindex 0026223b0e..47fbbd6888 100644--- a/server/services/voice/fineTuning.js+++ b/server/services/voice/fineTuning.js@@ -6,6 +6,8 @@* checkpoint promotion.** Training is machine-local, optional, and never assumes the last checkpoint is best.+ * It starts only when the runner's probe names a real training adapter; today+ * none exists, so starts refuse and adapter-less legacy checkpoints never promote.*/import { randomUUID } from 'node:crypto';@@ -20,7 +22,7 @@ import { closeJobAfterDelay } from '../../lib/sseUtils.js';import {DEFAULT_CLONE_MODEL,QWEN3_TTS_RUNNER_SCRIPT,- resolveQwen3Python,+ getQwen3RuntimeStatus,} from './qwen3TtsRuntime.js';import {getVoiceProfileRequired,@@ -183,11 +185,13 @@ export async function startFineTuningJob({});}- const python = await resolveQwen3Python();- if (!python) {- throw new ServerError('Python runtime is unavailable for fine-tuning', {+ // Refuse before a job record or child exists. Inference readiness is not+ // training support; only a runner that names a real adapter may train.+ const runtime = await getQwen3RuntimeStatus();+ if (!runtime.ok || !runtime.pythonPath || !runtime.trainingAdapter) {+ throw new ServerError('Qwen3-TTS fine-tuning is unavailable: no supported training adapter is installed', {status: 503,- code: 'QWEN3_RUNTIME_UNAVAILABLE',+ code: 'QWEN3_TRAINING_UNAVAILABLE',});}@@ -211,6 +215,7 @@ export async function startFineTuningJob({checkpoints: [],outputDir,baseModel,+ trainingAdapter: runtime.trainingAdapter,startedAt: new Date().toISOString(),completedAt: null,error: null,@@ -231,7 +236,7 @@ export async function startFineTuningJob({'--model-id', baseModel,];- const child = spawn(python, args, safeChildProcessOptions({ signal: abortController.signal }));+ const child = spawn(runtime.pythonPath, args, safeChildProcessOptions({ signal: abortController.signal }));// Keep a handle on the child so a future shutdown hook can reach in-flight training.jobState.child = child;@@ -351,6 +356,14 @@ export async function promoteCheckpoint({ profileId, jobId, checkpointId }) {if (!ckpt) {throw new ServerError(`Checkpoint not found: ${checkpointId}`, { status: 404, code: 'CHECKPOINT_NOT_FOUND' });}+ // Earlier runners wrote text placeholders named .safetensors. A job without+ // the adapter that produced it can never become an approved voice.+ if (!job.trainingAdapter) {+ throw new ServerError('Checkpoint was not produced by a supported training adapter', {+ status: 409,+ code: 'CHECKPOINT_UNVERIFIED',+ });+ }return promoteFineTunedProfile({profileId,diff --git a/server/services/voice/fineTuning.test.js b/server/services/voice/fineTuning.test.jsindex 5a6b0170f1..d5e813de27 100644--- a/server/services/voice/fineTuning.test.js+++ b/server/services/voice/fineTuning.test.js@@ -4,17 +4,15 @@ import { mkdtemp, rm, mkdir, writeFile, readFile } from 'node:fs/promises';import { tmpdir } from 'node:os';import { join } from 'node:path';import { SSE_CLEANUP_DELAY_MS } from '../../lib/sseUtils.js';-import { PY_TEST_TIMEOUT_MS, resolveTestPython } from '../../lib/testHelper.js';let voiceProfilesRoot = '';const queryMock = vi.fn();-// Both overrides default to null = "use the real thing", so one suite can hold-// the deterministic state-machine cases AND the single runner-boundary case-// that must exercise actual spawn wiring (vi.mock is per-FILE and hoisted, so-// a runtime switch is the only way to have both).+// Both overrides default to null = "use the real thing". The runner itself+// reports no training adapter today (scripts/qwen3_tts_runner.test.js), so the+// lifecycle cases stand in a scripted adapter and child for a future one.let spawnOverride = null;-let pythonOverride = null;+let runtimeOverride = null;vi.mock('../../lib/db.js', () => ({ query: (...args) => queryMock(...args) }));vi.mock('../../lib/paths.js', async () => {@@ -27,7 +25,7 @@ vi.mock('../../lib/childProcess.js', async (importOriginal) => {});vi.mock('./qwen3TtsRuntime.js', async (importOriginal) => {const actual = await importOriginal();- return { ...actual, resolveQwen3Python: async () => pythonOverride ?? actual.resolveQwen3Python() };+ return { ...actual, getQwen3RuntimeStatus: async () => runtimeOverride ?? actual.getQwen3RuntimeStatus() };});const {@@ -63,7 +61,7 @@ beforeEach(async () => {voiceProfilesRoot = await mkdtemp(join(tmpdir(), 'portos-voice-profiles-'));queryMock.mockReset();spawnOverride = null;- pythonOverride = null;+ runtimeOverride = null;});afterEach(async () => {@@ -94,7 +92,7 @@ const createScriptedChild = ({ signal } = {}) => {child.stdout = new EventEmitter();child.kill = vi.fn();// Frames mirror the runner's stdout contract (scripts/qwen3_tts_runner.py);- // the runner-boundary case below is what keeps that mirror honest.+ // they describe the contract a real training adapter must emit.child.emitFrames = (...frames) => {for (const frame of frames) {child.stdout.emit('data', Buffer.from(`${JSON.stringify(frame)}\n`));@@ -124,7 +122,7 @@ const checkpointFrame = (step) => ({/** Install a scripted child and hand the test the handle spawn will return. */const useScriptedRunner = () => {- pythonOverride = '/scripted/python';+ runtimeOverride = { ok: true, pythonPath: '/scripted/python', trainingAdapter: 'scripted-adapter' };let child = null;spawnOverride = (_command, _args, options) => {child = createScriptedChild(options);@@ -378,33 +376,34 @@ describe('fineTuning', () => {});});-// One boundary case keeps the scripted frames above honest: it runs the actual-// Python runner through the real spawn, so a rename in either the runner's-// stdout contract or the arguments it is handed fails here.-describe.skipIf(!resolveTestPython())('fineTuning runner boundary', () => {- it('records unsupported training as failed without fabricated checkpoints', async () => {+describe('fineTuning without a training adapter', () => {+ it('refuses to start before creating a job or spawning when inference is ready but training is not', async () => {queryMock.mockResolvedValue({ rows: [{ data: PROFILE }] });await seedSourceAudio();- // Windows ships a `python` Store-alias stub that resolves but cannot run, so- // take the interpreter the shared helper proved executable.- pythonOverride = resolveTestPython();+ runtimeOverride = { ok: true, pythonPath: '/scripted/python', trainingAdapter: null };+ spawnOverride = vi.fn();- const { jobId } = await startFineTuningJob({- profileId: PROFILE.id,- epochs: 2,- checkpointInterval: 20,- });+ await expect(startFineTuningJob({ profileId: PROFILE.id, epochs: 2 }))+ .rejects.toMatchObject({ status: 503, code: 'QWEN3_TRAINING_UNAVAILABLE' });+ expect(spawnOverride).not.toHaveBeenCalled();+ await expect(readFile(join(voiceProfilesRoot, PROFILE.id, 'fine-tune'))).rejects.toMatchObject({ code: 'ENOENT' });+ });- // A real interpreter's wall time tracks machine load, not the assertion, so- // both budgets come from the repository's Python-shelling allowance rather- // than a fixed inner deadline (#6268). The poll is strictly below the- // vitest budget so a genuinely stuck run reports the status it observed- // instead of producing a bare test timeout.- const record = await drainJobRecord(jobId, { timeout: Math.floor(PY_TEST_TIMEOUT_MS * 0.75) });- expect(record.status).toBe('failed');- expect(record.checkpoints).toEqual([]);- const status = await getFineTuningJobStatus(jobId, PROFILE.id);- expect(status.status).toBe('failed');- expect(status.progress).not.toBe(100);- }, PY_TEST_TIMEOUT_MS);+ it('never promotes a legacy placeholder checkpoint that has no producing adapter', async () => {+ queryMock.mockResolvedValue({ rows: [{ data: PROFILE }] });+ const jobId = '11111111-2222-4333-8444-555555555555';+ await mkdir(join(voiceProfilesRoot, PROFILE.id, 'fine-tune', jobId), { recursive: true });+ await writeFile(jobRecordPath(jobId), JSON.stringify({+ id: jobId,+ profileId: PROFILE.id,+ universeId: 'universe-1',+ characterId: 'character-1',+ status: 'completed',+ checkpoints: [{ id: 'checkpoint-20.safetensors', step: 20, checkpointPath: '/legacy/checkpoint-20.safetensors' }],+ }));++ await expect(promoteCheckpoint({ profileId: PROFILE.id, jobId, checkpointId: 'checkpoint-20.safetensors' }))+ .rejects.toMatchObject({ status: 409, code: 'CHECKPOINT_UNVERIFIED' });+ expect(queryMock.mock.calls.some(([sql]) => /insert|update/i.test(sql))).toBe(false);+ });});diff --git a/server/services/voice/qwen3TtsRuntime.js b/server/services/voice/qwen3TtsRuntime.jsindex 4bf7b5683f..0eba96661b 100644--- a/server/services/voice/qwen3TtsRuntime.js+++ b/server/services/voice/qwen3TtsRuntime.js@@ -86,6 +86,7 @@ export async function getQwen3RuntimeStatus() {hardware: { device: 'cpu', cuda: false, mps: false, vramGb: null },models: {},supportedModels: SUPPORTED_QWEN3_MODELS,+ trainingAdapter: null,message: 'Python environment not found for Qwen3-TTS runtime',};}@@ -120,6 +121,9 @@ export async function getQwen3RuntimeStatus() {},models: modelsState,supportedModels: SUPPORTED_QWEN3_MODELS,+ // Training is a separate capability: the runner names its adapter only+ // when one can produce loadable checkpoints (#8857).+ trainingAdapter: typeof data.training_adapter === 'string' && data.training_adapter ? data.training_adapter : null,};} catch (err) {return {@@ -130,6 +134,7 @@ export async function getQwen3RuntimeStatus() {hardware: { device: 'cpu', cuda: false, mps: false, vramGb: null },models: {},supportedModels: SUPPORTED_QWEN3_MODELS,+ trainingAdapter: null,error: err.message,};}diff --git a/server/services/voice/qwen3TtsRuntime.test.js b/server/services/voice/qwen3TtsRuntime.test.jsindex 6a17adbc86..51a3c265c7 100644--- a/server/services/voice/qwen3TtsRuntime.test.js+++ b/server/services/voice/qwen3TtsRuntime.test.js@@ -46,6 +46,12 @@ describe('qwen3TtsRuntime', () => {expect(status.models[modelId].downloaded).toBe(true);expect(spawn.mock.calls[0][1]).toContain('--probe');expect(spawn.mock.calls[0][1]).not.toContain('--download');+ expect(status.trainingAdapter).toBeNull();+ });++ it('keeps training unavailable when inference is ready but the runner names no adapter', async () => {+ runnerResponse({ ok: true, models: {}, training_adapter: null });+ expect(await getQwen3RuntimeStatus()).toMatchObject({ ok: true, trainingAdapter: null });});it('downloads explicitly, coalesces duplicate requests, and requires verified results', async () => {