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: require a string owner link before the migration calls a collection auto-created (#3311)

[._.]/ Adam Eivy06b609bf1e91
diff --git a/scripts/migrations/220-backfill-media-collection-source.js b/scripts/migrations/220-backfill-media-collection-source.js
index ba6044da8f..905ff1d246 100644
--- a/scripts/migrations/220-backfill-media-collection-source.js
+++ b/scripts/migrations/220-backfill-media-collection-source.js
@@ -76,6 +76,8 @@ import { join } from 'path';
const AUTO_DESCRIPTION_PREFIXES = ['Auto-created for project ', 'Auto-generated images for '];
const AUTO_ID_PREFIXES = ['uc-', 'sc-'];
+const isNonEmptyString = (v) => typeof v === 'string' && v !== '';
+
/**
* True when a record carries a marker of machine creation that a user could not
* have produced through the create form. A subset of `isAutoCollection` in
@@ -89,7 +91,11 @@ export function isAutoCreated(record) {
if (!record || typeof record !== 'object') return false;
if (typeof record.description === 'string' && AUTO_DESCRIPTION_PREFIXES.some((p) => record.description.startsWith(p))) return true;
if (typeof record.id === 'string' && AUTO_ID_PREFIXES.some((p) => record.id.startsWith(p))) return true;
- return Boolean(record.universeId || record.seriesId);
+ // Owner link must be a non-empty STRING, matching `sanitizeCollection` — this
+ // reads raw disk, where the client only ever sees sanitized records. A
+ // hand-edited/corrupt `universeId: true` is dropped to null on the next read,
+ // so treating it as a machine-owned marker would stamp a record that has none.
+ return isNonEmptyString(record.universeId) || isNonEmptyString(record.seriesId);
}
/**
diff --git a/scripts/migrations/220-backfill-media-collection-source.test.js b/scripts/migrations/220-backfill-media-collection-source.test.js
index 63f06becc3..b480efc1f3 100644
--- a/scripts/migrations/220-backfill-media-collection-source.test.js
+++ b/scripts/migrations/220-backfill-media-collection-source.test.js
@@ -107,6 +107,11 @@ describe('migration 220 — backfill media collection source', () => {
// The same record with a marker the create form cannot produce does qualify.
expect(isAutoCreated({ id: 'x', name: 'Universe: Example', universeId: 'u1' })).toBe(true);
expect(isAutoCreated({ id: 'x', description: 'Auto-created for project x' })).toBe(true);
+ // A corrupt owner link is not a marker — `sanitizeCollection` drops a
+ // non-string universeId/seriesId on the next read, so stamping from one
+ // would classify a record that has no machine-owned marker at all.
+ expect(isAutoCreated({ id: 'x', universeId: true })).toBe(false);
+ expect(isAutoCreated({ id: 'x', seriesId: '' })).toBe(false);
expect(isAutoCreated(null)).toBe(false);
expect(stampAutoSource('nope')).toBe(null);
});
diff --git a/server/services/mediaCollections.test.js b/server/services/mediaCollections.test.js
index f745f6ad67..990b412031 100644
--- a/server/services/mediaCollections.test.js
+++ b/server/services/mediaCollections.test.js
@@ -1818,14 +1818,21 @@ describe('source provenance', () => {
// because the field never reaches a peer, fixing it must not bump
// `updatedAt` — that would out-race a peer's real edit for a change no peer
// can even see.
- const c = await svc.createCollection({ name: 'Renders', source: 'auto' });
- const fixed = await svc.updateCollection(c.id, { source: 'user' });
+ const seeded = '2026-05-22T00:00:00Z';
+ await seedState({
+ collections: [{
+ id: 'c-fix', name: 'Renders', description: '', coverKey: null,
+ universeId: null, seriesId: null, source: 'auto', items: [],
+ createdAt: seeded, updatedAt: seeded,
+ }],
+ });
+ const fixed = await svc.updateCollection('c-fix', { source: 'user' });
expect(fixed.source).toBe('user');
- expect(fixed.updatedAt).toBe(c.updatedAt);
+ expect(fixed.updatedAt).toBe(seeded);
// A patch that DOES touch wire-visible state still bumps it.
- const renamed = await svc.updateCollection(c.id, { name: 'Renders 2', source: 'auto' });
+ const renamed = await svc.updateCollection('c-fix', { name: 'Renders 2', source: 'auto' });
expect(renamed.source).toBe('auto');
- expect(renamed.updatedAt).not.toBe(c.updatedAt);
+ expect(renamed.updatedAt).not.toBe(seeded);
});
it('survives an edit and rides through the tombstone', async () => {