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: preserve additive series fields across behind-sender sync merges (#1361)
Adam Eivy0f4efecefff5
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 9cebdf3cfb..1235171289 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -89,6 +89,8 @@## Fixed+- **[issue-1361] A behind/legacy sync peer can no longer erase a series' style guide, reader map, ticking clock, style notes, or seasons.** `mergeSeriesFromSync` applied an incoming series payload wholesale via last-writer-wins on `updatedAt`, and `sanitizeSeries` flattens an *absent* key to the same `null`/`[]`/`""` as an explicit clear. So when a peer that never authored a field (an older install, or one that predates the field) pushed a series with a newer `updatedAt` but no `styleGuide`/`arc`/`styleNotes`/`seasons` key — or sent `arc` without its newer `readerMap`/`tickingClock` sub-keys — the receiver overwrote and wiped the locally-authored value. The merge now consults the **raw** remote payload to tell "key absent" from "key present-but-empty": an absent key preserves the local value (mirroring the existing `universeId` hierarchy guard, and applied uniformly across the additive fields plus the additive sub-fields nested in `arc`), while an explicit `null`/empty from an up-to-date peer is still honored as an intentional clear. Tombstones are skipped (a deleted record carries no content to protect). (`server/services/pipeline/series.js`, #1361)+- **[issue-1359] A catalog image you generate now attaches even if you navigate away before it finishes.** When you used the catalog item editor's **Generate** button with a local or Codex image backend, the render is a queued job — and if you refreshed, switched to another item, or left the page before it completed, the finished image still landed in your media library but was never attached to the item, so it silently vanished from that item's Media panel. The attachment is now made server-side the moment the render completes, independent of whether that page is still open: the first image becomes the item's portrait, later ones attach as references — exactly as it would if you'd stayed on the page. (#1359)- **The Universes list row thumbnail now shows the universe's base style image, matching the detail page.** The `/universes` index thumbnail read the *latest* image from the universe's auto-managed media collection, which is often a contact sheet or character reference render — so a universe whose detail page proudly shows its subject-less "Base style" probe (e.g. the Neon Expanse cityscape) was previewed in the list as an unrelated grid of figures. The row thumbnail now prefers the universe's base style image (last entry in `styleImageRefs`, the same selection the Universe Builder's `StyleProbeImage` → `EntryThumbSlot` makes), falling back to the latest media-collection image, then the Globe placeholder — so the list and detail views agree. (`client/src/pages/Universes.jsx`)diff --git a/server/services/pipeline/series.js b/server/services/pipeline/series.jsindex ed33b8252c..059ed3795c 100644--- a/server/services/pipeline/series.js+++ b/server/services/pipeline/series.js@@ -619,6 +619,46 @@ async function cascadeDeleteSideEffects(id) {emitRecordDeleted('series', id);}+// Top-level additive content fields whose ABSENCE in a remote payload must not+// erase a locally-authored value. `sanitizeSeries` collapses an absent key to+// the same null/[]/'' as an explicit clear, so on the sync-merge path we+// consult the RAW remote payload to tell the two apart: key absent → preserve+// local; key present (even null/empty) → honor the intentional clear. Mirrors+// the `universeId` hierarchy guard. See issue #1361.+const ADDITIVE_SERIES_FIELDS = ['arc', 'seasons', 'styleGuide', 'styleNotes'];+// Additive sub-fields nested inside `arc`. A peer that predates these (readerMap+// shipped at schema v2, tickingClock at #1289/v3) still sends an `arc` object —+// just without these keys — so the erasure for them happens one level down.+const ADDITIVE_ARC_FIELDS = ['readerMap', 'tickingClock'];++const keyAbsent = (obj, key) => !obj || typeof obj !== 'object' || !(key in obj) || obj[key] === undefined;++/**+ * Re-inject locally-authored additive fields into a freshly-sanitized remote+ * record when the RAW remote payload omitted the key entirely. Mutates and+ * returns `sanitized`. Skips tombstones (a deleted record carries no content to+ * protect). Operates both at the top level and on the additive sub-fields nested+ * inside `arc`. An explicitly-present null/empty from an up-to-date peer is left+ * untouched so an intentional clear still applies. See issue #1361.+ */+export const preserveAbsentAdditiveFields = (sanitized, rawRemote, local) => {+ if (!sanitized || sanitized.deleted || !local || typeof local !== 'object') return sanitized;+ for (const field of ADDITIVE_SERIES_FIELDS) {+ if (keyAbsent(rawRemote, field)) sanitized[field] = local[field];+ }+ // Nested arc sub-fields: only when the remote DID send an `arc` object (so the+ // top-level preserve above didn't already restore the whole arc) and both the+ // sanitized result and the local record carry an arc object to merge into.+ if (!keyAbsent(rawRemote, 'arc')+ && sanitized.arc && typeof sanitized.arc === 'object'+ && local.arc && typeof local.arc === 'object') {+ for (const sub of ADDITIVE_ARC_FIELDS) {+ if (keyAbsent(rawRemote.arc, sub)) sanitized.arc[sub] = local.arc[sub];+ }+ }+ return sanitized;+};+/*** Sync-orchestrator entry point. Merges a remote peer's series array into* local state through per-record collection-store queues. Each incoming record@@ -673,6 +713,14 @@ export async function mergeSeriesFromSync(remoteSeries, { source = { via: 'sync'if (!sanitized.deleted && !sanitized.universeId && local.universeId) {sanitized.universeId = local.universeId;}+ // Additive content fields: a behind/legacy peer (or one that never+ // authored the field) pushes a newer payload that simply OMITS the+ // key. `sanitizeSeries` already flattened that absence to null/[]/'',+ // so re-inject the local value from the raw remote payload — otherwise+ // LWW silently erases styleGuide/readerMap/tickingClock/styleNotes/+ // seasons. An explicit null/empty from an up-to-date peer still+ // applies. See issue #1361.+ preserveAbsentAdditiveFields(sanitized, remote, local);// Non-blocking conflict journal — archive the losing local version on// a true 3-way divergence; always advances the base hash. Never throws.await maybeJournalBeforeOverwrite({ kind: 'series', id: sanitized.id, local, remote: sanitized, source });diff --git a/server/services/pipeline/series.test.js b/server/services/pipeline/series.test.jsindex bf0966bc0b..7c7d9fdc14 100644--- a/server/services/pipeline/series.test.js+++ b/server/services/pipeline/series.test.js@@ -515,4 +515,108 @@ describe('pipeline series service', () => {expect(s.arc).toBe(null);});});++ // Issue #1361 — a behind/legacy peer pushes a newer series payload that simply+ // OMITS an additive content field. sanitizeSeries flattens that absence to the+ // same null/[]/'' as a deliberate clear, so without the absent-vs-clear guard+ // LWW would erase the locally-authored value. An explicit null/empty from an+ // up-to-date peer must still apply as an intentional clear.+ describe('mergeSeriesFromSync — additive-field preservation (behind-sender)', () => {+ const NEWER = '2999-01-01T00:00:00.000Z';++ it('preserves styleNotes/styleGuide/seasons when the remote omits the keys', async () => {+ const s = await svc.createSeries({+ name: 'Additive',+ styleNotes: 'moebius linework',+ styleGuide: { tense: 'past', povPerson: 'first' },+ seasons: [{ number: 1, title: 'Season One' }],+ });+ expect(s.styleGuide).not.toBeNull();+ expect(s.seasons).toHaveLength(1);+ // Behind-sender payload — newer updatedAt, but no styleNotes/styleGuide/+ // seasons keys at all.+ const behind = { id: s.id, name: 'Additive (peer edit)', updatedAt: NEWER };+ const res = await svc.mergeSeriesFromSync([behind]);+ expect(res.applied).toBe(true);+ const after = await svc.getSeries(s.id);+ expect(after.name).toBe('Additive (peer edit)'); // remote edit applied+ expect(after.styleNotes).toBe('moebius linework'); // …additive fields kept+ expect(after.styleGuide.tense).toBe('past');+ expect(after.seasons).toHaveLength(1);+ expect(after.seasons[0].title).toBe('Season One');+ });++ it('preserves arc (incl. readerMap + tickingClock) when the remote omits arc', async () => {+ const s = await svc.createSeries({+ name: 'ArcKeep',+ arc: {+ logline: 'spine',+ readerMap: { hooks: [{ label: 'who?' }] },+ tickingClock: { enabled: true, label: 'the eclipse' },+ },+ });+ expect(s.arc.readerMap.hooks).toHaveLength(1);+ expect(s.arc.tickingClock.enabled).toBe(true);+ const behind = { id: s.id, name: 'ArcKeep (peer edit)', updatedAt: NEWER };+ await svc.mergeSeriesFromSync([behind]);+ const after = await svc.getSeries(s.id);+ expect(after.arc).not.toBeNull();+ expect(after.arc.logline).toBe('spine');+ expect(after.arc.readerMap.hooks[0].label).toBe('who?');+ expect(after.arc.tickingClock.label).toBe('the eclipse');+ });++ it('preserves nested readerMap/tickingClock when the remote sends arc but omits those sub-keys (legacy peer)', async () => {+ const s = await svc.createSeries({+ name: 'NestedKeep',+ arc: {+ logline: 'old spine',+ readerMap: { hooks: [{ label: 'mystery' }] },+ tickingClock: { enabled: true, label: 'countdown' },+ },+ });+ // Legacy peer predates readerMap/tickingClock: it still authors `arc`, just+ // without those sub-fields. The new arc.logline applies; the sub-fields are+ // preserved.+ const behind = { id: s.id, name: 'NestedKeep', arc: { logline: 'new spine' }, updatedAt: NEWER };+ await svc.mergeSeriesFromSync([behind]);+ const after = await svc.getSeries(s.id);+ expect(after.arc.logline).toBe('new spine'); // remote arc edit applied+ expect(after.arc.readerMap.hooks[0].label).toBe('mystery'); // sub-fields kept+ expect(after.arc.tickingClock.label).toBe('countdown');+ });++ it('applies an explicit null/empty clear from an up-to-date peer (present key wins)', async () => {+ const s = await svc.createSeries({+ name: 'ClearMe',+ styleNotes: 'to be cleared',+ styleGuide: { tense: 'past' },+ arc: { logline: 'spine', readerMap: { hooks: [{ label: 'keep?' }] } },+ });+ // Up-to-date peer intentionally clears: keys present, values empty/null.+ const clear = {+ id: s.id,+ name: 'ClearMe',+ styleNotes: '',+ styleGuide: null,+ arc: { logline: 'spine', readerMap: null },+ updatedAt: NEWER,+ };+ await svc.mergeSeriesFromSync([clear]);+ const after = await svc.getSeries(s.id);+ expect(after.styleNotes).toBe(''); // intentional clear honored+ expect(after.styleGuide).toBeNull();+ expect(after.arc.readerMap).toBeNull(); // nested intentional clear honored+ expect(after.arc.logline).toBe('spine');+ });++ it('does not resurrect content onto an inbound tombstone', async () => {+ const s = await svc.createSeries({ name: 'Doomed', styleNotes: 'doomed notes' });+ const tombstone = { id: s.id, name: 'Doomed', deleted: true, deletedAt: NEWER, updatedAt: NEWER };+ await svc.mergeSeriesFromSync([tombstone]);+ const after = await svc.getSeries(s.id, { includeDeleted: true });+ expect(after.deleted).toBe(true);+ expect(after.styleNotes).toBe(''); // tombstone stays clean, no resurrection+ });+ });});