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 (codex): refuse dataset reassignment while a training run is in flight

[._.]/ Adam Eivy5430a88e2357
diff --git a/client/src/pages/LoraDatasetDetail.jsx b/client/src/pages/LoraDatasetDetail.jsx
index 8a6fb9a60a..9e8b2a324e 100644
--- a/client/src/pages/LoraDatasetDetail.jsx
+++ b/client/src/pages/LoraDatasetDetail.jsx
@@ -378,8 +378,11 @@ export default function LoraDatasetDetail() {
<button
type="button"
onClick={() => setShowReassign(true)}
- title="Reassign this dataset to a different universe character"
- className="shrink-0 text-xs text-gray-500 hover:text-port-accent flex items-center gap-1"
+ disabled={dataset.status === 'training'}
+ title={dataset.status === 'training'
+ ? 'Cancel the in-progress training run before reassigning'
+ : 'Reassign this dataset to a different universe character'}
+ className="shrink-0 text-xs text-gray-500 hover:text-port-accent flex items-center gap-1 disabled:opacity-40 disabled:hover:text-gray-500"
>
<Replace className="w-3.5 h-3.5" /> Reassign
</button>
diff --git a/server/services/loraDatasets.js b/server/services/loraDatasets.js
index d4e4640631..c19ab8b678 100644
--- a/server/services/loraDatasets.js
+++ b/server/services/loraDatasets.js
@@ -207,6 +207,17 @@ export async function patchDataset(id, { triggerWord, universeId, entryId } = {}
resolveCharacterSnapshot(universeId, entryId),
loraDatasetStore.loadAll(),
]);
+ // Refuse while a run is in flight (status 'training' = a queued or running
+ // job exists). A queued run captured this dataset's id + old character
+ // snapshot; if we moved the dataset now, the run would stage the moved
+ // images yet register the adapter under the OLD character. Make the user
+ // cancel first — then reassignment is a clean draft-state operation.
+ const self = all.find((d) => d.id === id);
+ if (self?.status === 'training') {
+ throw new ServerError('Cannot reassign while a training run is in progress — cancel it first', {
+ status: 409, code: 'DATASET_TRAINING',
+ });
+ }
// Enforce the same find-or-create key createDataset uses: at most one
// dataset per (universeId, entryId). Reassigning onto a character that
// already owns a dataset would create a duplicate the list can't tell apart.
diff --git a/server/services/loraDatasets.test.js b/server/services/loraDatasets.test.js
index 03cb13085f..66d1043571 100644
--- a/server/services/loraDatasets.test.js
+++ b/server/services/loraDatasets.test.js
@@ -171,6 +171,16 @@ describe('patchDataset / listDatasets', () => {
expect(next.training.loraFilename).toBe('char-1.safetensors');
});
+ it('refuses to reassign while a training run is in progress', async () => {
+ // status 'training' = a queued/running job that captured this dataset id +
+ // old character; reassigning now would register the adapter under the wrong
+ // character. The user must cancel first.
+ const { dataset } = await createDataset({ universeId: 'uni-1', entryId: 'char-1' });
+ await updateDataset(dataset.id, (current) => ({ ...current, status: 'training' }));
+ await expect(patchDataset(dataset.id, { universeId: 'uni-1', entryId: 'char-2' }))
+ .rejects.toMatchObject({ status: 409, code: 'DATASET_TRAINING' });
+ });
+
it('refuses to reassign onto a character that already owns a dataset', async () => {
const a = await createDataset({ universeId: 'uni-1', entryId: 'char-1' });
await createDataset({ universeId: 'uni-1', entryId: 'char-2' });