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
address review (codex): re-check queued runs for caption leak + handle string palettes
[._.]/ Adam Eivyeae92fae9b85
diff --git a/server/services/loraDatasetGenerate.js b/server/services/loraDatasetGenerate.jsindex 4b42cd7458..2406b426a7 100644--- a/server/services/loraDatasetGenerate.js+++ b/server/services/loraDatasetGenerate.js@@ -102,10 +102,14 @@ export function extractSubjectSignaturePhrases(subject, entryKind = 'characters'pushNames(subject.props);pushNames(subject.colorPalette);} else {- // Objects/places: the recurring details + palette names are the invariants.- pushNames(subject.colorPalette || subject.palette);- const recurring = flattenValue(subject.recurringDetails);- if (recurring) out.push(...recurring.split(',').map((p) => p.trim()));+ // Objects/places: the recurring details + palette are the invariants. In the+ // looser object/place bible shape both can be a string OR an array, so route+ // them through flattenValue (handles both) rather than the array-only+ // pushNames — a string `palette` would otherwise be dropped entirely.+ for (const raw of [subject.colorPalette || subject.palette, subject.recurringDetails]) {+ const flat = flattenValue(raw);+ if (flat) out.push(...flat.split(',').map((p) => p.trim()));+ }}const visualIdentity = trim(subject.visualIdentity);if (visualIdentity) out.push(visualIdentity);diff --git a/server/services/loraDatasetGenerate.test.js b/server/services/loraDatasetGenerate.test.jsindex b741d0af0f..d00767180f 100644--- a/server/services/loraDatasetGenerate.test.js+++ b/server/services/loraDatasetGenerate.test.js@@ -77,6 +77,14 @@ describe('extractSubjectSignaturePhrases', () => {expect(phrases).toEqual(['mossy green', 'cracked obelisk', 'glowing runes']);});+ it('handles a STRING palette on object/place subjects (not just arrays)', () => {+ const phrases = extractSubjectSignaturePhrases({+ palette: 'mossy green, weathered grey',+ recurringDetails: 'cracked obelisk',+ }, 'places');+ expect(phrases).toEqual(['mossy green', 'weathered grey', 'cracked obelisk']);+ });+it('returns [] for a null/empty subject', () => {expect(extractSubjectSignaturePhrases(null)).toEqual([]);expect(extractSubjectSignaturePhrases({})).toEqual([]);diff --git a/server/services/loraTraining/captionLeakStaging.test.js b/server/services/loraTraining/captionLeakStaging.test.jsindex 0cd21da1dc..72f1d4642d 100644--- a/server/services/loraTraining/captionLeakStaging.test.js+++ b/server/services/loraTraining/captionLeakStaging.test.js@@ -2,11 +2,11 @@ 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 }.+// launch (startTrainingRun). The staging re-check must skip the gate ONLY for a+// run that already opted past it — an explicit "Train anyway" (persisted as+// run.captionLeakAcknowledged) or a resume (resumeCheckpoint set) — while still+// re-checking an ordinary clean-at-launch run, so captions edited leaky WHILE+// the run sat in the queue are caught instead of training silently.const getRunMock = vi.fn();const updateRunMock = vi.fn();const validateDatasetReadyMock = vi.fn();@@ -30,43 +30,57 @@ vi.mock('../mediaJobQueue/index.js', () => ({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 = () => {+// Mirrors the real gate: throw the leak 409 when the caller did NOT acknowledge,+// otherwise return a dataset whose character MISMATCHES the run so runTraining+// bails at the ownership check (before any real spawn). So a regressed staging+// call that dropped the flag surfaces as a leak failure rather than the+// reassignment one.+const LEAK_MSG = 'Identity is leaking into the captions — "red cloak" repeat across most images';+beforeEach(() => {+ vi.clearAllMocks();+ updateRunMock.mockResolvedValue();+ updateDatasetMock.mockResolvedValue();validateDatasetReadyMock.mockImplementation(async (_id, opts = {}) => {if (!opts.acknowledgeCaptionLeak) {- const err = new Error('Identity is leaking into the captions — "red cloak" repeat across most images');+ const err = new Error(LEAK_MSG);err.status = 409;err.code = 'CAPTION_IDENTITY_LEAK';throw err;}return { dataset: { character: { entryId: 'other', universeId: 'u1' } }, manifest: { images: [] } };});-};+});++const failError = () =>+ updateRunMock.mock.calls.find(([, patch]) => patch?.status === 'failed')?.[1]?.error || '';-describe('runTraining staging re-validation bypasses the caption-leak gate', () => {- beforeEach(() => {- vi.clearAllMocks();+describe('runTraining staging re-validation — caption-leak gate', () => {+ it('skips the gate for a run launched with "Train anyway" (captionLeakAcknowledged)', async () => {getRunMock.mockResolvedValue({- id: 'run-1',- datasetId: 'ds1',+ id: 'run-1', datasetId: 'ds1', captionLeakAcknowledged: true,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 });+ expect(failError()).not.toMatch(/leaking/i); // bailed at ownership, not the leak gate+ });+ it('skips the gate when resuming (captions already trained once)', async () => {+ getRunMock.mockResolvedValue({+ id: 'run-1', datasetId: 'ds1', captionLeakAcknowledged: false,+ character: { entryId: 'c1', universeId: 'u1' },+ });+ await runTraining({ jobId: 'job-1', runId: 'run-1', resumeCheckpoint: '/ckpt/step-300' });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);+ });++ it('STILL re-checks an ordinary queued run, catching captions edited leaky while queued', async () => {+ getRunMock.mockResolvedValue({+ id: 'run-1', datasetId: 'ds1', captionLeakAcknowledged: false,+ character: { entryId: 'c1', universeId: 'u1' },+ });+ await runTraining({ jobId: 'job-1', runId: 'run-1' });+ expect(validateDatasetReadyMock).toHaveBeenCalledWith('ds1', { acknowledgeCaptionLeak: false });+ expect(failError()).toMatch(/leaking/i); // the queued-time leak is caught, run fails});});diff --git a/server/services/loraTraining/index.js b/server/services/loraTraining/index.jsindex f8abf6df5c..8cb505c385 100644--- a/server/services/loraTraining/index.js+++ b/server/services/loraTraining/index.js@@ -186,6 +186,11 @@ export async function startTrainingRun({character: dataset.character,datasetId,triggerWord: dataset.triggerWord,+ // Persist whether the launch opted past the caption identity-leak gate, so+ // the staging re-validation can skip the gate for THIS run without also+ // skipping it for ordinary queued runs whose captions were edited (leaky)+ // while waiting in the queue.+ captionLeakAcknowledged: acknowledgeCaptionLeak === true,params: mergedParams,progress: { step: 0, totalSteps: mergedParams.steps, loss: null, lastCheckpointStep: null },artifacts: { dir: `training-runs/${runId}`, checkpoints: [], samples: [] },@@ -451,14 +456,19 @@ export async function runTraining({ jobId, runId, pythonPath = null, resumeCheck}// 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.+ // the caption identity-leak gate ONLY for a run that already opted past it:+ // one launched with an explicit "Train anyway" (persisted on the record) or a+ // resume (its captions already trained once). An ordinary clean-at-launch run+ // is still re-checked here, so captions edited leaky while it sat in the queue+ // are caught instead of training silently.+ const skipCaptionLeakGate = run.captionLeakAcknowledged === true || resumeCheckpoint != null;let manifest;let dataset;try {- ({ dataset, manifest } = await validateDatasetReady(run.datasetId, { acknowledgeCaptionLeak: true }));+ ({ dataset, manifest } = await validateDatasetReady(+ run.datasetId,+ { acknowledgeCaptionLeak: skipCaptionLeakGate },+ ));} catch (err) {return failBeforeSpawn(err.message);}