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: guard fileCoverIntoSeriesCollection against linked series

[._.]/ Adam Eivy719f48797d57
diff --git a/server/services/pipeline/coverUniverseFiler.js b/server/services/pipeline/coverUniverseFiler.js
index 5bee44c18c..b4763a42f4 100644
--- a/server/services/pipeline/coverUniverseFiler.js
+++ b/server/services/pipeline/coverUniverseFiler.js
@@ -129,6 +129,18 @@ export async function fileCoverIntoSeriesCollection({ seriesId, filename }) {
const liveSeries = await seriesSvc.getSeries(seriesId).catch(() => null);
if (!liveSeries) return;
+ // Re-route if the series has (gained) a universe link. Two ways this matters:
+ // (a) this helper is exported and a direct caller may invoke it for an
+ // already-linked series — without the guard we'd stamp a per-series bucket
+ // even though linked series are supposed to use the universe collection;
+ // (b) when called via the dispatcher, `updateSeries` could land a universe
+ // link between the dispatcher's branch and this fetch. Either way, defer
+ // to the universe path so all linked series share one universe collection.
+ if (liveSeries.universeId) {
+ await fileCoverIntoUniverseCollection({ seriesId, filename });
+ return;
+ }
+
const collection = await findOrCreateSeriesCollection({
seriesId: liveSeries.id,
seriesName: liveSeries.name,
diff --git a/server/services/pipeline/coverUniverseFiler.test.js b/server/services/pipeline/coverUniverseFiler.test.js
index d54c913728..0ff8c14237 100644
--- a/server/services/pipeline/coverUniverseFiler.test.js
+++ b/server/services/pipeline/coverUniverseFiler.test.js
@@ -153,6 +153,22 @@ describe('fileCoverIntoSeriesCollection', () => {
expect(await collections.listCollections()).toEqual([]);
});
+ it('re-routes to the universe collection when the series is universe-linked', async () => {
+ // Guard against (a) a direct caller invoking this helper for an
+ // already-linked series and (b) a parallel `updateSeries` adding a
+ // universe link between the dispatcher's branch and this fetch. Either
+ // way the cover must land in the universe collection, not a per-series
+ // bucket that contradicts the canon link.
+ const universe = await universeSvc.createUniverse({ name: 'Linked' });
+ const series = await seriesSvc.createSeries({ name: 'Bound', universeId: universe.id });
+ await fileCoverIntoSeriesCollection({ seriesId: series.id, filename: 'rerouted.png' });
+ expect(await collections.findCollectionBySeriesId(series.id)).toBeNull();
+ expect(await collections.findCollectionByUniverseId(universe.id)).toMatchObject({
+ name: 'Universe: Linked',
+ items: [expect.objectContaining({ ref: 'rerouted.png' })],
+ });
+ });
+
it('serializes concurrent filings for the same series', async () => {
const series = await seriesSvc.createSeries({ name: 'RaceSeries' });
await Promise.all([