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): surface universe-not-found as 404 and don't swallow listSeries failures
[._.]/ Adam Eivy2b48e805fbff
diff --git a/server/services/pipeline/seriesGenerate.js b/server/services/pipeline/seriesGenerate.jsindex f2564fbffe..0657a53d1a 100644--- a/server/services/pipeline/seriesGenerate.js+++ b/server/services/pipeline/seriesGenerate.js@@ -15,7 +15,7 @@* surfaces a uniform "try again" toast.*/-import { getUniverse, joinInfluenceList } from '../universeBuilder.js';+import { getUniverse, joinInfluenceList, ERR_NOT_FOUND as UNIVERSE_ERR_NOT_FOUND } from '../universeBuilder.js';import { listSeries, NAME_MAX, LOGLINE_MAX, PREMISE_MAX } from './series.js';import { ARC_SHAPES, ARC_SHAPE_IDS } from '../../lib/storyArc.js';import { runPromptRefineRaw } from './refineHelpers.js';@@ -76,8 +76,23 @@ function buildContext(universe, existingSeries) {}export async function generateSeriesConcept(universeId, options = {}) {- const universe = await getUniverse(universeId);- const all = await listSeries().catch(() => []);+ // getUniverse throws the universe service's generic NOT_FOUND code, which the+ // pipeline route's mapServiceError doesn't translate — leaving a stale/deleted+ // universeId to surface as a 500. Translate it here to a proper 404 so bad+ // user input reads as bad input, not a server fault.+ const universe = await getUniverse(universeId).catch((err) => {+ if (err?.code === UNIVERSE_ERR_NOT_FOUND) {+ throw new ServerError(`Universe not found: ${universeId} — pick an existing universe.`, {+ status: 404, code: 'PIPELINE_SERIES_CONCEPT_UNIVERSE_NOT_FOUND',+ });+ }+ throw err;+ });+ // Let a storage failure propagate (→ 500) rather than swallowing it: a+ // silently-empty list would feed the model a "no existing series" brief for a+ // universe that actually has some, weakening duplicate-avoidance while still+ // reporting success.+ const all = await listSeries();const existingSeries = all.filter((s) => s.universeId === universeId);const emptyError = {code: 'PIPELINE_SERIES_CONCEPT_EMPTY',diff --git a/server/services/pipeline/seriesGenerate.test.js b/server/services/pipeline/seriesGenerate.test.jsindex 9aad8814f0..bae931c21c 100644--- a/server/services/pipeline/seriesGenerate.test.js+++ b/server/services/pipeline/seriesGenerate.test.js@@ -7,6 +7,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';vi.mock('../universeBuilder.js', () => ({getUniverse: vi.fn(),joinInfluenceList: (a) => (Array.isArray(a) ? a.filter(Boolean).join(', ') : ''),+ ERR_NOT_FOUND: 'NOT_FOUND',}));vi.mock('./series.js', async (importOriginal) => {const actual = await importOriginal();@@ -102,6 +103,23 @@ describe('generateSeriesConcept', () => {});});+ it('maps a missing universe to a 404 (not a 500)', async () => {+ getUniverse.mockRejectedValue(Object.assign(new Error('Universe not found: uni-x'), { code: 'NOT_FOUND' }));+ await expect(generateSeriesConcept('uni-x')).rejects.toMatchObject({+ status: 404,+ code: 'PIPELINE_SERIES_CONCEPT_UNIVERSE_NOT_FOUND',+ });+ // The LLM must never be invoked when the seed universe is missing.+ expect(runPromptRefineRaw).not.toHaveBeenCalled();+ });++ it('propagates a listSeries storage failure instead of swallowing it', async () => {+ listSeries.mockRejectedValue(new Error('db unavailable'));+ await expect(generateSeriesConcept('uni-1')).rejects.toThrow('db unavailable');+ // No generation off an incomplete duplicate-avoidance brief.+ expect(runPromptRefineRaw).not.toHaveBeenCalled();+ });+it('passes the universe and existing-series context into the prompt', async () => {listSeries.mockResolvedValue([{ id: 'ser-a', universeId: 'uni-1', name: 'First Tale', logline: 'an old story' },