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): scope caption strip to trigger-bearing captions so it can't prefix-promote unrelated ones (#1320)

[._.]/ Adam Eivyf3ac4da1c30d
diff --git a/server/services/loraDatasets.js b/server/services/loraDatasets.js
index 8f2dc98761..c3653ffed9 100644
--- a/server/services/loraDatasets.js
+++ b/server/services/loraDatasets.js
@@ -24,6 +24,7 @@ import {
LORA_DATASET_SCHEMA_VERSION,
LORA_DATASET_ENTRY_KINDS,
analyzeCaptionInvariants,
+ captionHasTriggerWord,
computeDatasetReadiness,
deriveTriggerWord,
isValidTriggerWord,
@@ -454,7 +455,12 @@ export async function stripSharedCaptionFragments(id) {
const next = await updateDataset(id, (record) => ({
...record,
images: record.images.map((img) => {
- if (img.status !== 'ready' || !img.caption) return img;
+ // Only rewrite the captions the analysis actually looked at — ready AND
+ // trigger-bearing. A ready caption that lacks the trigger was excluded
+ // from analyzeCaptionInvariants; rewriting it would re-`prefixCaption` the
+ // trigger onto it, silently making an unrelated caption count toward
+ // readiness/the training manifest even when no shared fragment matched.
+ if (img.status !== 'ready' || !captionHasTriggerWord(img.caption, record.triggerWord)) return img;
const stripped = stripSharedFragments(img.caption, toStrip, record.triggerWord);
if (stripped === img.caption) return img;
updatedImages += 1;
diff --git a/server/services/loraDatasets.test.js b/server/services/loraDatasets.test.js
index bdd8896d04..b77d0b36d5 100644
--- a/server/services/loraDatasets.test.js
+++ b/server/services/loraDatasets.test.js
@@ -463,4 +463,24 @@ describe('stripSharedCaptionFragments', () => {
expect(second.removedFragments).toEqual([]);
expect(second.updatedImages).toBe(0);
});
+
+ it('leaves captions without the trigger word untouched (never prefixes them)', async () => {
+ const id = await seedFreydisDataset();
+ // Add a ready caption that shares an identity fragment but lacks the trigger
+ // — it was excluded from the analysis, so the strip must not touch it (and
+ // must not silently prepend the trigger, which would inflate readiness).
+ const tmpPath = join(TEST_DATA_ROOT, 'untriggered.png');
+ await makePng(tmpPath);
+ const entry = await addUploadedImage(id, { tmpPath });
+ await updateImageCaption(id, entry.id, 'white hair, circlet, lurking in shadow');
+
+ const before = await getDataset(id);
+ const captionedBefore = before.readiness.captioned;
+ const { dataset } = await stripSharedCaptionFragments(id);
+
+ const untriggered = dataset.images.find((i) => i.id === entry.id);
+ expect(untriggered.caption).toBe('white hair, circlet, lurking in shadow');
+ // Strip didn't convert the untriggered caption into a trigger-bearing one.
+ expect(dataset.readiness.captioned).toBe(captionedBefore);
+ });
});