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
fix([med-sharing-server-services-sharing-version-js]): retry missing-universe manifests instead of advancing cursor
[._.]/ Adam Eivy7115f0a5fe25
diff --git a/server/services/sharing/importer.js b/server/services/sharing/importer.jsindex ed4025685b..f24ed3f511 100644--- a/server/services/sharing/importer.js+++ b/server/services/sharing/importer.js@@ -444,10 +444,12 @@ async function applyAutoMerge(bucket, manifest, records, { availableAssetKeys =// to a universe that isn't in this manifest and isn't local), skip the// sanitized-series insert for that record — otherwise the canon arrays// get silently stripped by `sanitizeSeries` and the bug we just fixed- // recurs. The bucket record stays untouched so the user can reimport- // after fixing the missing universe (or rerunning when transient I/O- // recovers).+ // recurs. The bucket record stays untouched and `legacyCanonPendingUniverses`+ // surfaces upward to the manifest-pending check, so the watcher retries+ // when the missing universe later arrives instead of cursor-advancing into+ // permanent skip.const skipSeriesMerge = new Set();+ const legacyCanonPendingUniverses = [];for (const s of records.series) {const hasLegacyCanon = ['characters', 'settings', 'places', 'objects'].some((field) => Array.isArray(s[field]) && s[field].length > 0);@@ -459,6 +461,9 @@ async function applyAutoMerge(bucket, manifest, records, { availableAssetKeys =if (!r || r.skipped === 'missing-universe') {console.log(`⚠️ sharing.importer: skipping series ${s.id} merge — legacy canon could not be salvaged (${r?.skipped || 'helper failed'})`);skipSeriesMerge.add(s.id);+ if (r?.skipped === 'missing-universe' && r.universeId) {+ legacyCanonPendingUniverses.push(r.universeId);+ }continue;}// Stamp the freshly-created orphan universe id onto the in-memory record@@ -531,6 +536,7 @@ async function applyAutoMerge(bucket, manifest, records, { availableAssetKeys =collectionItemsDeferred: itemsDeferred,collectionPendingUniverse,collectionPendingSeries,+ legacyCanonPendingUniverses: legacyCanonPendingUniverses.length > 0 ? legacyCanonPendingUniverses : null,adoptedSubscription: adoptedSubscription? { id: adoptedSubscription.id, bucketId: adoptedSubscription.bucketId, recordKind: adoptedSubscription.recordKind, recordId: adoptedSubscription.recordId }: null,@@ -743,13 +749,15 @@ export async function processManifest(bucketId, manifestFilename) {// `recordIds`.const collectionPendingUniverse = outcome?.collectionPendingUniverse || null;const collectionPendingSeries = outcome?.collectionPendingSeries || null;- if (assetCopy.missing.length > 0 || missingRecords.length > 0 || collectionPendingUniverse || collectionPendingSeries) {+ const legacyCanonPendingUniverses = outcome?.legacyCanonPendingUniverses || null;+ if (assetCopy.missing.length > 0 || missingRecords.length > 0 || collectionPendingUniverse || collectionPendingSeries || legacyCanonPendingUniverses) {if (assetCopy.missing.length > 0) outcome.pendingAssets = assetCopy.missing;if (missingRecords.length > 0) outcome.pendingRecords = missingRecords;if (collectionPendingUniverse) outcome.pendingCollectionUniverse = collectionPendingUniverse;if (collectionPendingSeries) outcome.pendingCollectionSeries = collectionPendingSeries;+ if (legacyCanonPendingUniverses) outcome.pendingLegacyCanonUniverses = legacyCanonPendingUniverses;sharingEvents.emit('manifest-processed', { bucketId, manifestId: manifest.id, manifestFilename, outcome });- console.log(`⏳ sharing: bucket=${bucket.name} manifest=${manifest.id} kind=${manifest.kind} mode=${bucket.mode} waitingForAssets=${assetCopy.missing.length} waitingForRecords=${missingRecords.length}${collectionPendingUniverse ? ` waitingForUniverse=${collectionPendingUniverse}` : ''}${collectionPendingSeries ? ` waitingForSeries=${collectionPendingSeries}` : ''}`);+ console.log(`⏳ sharing: bucket=${bucket.name} manifest=${manifest.id} kind=${manifest.kind} mode=${bucket.mode} waitingForAssets=${assetCopy.missing.length} waitingForRecords=${missingRecords.length}${collectionPendingUniverse ? ` waitingForUniverse=${collectionPendingUniverse}` : ''}${collectionPendingSeries ? ` waitingForSeries=${collectionPendingSeries}` : ''}${legacyCanonPendingUniverses ? ` waitingForLegacyCanonUniverses=${legacyCanonPendingUniverses.join(',')}` : ''}`);return { processed: true, pending: true, manifest, outcome };}await markProcessed(bucketId, manifestFilename, manifest.id);diff --git a/server/services/sharing/integration.test.js b/server/services/sharing/integration.test.jsindex a0d47a56db..9b70fdbab1 100644--- a/server/services/sharing/integration.test.js+++ b/server/services/sharing/integration.test.js@@ -1385,20 +1385,23 @@ describe('sharing round-trip', () => {expect(orphanUni.characters.map((c) => c.name)).toContain('Solo');});- it('skips the series merge when legacy canon cannot land (universeId points to a missing universe)', async () => {+ it('leaves the manifest pending and retries when the missing universe later arrives', async () => {// Without this guard, the importer would fall through to insertSeriesWithId// and `sanitizeSeries` would silently drop the legacy canon arrays — the- // exact bug this PR fixes. The bucket record stays untouched so the user- // can reimport after fixing the missing universe.+ // exact bug this PR fixes. The bucket record stays untouched and the+ // cursor stays un-advanced so the watcher retries when the missing+ // universe later shows up.+ const { hasBeenProcessed, readCursor } = await import('./manifest.js');const bucket = await buckets.createBucket({ name: 'MissingUniBucket', path: tempBucket, mode: 'auto-merge' });+ const missingUniverseId = 'uni-not-yet-bundled-123';const seriesId = 'ser-missing-uni';const legacySeries = {id: seriesId,name: 'Missing-Uni Series',logline: 'orphaned link',premise: 'links to a universe not in the bundle',- universeId: 'uni-does-not-exist-123',+ universeId: missingUniverseId,characters: [{ name: 'Ghost', physicalDescription: 'unseen' }],createdAt: '2026-05-01T00:00:00.000Z',updatedAt: '2026-05-01T00:00:00.000Z',@@ -1427,13 +1430,37 @@ describe('sharing round-trip', () => {const filename = `2026-05-01T00-00-00-000Z-missing-uni-peer-${manifest.id}.json`;writeFileSync(join(tempBucket, 'manifests', filename), JSON.stringify(manifest));- const result = await importer.processManifest(bucket.id, filename);- expect(result.processed).toBe(true);+ // First pass: universe is missing → manifest must stay pending, cursor not advanced, series not written.+ const first = await importer.processManifest(bucket.id, filename);+ expect(first.processed).toBe(true);+ expect(first.pending).toBe(true);+ expect(first.outcome.pendingLegacyCanonUniverses).toEqual([missingUniverseId]);+ let cursor = await readCursor(bucket.id);+ expect(hasBeenProcessed(cursor, filename, manifest.id)).toBe(false);+ const stillMissing = await series.getSeries(seriesId).catch(() => null);+ expect(stillMissing).toBeNull();++ // Local universe lands (peer re-shares it via a different channel, or+ // the user creates one with the matching id).+ await universeSvc.insertUniverseWithId({+ id: missingUniverseId,+ name: 'Late-Arriving Universe',+ starterPrompt: '',+ createdAt: '2026-05-01T00:00:00.000Z',+ updatedAt: '2026-05-01T00:00:00.000Z',+ });- // Series MUST NOT have been written — otherwise sanitizeSeries would have- // silently dropped the legacy canon arrays.- const restored = await series.getSeries(seriesId).catch(() => null);- expect(restored).toBeNull();+ // Retry: now the migration lands canon on the universe, the series imports.+ const second = await importer.processManifest(bucket.id, filename);+ expect(second.processed).toBe(true);+ expect(second.pending).toBeFalsy();+ cursor = await readCursor(bucket.id);+ expect(hasBeenProcessed(cursor, filename, manifest.id)).toBe(true);+ const restored = await series.getSeries(seriesId);+ expect(restored.id).toBe(seriesId);+ expect(restored.universeId).toBe(missingUniverseId);+ const restoredUni = await universeSvc.getUniverse(missingUniverseId);+ expect(restoredUni.characters.map((c) => c.name)).toContain('Ghost');});it('refuses a manifest with a sharingSchemaVersion newer than local + emits incompatible event', async () => {