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: strict ownership check for legacy unsubscribe cleanup
[._.]/ Adam Eivy58cd12a9b4fb
diff --git a/server/services/sharing/subscriptions.js b/server/services/sharing/subscriptions.jsindex c0a182fcfc..1116c5ffed 100644--- a/server/services/sharing/subscriptions.js+++ b/server/services/sharing/subscriptions.js@@ -192,7 +192,10 @@ export async function unsubscribe(id) {// if it exists AND was authored by THIS instance — a peer that subscribed// pre-upgrade and unsubscribed post-upgrade would otherwise leave a phantom// file in the bucket. Read the file's `senderInstanceId` before unlinking- // so we don't stomp on a different peer's pre-upgrade share.+ // so we don't stomp on a different peer's pre-upgrade share. We only unlink+ // on a strict positive match — a legacy file missing `senderInstanceId`+ // (very early v1 or malformed) is left alone, since ownership cannot be+ // verified and removing a peer's share is worse than leaving a phantom.const bucket = await getBucket(sub.bucketId).catch(() => null);if (bucket) {const myInstanceId = await getInstanceId().catch(() => null);@@ -205,9 +208,9 @@ export async function unsubscribe(id) {}const legacyName = legacySubscriptionFilename(sub);const legacyPath = join(bucket.path, 'manifests', legacyName);- if (existsSync(legacyPath)) {+ if (existsSync(legacyPath) && isStr(myInstanceId)) {const legacy = await readJSONFile(legacyPath, null, { logError: false });- if (legacy && (!legacy.senderInstanceId || legacy.senderInstanceId === myInstanceId)) {+ if (legacy && legacy.senderInstanceId === myInstanceId) {await unlink(legacyPath).catch((err) => {console.log(`⚠️ sharing.subscriptions: failed to remove legacy ${legacyPath}: ${err.message}`);});diff --git a/server/services/sharing/subscriptions.test.js b/server/services/sharing/subscriptions.test.jsindex cd70e9d43a..9847171dd3 100644--- a/server/services/sharing/subscriptions.test.js+++ b/server/services/sharing/subscriptions.test.js@@ -116,6 +116,22 @@ describe('sharing/subscriptions', () => {expect(fs.existsSync(legacyPath)).toBe(true);});+ it('unsubscribe preserves a legacy filename with no senderInstanceId (ownership unverifiable)', async () => {+ // A pre-v2 or malformed legacy file with no `senderInstanceId` could+ // belong to any peer; deleting it on unsubscribe risks stomping a+ // peer's share. The strict-equality gate must leave it in place.+ const bucket = await buckets.createBucket({ name: 'B', path: tempBucket });+ const u = await universeBuilder.createUniverse({ name: 'U-legacy-anon' });+ const fs = await import('fs');++ const sub = await subs.subscribe({ bucketId: bucket.id, recordKind: 'universe', recordId: u.id });+ const legacyPath = join(tempBucket, 'manifests', `sub-universe-${u.id}.json`);+ fs.writeFileSync(legacyPath, JSON.stringify({ /* senderInstanceId absent */ }));++ await subs.unsubscribe(sub.id);+ expect(fs.existsSync(legacyPath)).toBe(true);+ });+it('listSubscriptions filters by bucketId / recordKind / recordId', async () => {const bucket1 = await buckets.createBucket({ name: 'A', path: tempBucket });const bucket2Path = mkdtempSync(join(tmpdir(), 'portos-subs-b2-'));