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-sharing-server-services-sharing-version-js]): skip series merge when legacy canon can't be salvaged

[._.]/ Adam Eivy7c7df51a1564
diff --git a/server/services/sharing/importer.js b/server/services/sharing/importer.js
index 5b4a74e326..ed4025685b 100644
--- a/server/services/sharing/importer.js
+++ b/server/services/sharing/importer.js
@@ -439,6 +439,15 @@ async function applyAutoMerge(bucket, manifest, records, { availableAssetKeys =
// sanitized series. Both `settings` (pre-022) and `places` (post-022) wire
// names are recognized; the helper coalesces them. No-op for post-B.4
// records (the helper returns 'no-legacy' immediately).
+ //
+ // If the migration can't land the canon (helper threw, OR the peer linked
+ // 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).
+ const skipSeriesMerge = new Set();
for (const s of records.series) {
const hasLegacyCanon = ['characters', 'settings', 'places', 'objects']
.some((field) => Array.isArray(s[field]) && s[field].length > 0);
@@ -447,16 +456,22 @@ async function applyAutoMerge(bucket, manifest, records, { availableAssetKeys =
console.log(`⚠️ sharing.importer: legacy series canon migration for ${s.id} failed: ${err.message}`);
return null;
});
+ 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);
+ continue;
+ }
// Stamp the freshly-created orphan universe id onto the in-memory record
// so the upcoming insertSeriesWithId call preserves the link. (We can't
// call updateSeries here like the CLI batch does — the series record
// hasn't been inserted yet.)
- if (r?.universeCreated && r.universeId) {
+ if (r.universeCreated && r.universeId) {
s.universeId = r.universeId;
}
}
for (const s of records.series) {
+ if (skipSeriesMerge.has(s.id)) continue;
await mergeOne({
kind: 'series', record: s, label: s.name,
getFn: getSeries, insertFn: insertSeriesWithId, updateFn: updateSeries,
diff --git a/server/services/sharing/integration.test.js b/server/services/sharing/integration.test.js
index 27c5d19b97..a0d47a56db 100644
--- a/server/services/sharing/integration.test.js
+++ b/server/services/sharing/integration.test.js
@@ -1385,6 +1385,57 @@ 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 () => {
+ // 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.
+ const bucket = await buckets.createBucket({ name: 'MissingUniBucket', path: tempBucket, mode: 'auto-merge' });
+
+ 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',
+ characters: [{ name: 'Ghost', physicalDescription: 'unseen' }],
+ createdAt: '2026-05-01T00:00:00.000Z',
+ updatedAt: '2026-05-01T00:00:00.000Z',
+ };
+ mkdirSync(join(tempBucket, 'records', 'series'), { recursive: true });
+ writeFileSync(
+ join(tempBucket, 'records', 'series', `${seriesId}.json`),
+ JSON.stringify(legacySeries),
+ );
+ const manifest = {
+ id: 'mfst-missing-uni',
+ schemaVersion: 1,
+ sharingSchemaVersion: 1,
+ producedByVersion: '1.0.0',
+ createdAt: new Date().toISOString(),
+ kind: 'series',
+ senderInstanceId: 'missing-uni-peer',
+ source: 'Missing Uni Peer',
+ sourceBio: null,
+ bucketId: bucket.id,
+ bucketName: bucket.name,
+ recordIds: [seriesId],
+ assetRefs: [],
+ note: null,
+ };
+ 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);
+
+ // 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();
+ });
+
it('refuses a manifest with a sharingSchemaVersion newer than local + emits incompatible event', async () => {
const { SHARING_SCHEMA_VERSION } = await import('./version.js');
const { sharingEvents } = await import('./importer.js');