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

address review: snapshot path parent-ephemeral + UI subscribe full guard

Adam Eivy78bbf0d353f7
diff --git a/client/src/components/sharing/SyncToPeerButton.jsx b/client/src/components/sharing/SyncToPeerButton.jsx
index 249ca66d69..0cdc227137 100644
--- a/client/src/components/sharing/SyncToPeerButton.jsx
+++ b/client/src/components/sharing/SyncToPeerButton.jsx
@@ -63,14 +63,21 @@ export default function SyncToPeerButton({
setLoading(false);
};
- // Per-record subscribability — mirrors server-side peerHasCategory in
- // peerSync.js. universe → 'universe' category, series → 'pipeline'.
- // Without this gate the UI would let the user subscribe to a peer
- // whose category bit is off, then silently fail every push with
- // category-disabled (server-side guard in pushRecordToPeer).
+ // Per-record subscribability — mirrors server-side guards in peerSync.js
+ // (peerAllowsOutbound + peerHasCategory). Without this triple gate the
+ // UI would let the user subscribe to a peer that silently rejects every
+ // push (with peer-disabled, peer-disallows-outbound, or
+ // category-disabled), leaving the row checked but no records ever
+ // landing. universe → 'universe' category, series → 'pipeline'.
const requiredCategory = recordKind === 'universe' ? 'universe' : 'pipeline';
- const peerHasMatchingCategory = (peer) => {
- const cats = peer?.syncCategories;
+ const peerCanReceiveOutbound = (peer) => {
+ if (!peer) return false;
+ // Global sync flag off → server's pushRecordToPeer refuses.
+ if (peer.syncEnabled === false) return false;
+ // Inbound-only direction → outbound pushes silently dropped.
+ if (Array.isArray(peer.directions) && peer.directions.length > 0
+ && !peer.directions.includes('outbound')) return false;
+ const cats = peer.syncCategories;
return !!cats && typeof cats === 'object' && cats[requiredCategory] === true;
};
@@ -157,21 +164,28 @@ export default function SyncToPeerButton({
{peers.map((p) => {
const subscribed = !!subscriptionForPeer(p.instanceId);
const busy = busyPeerId === p.instanceId;
- // Disable when the peer's syncCategories doesn't cover this
- // record kind. server-side pushRecordToPeer would otherwise
- // accept the subscription but refuse every push with
- // `category-disabled`, leaving the UI with a misleading
- // "Syncing" toast for a peer that won't actually receive
- // any pushes.
- const categoryEnabled = peerHasMatchingCategory(p);
+ // Disable when the peer can't actually receive outbound
+ // pushes for this record kind — global sync off, inbound-
+ // only directions, or the per-record category is off. UI
+ // mirrors server-side guards in pushRecordToPeer.
+ const canSync = peerCanReceiveOutbound(p);
const categoryLabel = requiredCategory === 'universe' ? 'Universe' : 'Pipeline';
+ // Compute the most-specific reason for the inline hint.
+ const disabledReason = !canSync
+ ? (p.syncEnabled === false
+ ? 'Sync disabled for this peer'
+ : (Array.isArray(p.directions) && p.directions.length > 0
+ && !p.directions.includes('outbound')
+ ? 'Peer is inbound-only'
+ : `${categoryLabel} sync off`))
+ : null;
return (
<li key={p.instanceId}>
<button
type="button"
onClick={() => handleToggle(p)}
- disabled={busy || !categoryEnabled}
- title={!categoryEnabled ? `Enable ${categoryLabel} sync for this peer on the Instances page first.` : undefined}
+ disabled={busy || !canSync}
+ title={disabledReason ? `${disabledReason}. Enable on the Instances page first.` : undefined}
className="w-full text-left px-3 py-2 hover:bg-port-bg disabled:opacity-50 disabled:cursor-not-allowed flex items-start gap-2"
>
<span className="mt-0.5 shrink-0">
@@ -186,7 +200,7 @@ export default function SyncToPeerButton({
<div className="text-[10px] text-gray-500 truncate">
{p.status === 'online' ? 'online' : p.status || 'offline'}
{p.host ? ` · ${p.host}` : p.address ? ` · ${p.address}` : ''}
- {!categoryEnabled && ` · ${categoryLabel} sync off`}
+ {disabledReason && ` · ${disabledReason}`}
</div>
</div>
</button>
diff --git a/server/services/pipeline/issues.js b/server/services/pipeline/issues.js
index fee20f1b6f..6d30547900 100644
--- a/server/services/pipeline/issues.js
+++ b/server/services/pipeline/issues.js
@@ -896,8 +896,8 @@ export function updateStageWithLatest(issueId, stageId, computeFn) {
* `{ applied, count }` where `count` is the number of issues actually
* changed/added.
*/
-export function mergeIssuesFromSync(remoteIssues) {
- if (!Array.isArray(remoteIssues)) return Promise.resolve({ applied: false, count: 0 });
+export async function mergeIssuesFromSync(remoteIssues) {
+ if (!Array.isArray(remoteIssues)) return { applied: false, count: 0 };
// Series IDs whose issue set saw at least one delete-transition — drives a
// post-write renumber so the receiver's issue numbering catches up with the
// sender's (otherwise a synced tombstone would leave a gap).
@@ -907,17 +907,40 @@ export function mergeIssuesFromSync(remoteIssues) {
// Stage 2 per-record peer-sync push owns sync-time edit emits). Delete-
// transitions DO emit per series so subscribers know to drop the issue.
const seriesNeedingRenumber = new Set();
+ // Build the set of locally-ephemeral series ids BEFORE the queue. The
+ // per-record push pipeline (applyIncomingPush) already gates the bundled
+ // issues batch by parent-ephemeral, but the snapshot pipeline path
+ // (applyPipelineRemote → mergeIssuesFromSync) bypasses that check. Without
+ // this filter, a peer with `pipeline` sync enabled can create/update/
+ // tombstone issues under a locally-private series and overwrite the
+ // user's private fork.
+ const ephemeralSeriesIds = new Set(
+ (await seriesSvc.listSeries({ includeDeleted: true }).catch(() => []))
+ .filter((s) => s?.ephemeral === true)
+ .map((s) => s.id),
+ );
return queueIssueWrite(async () => {
const state = await readState();
const localById = new Map(state.issues.map((i) => [i.id, i]));
let changed = 0;
for (const remote of remoteIssues) {
if (!remote || typeof remote !== 'object' || !isStr(remote.id)) continue;
+ // Drop issues whose parent series is locally ephemeral, BEFORE any
+ // mutation. This covers create/update/tombstone uniformly — the
+ // sanitized.seriesId may be either the existing local series or a
+ // remote-only target; reject either way.
+ if (ephemeralSeriesIds.has(remote.seriesId)) continue;
const sanitized = sanitizeIssue(remote);
if (!sanitized) continue;
// Strip inbound `ephemeral` — see mergeUniversesFromSync.
if ('ephemeral' in sanitized) delete sanitized.ephemeral;
const local = localById.get(sanitized.id);
+ // Belt-and-suspenders: if the existing local issue belongs to an
+ // ephemeral series, refuse the merge even though the inbound
+ // sanitized.seriesId might point elsewhere (a peer could ship an
+ // issue id whose local copy is under a private series and try to
+ // move it).
+ if (local && ephemeralSeriesIds.has(local.seriesId)) continue;
if (!local) {
// No local counterpart — accept the record but don't trigger a
// renumber pass. A tombstone for an issue we never had has nothing