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

fix([med-pipeline-server-services-pipeline-arcplanner]): warn on duplicate season ids in sanitizeSeasonList

[._.]/ Adam Eivyec97ab0897ca
diff --git a/server/lib/storyArc.js b/server/lib/storyArc.js
index cde4556bac..589d8435f4 100644
--- a/server/lib/storyArc.js
+++ b/server/lib/storyArc.js
@@ -308,16 +308,31 @@ export function sanitizeSeason(raw, { preserveTimestamps = true } = {}) {
* SEASONS_PER_SERIES_MAX, deduplicates ids (last-write-wins on collision),
* and sorts by `number` ascending so consumers can render straight from the
* array.
+ *
+ * LWW dedupe is silent — surfacing the collision matters because child issues
+ * carry `seasonId` pointers, so a dropped duplicate leaves those issues
+ * attached to the surviving season under the colliding id, which is rarely
+ * what the producer (usually an LLM rewrite) intended. The helper warns on
+ * duplicates with the offending ids so the responsible run is grep-able in
+ * logs without crashing the persist path.
*/
export function sanitizeSeasonList(rawList, opts = {}) {
if (!Array.isArray(rawList)) return [];
const byId = new Map();
+ const duplicateIds = [];
for (const raw of rawList) {
const s = sanitizeSeason(raw, opts);
if (!s) continue;
+ if (byId.has(s.id)) duplicateIds.push(s.id);
byId.set(s.id, s);
if (byId.size >= ARC_LIMITS.SEASONS_PER_SERIES_MAX) break;
}
+ if (duplicateIds.length) {
+ const distinct = [...new Set(duplicateIds)];
+ console.warn(
+ `⚠️ sanitizeSeasonList dropped ${duplicateIds.length} duplicate season entry/entries via LWW across ${distinct.length} colliding id(s): ${distinct.join(', ')} — child issues stay attached to the surviving entry`,
+ );
+ }
return [...byId.values()].sort((a, b) => (a.number || 0) - (b.number || 0));
}
diff --git a/server/lib/storyArc.test.js b/server/lib/storyArc.test.js
index 7fba7727d4..3c8fe27db5 100644
--- a/server/lib/storyArc.test.js
+++ b/server/lib/storyArc.test.js
@@ -162,13 +162,62 @@ describe('storyArc — sanitizeSeasonList', () => {
expect(out.map((s) => s.title)).toEqual(['B', 'C', 'A']);
});
- it('deduplicates by id (last write wins)', () => {
+ it('deduplicates by id (last write wins) and warns on collision', () => {
+ const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
const out = sanitizeSeasonList([
{ id: 'sea-dup', title: 'first', number: 1 },
{ id: 'sea-dup', title: 'second', number: 1 },
]);
expect(out).toHaveLength(1);
expect(out[0].title).toBe('second');
+ expect(warnSpy).toHaveBeenCalledTimes(1);
+ const msg = warnSpy.mock.calls[0][0];
+ expect(msg).toContain('sea-dup');
+ expect(msg).toContain('duplicate');
+ warnSpy.mockRestore();
+ });
+
+ it('does not warn when ids are unique', () => {
+ const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
+ sanitizeSeasonList([
+ { id: 'sea-a', title: 'A', number: 1 },
+ { id: 'sea-b', title: 'B', number: 2 },
+ ]);
+ expect(warnSpy).not.toHaveBeenCalled();
+ warnSpy.mockRestore();
+ });
+
+ it('reports every duplicate id when multiple ids collide', () => {
+ const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
+ sanitizeSeasonList([
+ { id: 'sea-a', title: 'A1', number: 1 },
+ { id: 'sea-a', title: 'A2', number: 1 },
+ { id: 'sea-b', title: 'B1', number: 2 },
+ { id: 'sea-b', title: 'B2', number: 2 },
+ ]);
+ expect(warnSpy).toHaveBeenCalledTimes(1);
+ const msg = warnSpy.mock.calls[0][0];
+ expect(msg).toContain('sea-a');
+ expect(msg).toContain('sea-b');
+ expect(msg).toContain('2 duplicate');
+ expect(msg).toContain('2 colliding');
+ warnSpy.mockRestore();
+ });
+
+ it('does not repeat the same id in the warning when one id collides 3+ times', () => {
+ const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
+ sanitizeSeasonList([
+ { id: 'sea-a', title: 'A1', number: 1 },
+ { id: 'sea-a', title: 'A2', number: 1 },
+ { id: 'sea-a', title: 'A3', number: 1 },
+ ]);
+ expect(warnSpy).toHaveBeenCalledTimes(1);
+ const msg = warnSpy.mock.calls[0][0];
+ const matches = msg.match(/sea-a/g) || [];
+ expect(matches).toHaveLength(1);
+ expect(msg).toContain('2 duplicate');
+ expect(msg).toContain('1 colliding');
+ warnSpy.mockRestore();
});
it('caps at SEASONS_PER_SERIES_MAX', () => {