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
address review: cascade ephemeral protection to children + collections
Adam Eivy539ddf99cd74
diff --git a/server/lib/syncWire.js b/server/lib/syncWire.jsindex ae4930675d..7c346a3180 100644--- a/server/lib/syncWire.js+++ b/server/lib/syncWire.js@@ -131,8 +131,21 @@ export function sanitizeStateForWire(kind, state) {.map((s) => sanitizeRecordForWire('series', s)).filter(Boolean): [];+ // Cascade ephemeral protection from series to their child issues.+ // `updateSeries` doesn't auto-flip every child issue's `ephemeral` flag+ // when the parent is marked ephemeral, so an unfiltered issues array+ // would leak private issue stages (prose, comic pages, render+ // metadata) even though the parent series itself is filtered out.+ // Build the set of locally-ephemeral series ids by inspecting the+ // raw state.series (NOT the sanitized array — `sanitizeRecordForWire`+ // strips the ephemeral flag on the way out so it can't be used as+ // the gate).+ const ephemeralSeriesIds = Array.isArray(state.series)+ ? new Set(state.series.filter((s) => s?.ephemeral === true).map((s) => s.id))+ : new Set();const issues = Array.isArray(state.issues)? state.issues+ .filter((i) => !ephemeralSeriesIds.has(i?.seriesId)).map((i) => sanitizeRecordForWire('issue', i)).filter(Boolean): [];diff --git a/server/services/dataSync.js b/server/services/dataSync.jsindex 1d20ef944f..ceab41f1d5 100644--- a/server/services/dataSync.js+++ b/server/services/dataSync.js@@ -476,11 +476,33 @@ async function getMediaCollectionsSnapshot() {async function applyMediaCollectionsRemote(remoteData) {if (!remoteData) return { applied: false, count: 0 };+ // Symmetric receiver-side guard. The sender filters collections linked+ // to local-ephemeral parents in getMediaCollectionsSnapshot, but a+ // peer running an older PortOS (or any non-conformant client) could+ // still ship them. Without this filter, an incoming snapshot could+ // mutate item refs or scalars on a collection whose universe/series+ // the user explicitly marked private.+ const incoming = Array.isArray(remoteData.collections) ? remoteData.collections : [];+ const ephemeralUniverseIds = new Set(+ (await listUniverses({ includeDeleted: true }).catch(() => []))+ .filter((u) => u?.ephemeral === true)+ .map((u) => u.id),+ );+ const ephemeralSeriesIds = new Set(+ (await listSeries({ includeDeleted: true }).catch(() => []))+ .filter((s) => s?.ephemeral === true)+ .map((s) => s.id),+ );+ const filtered = incoming.filter((c) => {+ if (c?.universeId && ephemeralUniverseIds.has(c.universeId)) return false;+ if (c?.seriesId && ephemeralSeriesIds.has(c.seriesId)) return false;+ return true;+ });// Routes through `mergeMediaCollectionsFromSync` so the read-modify-write// runs INSIDE `serializeFileWrite` (same tail as addItem / removeItem /// bulkUpdateCollectionItems) — a sync-driven write can't interleave with a// concurrent local mutation on the same JSON file.- const result = await mergeMediaCollectionsFromSync(remoteData.collections || []);+ const result = await mergeMediaCollectionsFromSync(filtered);if (result.applied) {console.log(`🔄 MediaCollections sync: merged ${result.count} collection(s)`);}diff --git a/server/services/sharing/peerSync.js b/server/services/sharing/peerSync.jsindex ff12861044..9232b367f3 100644--- a/server/services/sharing/peerSync.js+++ b/server/services/sharing/peerSync.js@@ -914,14 +914,18 @@ export async function applyIncomingPush(payload) {// Merge into local state via the existing LWW path. The merge functions// honor `deleted: true` + bump `updatedAt`, so this is the single- // tombstone-aware reconciliation point. (Local-ephemeral records are- // silently dropped inside the merge; we still call it so non-ephemeral- // siblings in the issues array land.)+ // tombstone-aware reconciliation point.if (kind === 'universe') {await mergeUniversesFromSync([record]);} else if (kind === 'series') {await mergeSeriesFromSync([record]);- if (Array.isArray(issues) && issues.length > 0) {+ // Bundled issues: skip the entire batch if the LOCAL series is+ // ephemeral. mergeSeriesFromSync already refused the parent record on+ // its own, but child issue merges are a separate code path —+ // `updateSeries` doesn't auto-flip child issues' `ephemeral` flag when+ // the parent is marked ephemeral, so without this gate a stale reverse+ // subscription could overwrite the private fork's issue stages.+ if (!localEphemeral && Array.isArray(issues) && issues.length > 0) {await mergeIssuesFromSync(issues);}}