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-2]): tighten buildSeasonRemap Pass 3 to forced 1↔1 pairings

[._.]/ Adam Eivy02b4ceca6727
diff --git a/server/services/pipeline/arcPlanner.js b/server/services/pipeline/arcPlanner.js
index 84c7a60e88..2adb8f3aa3 100644
--- a/server/services/pipeline/arcPlanner.js
+++ b/server/services/pipeline/arcPlanner.js
@@ -1103,7 +1103,12 @@ export async function commitSeasonsWithRemap(currentSeries, { arc, seasons }) {
// and the freshly-minted ones in the same resolve. Matching priority:
// 1. normalized title equality (LLM was told to preserve titles when it can)
// 2. `number` equality (only when the target number is unique among new ones)
-// 3. positional fallback (only when counts match and ordering aligns)
+// 3. positional fallback — only fires when exactly ONE unmatched on each
+// side. With a single pair the mapping is forced and unambiguous; with
+// 2+ unmatched the LLM may have reshuffled/renamed everything and
+// positional guessing silently invents wrong mappings (the bug that
+// motivated this guard). Skipped runs log a warning and let those
+// orphans fall through to the ungrouped bucket below.
// Anything that can't be matched maps to null so the issue lands in the
// ungrouped bucket instead of staying stranded behind a defunct id.
export function buildSeasonRemap(droppedOldSeasons, newlyMintedSeasons) {
@@ -1137,20 +1142,20 @@ export function buildSeasonRemap(droppedOldSeasons, newlyMintedSeasons) {
}
}
- // Pass 3: positional fallback when the unclaimed sets line up 1:1
+ // Pass 3: positional fallback — only when the unmatched sets are exactly
+ // 1↔1, where the pairing is forced.
const oldRemaining = droppedOldSeasons.filter((s) => !remap.has(s.id));
const newRemaining = newlyMintedSeasons.filter((n) => !claimed.has(n.id));
- if (oldRemaining.length && oldRemaining.length === newRemaining.length) {
- const oldSorted = [...oldRemaining].sort(
- (a, b) => (a.number ?? 0) - (b.number ?? 0),
+ if (oldRemaining.length === 1 && newRemaining.length === 1) {
+ console.warn(
+ `⚠️ buildSeasonRemap Pass 3 fired: forced 1↔1 pairing "${oldRemaining[0].title || oldRemaining[0].id}" → "${newRemaining[0].title || newRemaining[0].id}"`,
);
- const newSorted = [...newRemaining].sort(
- (a, b) => (a.number ?? 0) - (b.number ?? 0),
+ remap.set(oldRemaining[0].id, newRemaining[0].id);
+ claimed.add(newRemaining[0].id);
+ } else if (oldRemaining.length && newRemaining.length) {
+ console.warn(
+ `⚠️ buildSeasonRemap skipped positional fallback (${oldRemaining.length} old × ${newRemaining.length} new unmatched) — orphan issues route to ungrouped`,
);
- for (let i = 0; i < oldSorted.length; i += 1) {
- remap.set(oldSorted[i].id, newSorted[i].id);
- claimed.add(newSorted[i].id);
- }
}
// Anything still unmapped → null (ungrouped bucket).
diff --git a/server/services/pipeline/arcPlanner.test.js b/server/services/pipeline/arcPlanner.test.js
index ec4cc6f1a1..c1a0108a18 100644
--- a/server/services/pipeline/arcPlanner.test.js
+++ b/server/services/pipeline/arcPlanner.test.js
@@ -1034,18 +1034,38 @@ describe('arcPlanner — buildSeasonRemap', () => {
expect(remap.get('old1')).toBe('new2');
});
- it('falls back positionally when counts match and unique-number is ambiguous', () => {
+ it('falls back positionally when exactly one unmatched on each side (forced 1↔1)', () => {
+ const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
+ const dropped = [{ id: 'old1', number: 1, title: 'A' }];
+ const minted = [{ id: 'new1', number: 2, title: 'X' }];
+ const remap = planner.buildSeasonRemap(dropped, minted);
+ expect(remap.get('old1')).toBe('new1');
+ expect(warnSpy).toHaveBeenCalledWith(
+ expect.stringContaining('Pass 3 fired'),
+ );
+ warnSpy.mockRestore();
+ });
+
+ it('drops orphans to null when 2+ unmatched on each side after pass 1/2', () => {
+ const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
+ // Titles diverge AND numbers diverge → Pass 1 (title) and Pass 2 (unique
+ // number) leave 2-old × 2-new unmatched. Old behavior would positionally
+ // pair them; new behavior refuses and warns.
const dropped = [
- { id: 'old1', number: 1, title: 'A' },
- { id: 'old2', number: 2, title: 'B' },
+ { id: 'old1', number: 10, title: 'A' },
+ { id: 'old2', number: 20, title: 'B' },
];
const minted = [
{ id: 'new1', number: 1, title: 'X' },
{ id: 'new2', number: 2, title: 'Y' },
];
const remap = planner.buildSeasonRemap(dropped, minted);
- expect(remap.get('old1')).toBe('new1');
- expect(remap.get('old2')).toBe('new2');
+ expect(remap.get('old1')).toBeNull();
+ expect(remap.get('old2')).toBeNull();
+ expect(warnSpy).toHaveBeenCalledWith(
+ expect.stringContaining('skipped positional fallback'),
+ );
+ warnSpy.mockRestore();
});
it('maps to null when nothing plausible exists', () => {