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([issue-729]): preserve local styleImageRefs on remote-wins sync merge

[._.]/ Adam Eivy51a6c0868097
diff --git a/server/services/universeBuilder.js b/server/services/universeBuilder.js
index 2ece683dc8..849c569fae 100644
--- a/server/services/universeBuilder.js
+++ b/server/services/universeBuilder.js
@@ -1507,6 +1507,15 @@ export async function mergeUniversesFromSync(remoteUniverses, { source = { via:
const localTs = local.updatedAt || '';
const remoteTs = sanitized.updatedAt || '';
if (remoteTs > localTs) {
+ // `styleImageRefs` is WIRE-LOCAL — sanitizeRecordForWire strips it, so an
+ // inbound payload never carries it and sanitizeTemplate defaulted it to []
+ // above. The local value is authoritative for THIS peer's probe renders;
+ // without restoring it, this remote-wins LWW write would clobber the local
+ // refs to []. Preserve it onto the sanitized record before it's journaled
+ // or written (the conflict hash excludes the field, so this restore can't
+ // shift the journal's divergence verdict). Mirror of the ephemeral
+ // local-only contract above.
+ sanitized.styleImageRefs = local.styleImageRefs ?? [];
// Non-blocking conflict journal: archive the about-to-be-lost local
// version when BOTH sides diverged from the last synced base. Always
// advances the base hash (clean or conflict) so the next snapshot
diff --git a/server/services/universeBuilder.test.js b/server/services/universeBuilder.test.js
index 740def4270..d33a6861cb 100644
--- a/server/services/universeBuilder.test.js
+++ b/server/services/universeBuilder.test.js
@@ -908,6 +908,32 @@ describe("universeBuilder service", () => {
// Receiver scrubs the field — record is normal-syncable.
expect(inbound.ephemeral).toBeUndefined();
});
+
+ it("preserves local styleImageRefs across a remote-wins LWW edit (wire-local probe renders)", async () => {
+ // styleImageRefs is stripped from the wire, so an inbound payload never
+ // carries it. Without the receive-side restore, sanitizeTemplate would
+ // default the missing field to [] and a remote-wins LWW write would
+ // clobber this peer's locally-rendered probe images. The local value
+ // is authoritative — a peer's edit to OTHER fields must not wipe it.
+ const w = await seedWorld();
+ await svc.updateUniverse(w.id, { styleImageRefs: ["probe-1.png", "probe-2.png"] });
+ const localBefore = await svc.getUniverse(w.id);
+ expect(localBefore.styleImageRefs).toEqual(["probe-1.png", "probe-2.png"]);
+ // Inbound edit (newer updatedAt, no styleImageRefs — wire-stripped) wins LWW.
+ const editTs = new Date(Date.now() + 60_000).toISOString();
+ const r = await svc.mergeUniversesFromSync([{
+ ...w,
+ name: "Remote Edited Name",
+ styleImageRefs: undefined, // mirror the wire form (field absent)
+ updatedAt: editTs,
+ }]);
+ expect(r.applied).toBe(true);
+ const after = await svc.getUniverse(w.id);
+ // Remote name landed…
+ expect(after.name).toBe("Remote Edited Name");
+ // …but local probe renders survived.
+ expect(after.styleImageRefs).toEqual(["probe-1.png", "probe-2.png"]);
+ });
});
describe("pruneTombstonedUniverses", () => {