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

feat(peer-sync): broadcast peerSync:subscription:created on reverse-sub auto-create

Adam Eivy0e81cb3f3014
diff --git a/client/src/pages/Instances.jsx b/client/src/pages/Instances.jsx
index 572d59135f..3697e7ff5e 100644
--- a/client/src/pages/Instances.jsx
+++ b/client/src/pages/Instances.jsx
@@ -805,10 +805,18 @@ function PeerCard({ peer, onRefresh, syncStatus, tailnetInfo }) {
};
socket.on('peerSync:subscription-blocked', handleSchemaSubChange);
socket.on('peerSync:subscription-unblocked', handleSchemaSubChange);
+ // An incoming push from this peer auto-created a reverse subscription
+ // back to it (`maybeCreateReverseSubscription`). The new row lives in
+ // peer_subscriptions.json but this card cached `peerSubs` on mount, so
+ // refetch this peer's subs to surface the adopted-from-reverse sub
+ // without a manual page reload. Carries `peerId`, so the same filter
+ // keeps every other card from refetching needlessly.
+ socket.on('peerSync:subscription:created', handleSchemaSubChange);
return () => {
cancelled = true;
socket.off('peerSync:subscription-blocked', handleSchemaSubChange);
socket.off('peerSync:subscription-unblocked', handleSchemaSubChange);
+ socket.off('peerSync:subscription:created', handleSchemaSubChange);
};
}, [peer.instanceId]);
diff --git a/server/services/sharing/index.js b/server/services/sharing/index.js
index cad4e7a2cc..c42b9ba354 100644
--- a/server/services/sharing/index.js
+++ b/server/services/sharing/index.js
@@ -67,6 +67,12 @@ export async function initSharing({ io: socketIo } = {}) {
peerSyncEvents.on('subscription-unblocked', (payload) => {
io.emit('peerSync:subscription-unblocked', payload);
});
+ // An incoming push auto-created a reverse subscription back to the
+ // sender. Let the Instances UI re-fetch that peer's subs so the new
+ // adopted-from-reverse row appears without a manual page reload.
+ peerSyncEvents.on('subscription-created', (payload) => {
+ io.emit('peerSync:subscription:created', payload);
+ });
sharingEvents.on('unshared', (payload) => {
io.emit('sharing:unshared', payload);
});
diff --git a/server/services/sharing/peerSync.js b/server/services/sharing/peerSync.js
index 931c69229a..4428ea22a3 100644
--- a/server/services/sharing/peerSync.js
+++ b/server/services/sharing/peerSync.js
@@ -82,7 +82,11 @@ export const PEER_SUBSCRIBABLE_KINDS = Object.freeze(['universe', 'series', 'med
* emits `asset-arrived` ({ filename, kind, peerId }) when a previously-missing
* file lands locally; `sharing/index.js` wires that to a socket emission so
* the client's MediaImage component can swap its "syncing" placeholder for
- * the real bytes without polling.
+ * the real bytes without polling. `maybeCreateReverseSubscription` emits
+ * `subscription-created` ({ peerId, recordKind, recordId, subId }) when an
+ * incoming push auto-creates a reverse subscription, which `sharing/index.js`
+ * relays as the `peerSync:subscription:created` socket event so the Instances
+ * page can re-fetch that peer's subscriptions without a manual reload.
*/
export const peerSyncEvents = new EventEmitter();
peerSyncEvents.setMaxListeners(100);
@@ -1462,7 +1466,22 @@ async function maybeCreateReverseSubscription({ peerId, recordKind, recordId })
const localState = await classifyLocalRecord(recordKind, recordId);
if (localState !== 'syncable') return false;
- await subscribePeer({ peerId, recordKind, recordId }, { adoptedFromReverse: true });
+ const sub = await subscribePeer({ peerId, recordKind, recordId }, { adoptedFromReverse: true });
+ // subscribePeer is idempotent — only announce when a row was genuinely
+ // inserted (created=true). The existing-sub short-circuit at the top of
+ // this function already returns early, but guarding on `created` keeps the
+ // event honest if a race ever lands an identical row between the
+ // findPeerSubscription check and the insert. `sharing/index.js` wires this
+ // to the `peerSync:subscription:created` socket event so the Instances page
+ // re-fetches that peer's subs without a manual reload.
+ if (sub?.created) {
+ peerSyncEvents.emit('subscription-created', {
+ peerId,
+ recordKind,
+ recordId,
+ subId: sub.id,
+ });
+ }
return true;
}