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 (claude): thread acknowledgeCaptionLeak into the staging re-validation

[._.]/ Adam Eivyff3aa9c367c2
diff --git a/server/services/loraTraining/captionLeakStaging.test.js b/server/services/loraTraining/captionLeakStaging.test.js
new file mode 100644
index 0000000000..0cd21da1dc
--- /dev/null
+++ b/server/services/loraTraining/captionLeakStaging.test.js
@@ -0,0 +1,72 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+
+// Regression guard for the caption-leak gate's SECOND call site. The gate is
+// re-checked when the queued job actually stages (runTraining), not just at
+// launch (startTrainingRun). That staging re-validation must NOT re-apply the
+// leak gate — a leaky run only reaches the queue via an explicit "Train anyway"
+// (acknowledgeCaptionLeak) or a resume, and re-blocking it there would fail the
+// very runs those paths opted in. This pins runTraining → validateDatasetReady
+// being called with { acknowledgeCaptionLeak: true }.
+const getRunMock = vi.fn();
+const updateRunMock = vi.fn();
+const validateDatasetReadyMock = vi.fn();
+const updateDatasetMock = vi.fn();
+
+vi.mock('./db.js', () => ({
+ getRun: (...a) => getRunMock(...a),
+ getRunRequired: vi.fn(),
+ updateRun: (...a) => updateRunMock(...a),
+ listRuns: vi.fn(),
+ deleteRun: vi.fn(),
+}));
+vi.mock('./dataset.js', () => ({ validateDatasetReady: (...a) => validateDatasetReadyMock(...a) }));
+vi.mock('../settings.js', () => ({ getSettings: vi.fn(async () => ({})) }));
+vi.mock('../loraDatasets.js', () => ({ updateDataset: (...a) => updateDatasetMock(...a) }));
+vi.mock('../mediaJobQueue/index.js', () => ({
+ enqueueJob: vi.fn(),
+ getJob: vi.fn(),
+ mediaJobEvents: { emit: vi.fn(), on: vi.fn() },
+}));
+
+const { runTraining } = await import('./index.js');
+
+// validateDatasetReady mock that mirrors the real gate: throw the leak 409 when
+// the caller did NOT acknowledge, succeed (with a deliberately MISMATCHED
+// character so runTraining bails at the ownership check, before any real spawn)
+// when it did. So if the staging call ever drops the acknowledge flag again,
+// runTraining fails with the leak message instead of the reassignment one.
+const wireLeakyDataset = () => {
+ validateDatasetReadyMock.mockImplementation(async (_id, opts = {}) => {
+ if (!opts.acknowledgeCaptionLeak) {
+ const err = new Error('Identity is leaking into the captions — "red cloak" repeat across most images');
+ err.status = 409;
+ err.code = 'CAPTION_IDENTITY_LEAK';
+ throw err;
+ }
+ return { dataset: { character: { entryId: 'other', universeId: 'u1' } }, manifest: { images: [] } };
+ });
+};
+
+describe('runTraining staging re-validation bypasses the caption-leak gate', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ getRunMock.mockResolvedValue({
+ id: 'run-1',
+ datasetId: 'ds1',
+ character: { entryId: 'c1', universeId: 'u1' },
+ });
+ updateRunMock.mockResolvedValue();
+ updateDatasetMock.mockResolvedValue();
+ wireLeakyDataset();
+ });
+
+ it('re-validates with acknowledgeCaptionLeak so an acknowledged leaky run is not re-blocked at staging', async () => {
+ await runTraining({ jobId: 'job-1', runId: 'run-1' });
+
+ expect(validateDatasetReadyMock).toHaveBeenCalledWith('ds1', { acknowledgeCaptionLeak: true });
+ // The run still failed — but at the ownership check (mismatched character),
+ // NOT the leak gate. Proves the gate was bypassed at staging.
+ const failError = updateRunMock.mock.calls.find(([, patch]) => patch?.status === 'failed')?.[1]?.error || '';
+ expect(failError).not.toMatch(/leaking/i);
+ });
+});
diff --git a/server/services/loraTraining/index.js b/server/services/loraTraining/index.js
index ce44a9b1cd..f8abf6df5c 100644
--- a/server/services/loraTraining/index.js
+++ b/server/services/loraTraining/index.js
@@ -450,11 +450,15 @@ export async function runTraining({ jobId, runId, pythonPath = null, resumeCheck
return;
}
- // Re-validate — the dataset may have been edited/deleted while queued.
+ // Re-validate — the dataset may have been edited/deleted while queued. Skip
+ // the caption-leak gate: it's a launch-time decision already settled at
+ // enqueue (a non-leaky run cleared it; a leaky run only got here via an
+ // explicit "Train anyway" acknowledge or a resume). Re-blocking on it now
+ // would fail the very runs the acknowledge/resume paths opted in.
let manifest;
let dataset;
try {
- ({ dataset, manifest } = await validateDatasetReady(run.datasetId));
+ ({ dataset, manifest } = await validateDatasetReady(run.datasetId, { acknowledgeCaptionLeak: true }));
} catch (err) {
return failBeforeSpawn(err.message);
}