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
fix: fail closed when tombstone sweep can't read the peer registry (#8412)
[._.]/ Adam Eivy570f2ec00372
diff --git a/server/services/sharing/tombstoneGc.js b/server/services/sharing/tombstoneGc.jsindex ac5909152e..536928afe1 100644--- a/server/services/sharing/tombstoneGc.js+++ b/server/services/sharing/tombstoneGc.js@@ -375,9 +375,17 @@ async function cutoffForKind(recordKind, { peers, subs, now, graceMs }) {// `sweepTombstones` and `getSweepStatus` read these once and thread them// through the pure helpers, so the orchestrator's 60s loop hits the file// system twice per cycle instead of six times.+//+// getPeers() rejects only when the registry file exists but can't be read+// (jsonIo's `strict: true`); a genuinely absent instances.json resolves to+// an empty peer list instead. Do NOT swallow that rejection here — an empty+// peer list widens every cutoff to "prune everything older than the grace+// window", so a transient/corrupt read must fail the sweep, not fail open+// into an unbounded prune. Callers (runTombstoneSweep, the manual sweep+// route) already handle and log a rejected loadState().async function loadState() {const [peers, subs] = await Promise.all([- getPeers().catch(() => []),+ getPeers(),listPeerSubscriptions(),]);return { peers, subs };diff --git a/server/services/sharing/tombstoneGc.test.js b/server/services/sharing/tombstoneGc.test.jsindex 84e810c396..cfc5c62fa3 100644--- a/server/services/sharing/tombstoneGc.test.js+++ b/server/services/sharing/tombstoneGc.test.js@@ -215,6 +215,54 @@ describe('sweepTombstones — no peers subscribed', () => {});});+describe('sweepTombstones — unreadable peer registry fails closed (#8412)', () => {+ it('rejects and prunes nothing when getPeers() rejects, instead of treating the failure as "no peers"', async () => {+ getPeers.mockRejectedValue(new Error('EIO: instances.json unreadable'));+ mockSubs({});++ await expect(sweepTombstones({ now: NOW })).rejects.toThrow('EIO: instances.json unreadable');++ expect(pruneTombstonedUniverses).not.toHaveBeenCalled();+ expect(pruneTombstonedSeries).not.toHaveBeenCalled();+ expect(pruneTombstonedIssues).not.toHaveBeenCalled();+ expect(pruneTombstonedCollections).not.toHaveBeenCalled();+ expect(pruneTombstonedLooms).not.toHaveBeenCalled();+ expect(pruneTombstonedAuthors).not.toHaveBeenCalled();+ expect(pruneTombstonedArtists).not.toHaveBeenCalled();+ expect(pruneTombstonedAlbums).not.toHaveBeenCalled();+ expect(pruneTombstonedTracks).not.toHaveBeenCalled();+ expect(pruneTombstonedProjects).not.toHaveBeenCalled();+ expect(pruneTombstonedMusicVideoProjects).not.toHaveBeenCalled();+ expect(pruneTombstonedBoards).not.toHaveBeenCalled();+ expect(pruneTombstonedWorks).not.toHaveBeenCalled();+ expect(pruneTombstonedFolders).not.toHaveBeenCalled();+ expect(pruneTombstonedExercises).not.toHaveBeenCalled();+ expect(pruneTombstonedCommissionFeedback).not.toHaveBeenCalled();+ expect(pruneTombstonedCommissions).not.toHaveBeenCalled();+ expect(pruneTombstonedDecks).not.toHaveBeenCalled();+ expect(pruneOrphanedBaseHashes).not.toHaveBeenCalled();+ expect(pruneOrphanedPeerSubscriptions).not.toHaveBeenCalled();+ });++ it('getSweepStatus() rejects under the same condition instead of returning { refused: [] }', async () => {+ getPeers.mockRejectedValue(new Error('EIO: instances.json unreadable'));+ mockSubs({});++ await expect(getSweepStatus({ now: NOW })).rejects.toThrow('EIO: instances.json unreadable');+ });++ it('still prunes after the grace window when getPeers() resolves [] (no federation, e.g. ENOENT)', async () => {+ getPeers.mockResolvedValue([]);+ mockSubs({});++ const res = await sweepTombstones({ now: NOW });++ expect(res.refused).toEqual([]);+ const expectedCutoff = NOW - TOMBSTONE_GRACE_MS + 1;+ expect(pruneTombstonedUniverses).toHaveBeenCalledWith(expectedCutoff);+ });+});+describe('sweepTombstones — full-sync peer resurrection guard', () => {it('a full-sync peer with an empty category map still blocks snapshot-kind pruning', async () => {// A full-sync peer mirrors every category regardless of its stored