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([issue-851]): only promote draft parent for a syncing (non-ephemeral) child
[._.]/ Adam Eivy94b0f8f0ee0e
diff --git a/server/services/importer.test.js b/server/services/importer.test.jsindex 58ab166663..e9fd41e0ee 100644--- a/server/services/importer.test.js+++ b/server/services/importer.test.js@@ -1751,7 +1751,7 @@ describe('reconcile draft parent universe (issue #851)', () => {expect(after.importDraft).not.toBe(true);});- it('leaves a non-draft universe untouched (no spurious write) when a committed series links to it', async () => {+ it('leaves a non-draft universe untouched when a committed series links to it', async () => {const normalUni = await universeSvc.createUniverse({ name: 'Normal' });const realUni = await universeSvc.createUniverse({ name: 'Origin' });const series = await seriesSvc.createSeries({ name: 'Moving Series', universeId: realUni.id });@@ -1762,4 +1762,23 @@ describe('reconcile draft parent universe (issue #851)', () => {expect(after.importDraft).not.toBe(true);expect(after.ephemeral).not.toBe(true);});++ it('does NOT promote a draft universe when an EPHEMERAL (private, non-draft) series is linked', async () => {+ // An ephemeral series is the user signaling "keep this local" — it carries+ // no syncing work, so promoting (un-privatizing) its parent would push+ // peers a universe whose only child never syncs. Only a series that itself+ // reaches peers should pull its draft parent into sync.+ const draftUni = await universeSvc.createUniverse({+ name: 'Draft Parent 3', ephemeral: true, importDraft: true,+ });+ const privateSeries = await seriesSvc.createSeries({+ name: 'Private Committed', universeId: draftUni.id, ephemeral: true,+ });+ expect(privateSeries.importDraft).not.toBe(true);+ expect(privateSeries.ephemeral).toBe(true);++ const after = await universeSvc.getUniverse(draftUni.id);+ expect(after.importDraft).toBe(true);+ expect(after.ephemeral).toBe(true);+ });});diff --git a/server/services/pipeline/series.js b/server/services/pipeline/series.jsindex b94b3ec081..10ac9361be 100644--- a/server/services/pipeline/series.js+++ b/server/services/pipeline/series.js@@ -243,13 +243,11 @@ export async function createSeries(input = {}) {console.log(`⚠️ series: auto-subscribe after create failed: ${err.message}`);});}- // Reconcile a draft parent universe (issue #851) when a committed (non-draft)- // series is created already linked to it — the create-time twin of the- // updateSeries link path. Gated on `importDraft !== true` so analyzeImport's- // own draft-shell series (created WITH importDraft) never promotes its draft- // universe here; commitImport owns that promotion. See- // reconcileDraftParentUniverse for the contract.- if (created.universeId && created.importDraft !== true) {+ // Reconcile a draft parent universe (issue #851) when a committed (non-draft,+ // non-ephemeral) series is created already linked to it — the create-time+ // twin of the updateSeries link path. See reconcileDraftParentUniverse and+ // `isPromotingChild` for the gating contract.+ if (created.universeId && isPromotingChild(created)) {await reconcileDraftParentUniverse(created.universeId);}return created;@@ -298,16 +296,30 @@ export async function insertSeriesWithId(input = {}) {return next;}+/**+ * Whether linking `series` to a parent universe should promote a draft parent+ * (issue #851). True only for a series that is BOTH non-draft AND non-ephemeral:+ *+ * - `importDraft !== true` — an import-draft series linked to a draft universe+ * must NOT promote it; that's commitImport's job.+ * - `ephemeral !== true` — a deliberately-private (kept-local) series carries+ * no syncing work, so promoting (and thereby un-privatizing) its parent+ * would push peers a universe whose only child never syncs. Only a series+ * that itself reaches peers should pull its draft parent into sync.+ */+const isPromotingChild = (series) => series?.importDraft !== true && series?.ephemeral !== true;+/*** Promote an import-draft universe to a normal, syncing record when a- * committed (non-draft) series gets linked to it outside the commitImport- * path (issue #851). Mirrors commitImport's promotion: clears BOTH+ * committed (non-draft, non-ephemeral) series gets linked to it outside the+ * commitImport path (issue #851). Mirrors commitImport's promotion: clears BOTH* `importDraft` and `ephemeral` through `updateUniverse` so the* ephemeral→non-ephemeral peer re-subscribe wiring fires.*- * Gated STRICTLY on `importDraft === true` — a user's deliberately-private- * (`ephemeral`-only) universe must never be un-privatized as a side effect- * of linking a series, exactly as commitImport gates its own promotion.+ * Gated STRICTLY on the parent's `importDraft === true` — a user's+ * deliberately-private (`ephemeral`-only) universe must never be un-privatized+ * as a side effect of linking a series, exactly as commitImport gates its own+ * promotion. (Caller gates the child via `isPromotingChild`.)** Best-effort: runs outside any write queue and swallows + logs failures so a* universe-side error never fails the series link that triggered it. The@@ -385,11 +397,9 @@ export async function updateSeries(id, patch = {}) {if (!next) throw makeErr('Invalid series payload', ERR_VALIDATION);await store().saveOneNow(next.id, next);// Surface the universe this series ends up linked to ONLY when (a) this- // PATCH set/changed the link and (b) the series itself is NOT an import- // draft (committed work). The post-queue side effect reconciles a draft- // parent universe (issue #851) — see below. Gating on `importDraft !==- // true` is the load-bearing rule: an import-draft series linked to a- // draft universe must NOT promote it (that's commitImport's job).+ // PATCH set/changed the link and (b) the series itself qualifies to promote+ // its parent (committed AND syncing — see isPromotingChild). The post-queue+ // side effect reconciles a draft parent universe (issue #851) — see below.const linkChanged = 'universeId' in patch && next.universeId && next.universeId !== cur.universeId;return {merged: next,@@ -398,7 +408,7 @@ export async function updateSeries(id, patch = {}) {// side effects can wire subscribe / unsubscribe.prevEphemeral: cur.ephemeral === true,nextEphemeral: next.ephemeral === true,- linkedUniverseId: (linkChanged && next.importDraft !== true) ? next.universeId : null,+ linkedUniverseId: (linkChanged && isPromotingChild(next)) ? next.universeId : null,};});// Ephemeral lifecycle wiring — see updateUniverse for the rationale. false→true