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): drop stray mid-caption trigger fragments so stripping can't duplicate the trigger token (#1320)
[._.]/ Adam Eivy1d1f6b26c335
diff --git a/server/lib/loraDataset.js b/server/lib/loraDataset.jsindex 44dd1be2a0..19ab00b3de 100644--- a/server/lib/loraDataset.js+++ b/server/lib/loraDataset.js@@ -364,13 +364,22 @@ export function analyzeCaptionInvariants(images, triggerWord, {* matched by normalized form, so case/whitespace differences still strip. A* caption left with no descriptive body collapses to just the trigger word* (still a valid binding-only caption). Idempotent — re-running strips nothing.+ *+ * Works at the comma-fragment level. A bare-trigger fragment that sits MID-+ * caption (the trigger appears as its own fragment but not as the leading+ * prefix) is also dropped: prefixCaption re-adds the trigger once at the front,+ * so keeping the stray one would duplicate the token in the rewritten caption.*/export function stripSharedFragments(caption, fragmentsToStrip, triggerWord) {const stripSet = new Set((Array.isArray(fragmentsToStrip) ? fragmentsToStrip : []).map(normalizeFragment).filter(Boolean));if (!stripSet.size) return trim(caption);- const kept = splitCaptionFragments(caption, triggerWord)- .filter((frag) => !stripSet.has(normalizeFragment(frag)));- return prefixCaption(triggerWord, kept.join(', '));+ const word = trim(triggerWord);+ const wordNorm = word.toLowerCase();+ const kept = splitCaptionFragments(caption, word).filter((frag) => {+ const norm = normalizeFragment(frag);+ return !stripSet.has(norm) && (!wordNorm || norm !== wordNorm);+ });+ return prefixCaption(word, kept.join(', '));}diff --git a/server/lib/loraDataset.test.js b/server/lib/loraDataset.test.jsindex 03d78cc593..06bb660291 100644--- a/server/lib/loraDataset.test.js+++ b/server/lib/loraDataset.test.js@@ -358,6 +358,15 @@ describe('stripSharedFragments', () => {expect(stripSharedFragments(caption, [], trigger)).toBe(caption);});+ it('drops a stray mid-caption trigger fragment instead of duplicating the prefix', () => {+ // Non-canonical caption: trigger appears as a fragment but not as the lead.+ const caption = `white hair, ${trigger}, standing`;+ const out = stripSharedFragments(caption, ['white hair'], trigger);+ expect(out).toBe(`${trigger}, standing`);+ // Exactly one trigger token in the result.+ expect(out.split(trigger)).toHaveLength(2);+ });+it('round-trips with analyzeCaptionInvariants — stripping clears the shared set', () => {const ready = (id, body) => ({ id, status: 'ready', caption: prefixCaption(trigger, body) });const images = [