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

Keep a cancelled fine-tune busy until its trainer exits

Claudef89222286fbc
diff --git a/client/src/components/voice/VoiceFineTuningPanel.jsx b/client/src/components/voice/VoiceFineTuningPanel.jsx
index b2fbdf8ab2..327d8dc093 100644
--- a/client/src/components/voice/VoiceFineTuningPanel.jsx
+++ b/client/src/components/voice/VoiceFineTuningPanel.jsx
@@ -95,6 +95,7 @@ function JobCard({ job, activeModelRevision, disabled, cancelling, onCancel, pro
{' · '}started {timeAgo(job.startedAt, 'unknown')}
{job.step ? <> · step {formatCount(job.step)}{job.totalSteps ? ` / ${formatCount(job.totalSteps)}` : ''}</> : null}
{Number.isFinite(job.loss) ? <> · loss {job.loss.toFixed(3)}</> : null}
+ {!running && job.processActive ? <> · <span className="inline-flex items-center gap-1"><Loader2 size={10} className="animate-spin" /> stopping trainer</span></> : null}
</p>
{running ? (
<button
@@ -208,7 +209,9 @@ export default function VoiceFineTuningPanel({ profileId, disabled, activeModelR
await onPromoted?.(result.profile);
};
- const anyRunning = Boolean(jobs?.some((job) => job.status === 'running'));
+ // A cancelled run reads `cancelled` before its trainer has exited; the server
+ // refuses a new run until it has (`processActive`), so Start waits too.
+ const anyRunning = Boolean(jobs?.some((job) => job.status === 'running' || job.processActive));
const epochsId = `fine-tune-epochs-${profileId || 'none'}`;
return (
diff --git a/client/src/components/voice/VoiceFineTuningPanel.test.jsx b/client/src/components/voice/VoiceFineTuningPanel.test.jsx
index b3c33e6338..04be0e539b 100644
--- a/client/src/components/voice/VoiceFineTuningPanel.test.jsx
+++ b/client/src/components/voice/VoiceFineTuningPanel.test.jsx
@@ -71,11 +71,17 @@ describe('VoiceFineTuningPanel', () => {
await waitFor(() => expect(mocks.start).toHaveBeenCalledWith(PROFILE_ID, { epochs: 8 }, { silent: true }));
expect(await screen.findByText('running')).toBeTruthy();
- mocks.cancel.mockResolvedValue({ ok: true, jobId: JOB_ID, status: 'cancelled', job: job({ status: 'cancelled', error: 'Cancelled by user' }) });
+ mocks.cancel.mockResolvedValue({ ok: true, jobId: JOB_ID, status: 'cancelled',
+ job: job({ status: 'cancelled', error: 'Cancelled by user', processActive: true }) });
fireEvent.click(screen.getByRole('button', { name: /Cancel/ }));
expect(await screen.findByText('cancelled')).toBeTruthy();
expect(mocks.cancel).toHaveBeenCalledWith(PROFILE_ID, JOB_ID, { silent: true });
expect(screen.getByText('Cancelled by user')).toBeTruthy();
+ // The aborted trainer has not exited yet, so a new run must wait for it.
+ expect(screen.getByText(/stopping trainer/)).toBeTruthy();
+ expect(screen.getByRole('button', { name: /Start Fine-Tuning Job/ })).toBeDisabled();
+ emit('voice:fine-tune:updated', frame({ status: 'cancelled', error: 'Cancelled by user', processActive: false }));
+ await waitFor(() => expect(screen.getByRole('button', { name: /Start Fine-Tuning Job/ })).toBeEnabled());
});
it('promotes a verified checkpoint, refreshes profiles, and keeps an unverified one blocked with its reason', async () => {
diff --git a/docs/features/voice.md b/docs/features/voice.md
index b97dd787e9..a23f87b5ab 100644
--- a/docs/features/voice.md
+++ b/docs/features/voice.md
@@ -478,6 +478,8 @@ runs from their `job.json` sidecars (`GET /api/voice/profiles/:id/fine-tune`, ne
recovers them. After that it applies `voice:fine-tune:updated` frames, which carry the whole job, on each
status change, each sealed checkpoint, and at most once a second during training. It does not poll. Each
checkpoint plays its audition from `/data/voice-profiles/…`. **Promote** is disabled, with the refusal
-reason beside it, on any checkpoint the server would refuse. **Cancel** appears while a run is live. A
+reason beside it, on any checkpoint the server would refuse. **Cancel** appears while a run is live. A voice
+trains one run at a time (`409 FINE_TUNE_ALREADY_RUNNING`), and a cancelled run still counts until its
+trainer process has exited (`processActive`). A
sidecar left `running` by a server restart is reported as `interrupted`, because its process is gone. Its
sealed checkpoints remain promotable.
diff --git a/server/lib/socketEventContracts.js b/server/lib/socketEventContracts.js
index 0dcf90c501..a5caf6e9a5 100644
--- a/server/lib/socketEventContracts.js
+++ b/server/lib/socketEventContracts.js
@@ -76,6 +76,7 @@ export const SOCKET_EVENT_CONTRACTS = Object.freeze({
step: { type: ['integer', 'null'] },
totalSteps: { type: ['integer', 'null'] },
error: { type: ['string', 'null'] },
+ processActive: { type: 'boolean' },
checkpoints: { type: 'array', items: { type: 'object' } },
},
},
diff --git a/server/services/voice/fineTuning.js b/server/services/voice/fineTuning.js
index 56e419587e..e8dfea300d 100644
--- a/server/services/voice/fineTuning.js
+++ b/server/services/voice/fineTuning.js
@@ -123,11 +123,15 @@ const auditionUrl = (sampleWav) => {
* The client view of a job: the durable record plus what the Voice Lab renders
* per checkpoint — a playable audition URL and whether (and why not) it can be
* promoted, decided by the same predicate `promoteCheckpoint` enforces.
+ * `processActive` is true while the trainer process has not exited yet — a
+ * cancelled run reads `cancelled` at once but may still hold the GPU until
+ * then. Records read from disk never have a live process.
*/
const publicJob = (job) => {
const record = serializableJob(job);
return {
...record,
+ processActive: job.finalized === false,
checkpoints: record.checkpoints.map((checkpoint) => {
const blockedReason = promotionBlockedReason(record, checkpoint);
return {
@@ -203,9 +207,12 @@ const finalizeJob = (jobState) => {
closeJobAfterDelay(activeJobs, jobState.id);
};
+// Busy until the child has exited (`finalizeJob`), not merely until the status
+// leaves `running`: a cancel flips the status before the aborted trainer has
+// released the GPU.
const assertNoRunningJob = (profileId) => {
for (const job of activeJobs.values()) {
- if (job.profileId === profileId && job.status === 'running') {
+ if (job.profileId === profileId && job.finalized === false) {
throw new ServerError('A fine-tuning run is already in progress for this voice profile', {
status: 409,
code: 'FINE_TUNE_ALREADY_RUNNING',
@@ -363,6 +370,8 @@ export async function startFineTuningJob({
error: null,
controller: abortController,
child: null,
+ // Flipped by `finalizeJob` once the child has closed or errored.
+ finalized: false,
};
activeJobs.set(jobId, jobState);
diff --git a/server/services/voice/fineTuning.test.js b/server/services/voice/fineTuning.test.js
index 2fee1c6374..4c53b73013 100644
--- a/server/services/voice/fineTuning.test.js
+++ b/server/services/voice/fineTuning.test.js
@@ -423,7 +423,12 @@ describe('fineTuning', () => {
useScriptedRunner();
const spawned = [];
const scriptedSpawn = spawnOverride;
- spawnOverride = (...args) => { const child = scriptedSpawn(...args); spawned.push(child); return child; };
+ // No abort wiring: this test decides when an aborted trainer actually exits.
+ spawnOverride = (command, args, options) => {
+ const child = scriptedSpawn(command, args, { ...options, signal: undefined });
+ spawned.push(child);
+ return child;
+ };
// Two overlapping starts: exactly one becomes a run.
const results = await Promise.allSettled([
@@ -438,11 +443,21 @@ describe('fineTuning', () => {
.rejects.toMatchObject({ status: 409, code: 'FINE_TUNE_ALREADY_RUNNING' });
expect(spawned).toHaveLength(1);
- // Once the run settles the voice can train again.
- spawned[0].exit(0);
+ // A cancel reports `cancelled` at once, but the aborted trainer may still
+ // hold the GPU until it exits, so the voice stays busy until then.
+ const cancelled = cancelFineTuningJob(started[0].value.jobId, PROFILE.id);
+ expect(cancelled.job).toMatchObject({ status: 'cancelled', processActive: true });
+ await expect(startFineTuningJob({ profileId: PROFILE.id, epochs: 2 }))
+ .rejects.toMatchObject({ status: 409, code: 'FINE_TUNE_ALREADY_RUNNING' });
+ expect(spawned).toHaveLength(1);
+
+ // Once the child has exited the voice can train again.
+ spawned[0].exit(null, 'SIGTERM');
await drainJobRecord(started[0].value.jobId);
const next = await startFineTuningJob({ profileId: PROFILE.id, epochs: 2 });
expect(spawned).toHaveLength(2);
+ expect(next.job.processActive).toBe(true);
+ expect((await getFineTuningJobStatus(started[0].value.jobId, PROFILE.id)).processActive).toBe(false);
spawned[1].exit(0);
await drainJobRecord(next.jobId);
});