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 (codex): pin heal sync to intended feed + emit on heal

[._.]/ Adam Eivy5832ebbc87a6
diff --git a/server/services/moodBoard/pinterest.js b/server/services/moodBoard/pinterest.js
index aa0694bd10..fabcd61f66 100644
--- a/server/services/moodBoard/pinterest.js
+++ b/server/services/moodBoard/pinterest.js
@@ -105,11 +105,23 @@ export async function syncPinterestBoard(boardId) {
fromFeedUrl: staleFeedUrl, feedUrl: healedFeedUrl, boardUrl: healedBoardUrl,
});
board = healed;
- if (changed) console.log(`📌 Pinterest sync: board ${boardId} feed corrected to ${healedFeedUrl} (section URL has no RSS)`);
+ if (changed) {
+ // The heal persisted a feed-URL correction — emit now so federation/UI
+ // pick it up even if the fetch below fails (otherwise peers keep the stale
+ // section feed until a later successful sync).
+ emitRecordUpdated('moodBoard', boardId);
+ console.log(`📌 Pinterest sync: board ${boardId} feed corrected to ${healedFeedUrl} (section URL has no RSS)`);
+ }
+ }
+ // This sync is committed to `healedFeedUrl` (== staleFeedUrl when no heal was
+ // needed). If a concurrent unlink/repoint during the heal left the persisted
+ // board on a different feed, abort rather than sync a feed this run wasn't
+ // started for — same guard the locked append applies via expectedFeedUrl.
+ const feedUrl = healedFeedUrl;
+ if (board.pinterest?.feedUrl !== feedUrl) {
+ console.log(`📌 Pinterest sync: board ${boardId} aborted — link changed mid-sync`);
+ return { board, added: 0, feedCount: 0, aborted: true };
}
- // A concurrent unlink during the heal leaves the board without a link — bail.
- const feedUrl = board.pinterest?.feedUrl;
- if (!feedUrl) throw new ServerError('This board is not linked to a Pinterest board', { status: 400, code: 'NOT_LINKED' });
const xml = await fetchPublicText(feedUrl, { timeoutMs: FEED_TIMEOUT_MS, headers: FEED_HEADERS });
if (!xml) throw new ServerError('Could not fetch the Pinterest feed (it may be private or rate-limited)', { status: 502, code: 'FEED_FETCH_FAILED' });
diff --git a/server/services/moodBoard/pinterest.test.js b/server/services/moodBoard/pinterest.test.js
index a3f8d40c5a..d089ad761c 100644
--- a/server/services/moodBoard/pinterest.test.js
+++ b/server/services/moodBoard/pinterest.test.js
@@ -168,7 +168,7 @@ describe('syncPinterestBoard', () => {
expect(store.appendPinterestItems.mock.calls[0][2]).toMatchObject({ expectedFeedUrl: 'https://www.pinterest.com/j/b.rss' });
});
- it('bails with NOT_LINKED when a concurrent unlink wins the heal race', async () => {
+ it('aborts (no fetch) when a concurrent unlink wins the heal race', async () => {
store.getBoard.mockResolvedValue({
id: 'mb-1',
items: [],
@@ -177,8 +177,30 @@ describe('syncPinterestBoard', () => {
// User unlinked concurrently: the guarded heal didn't write and the board is now unlinked.
store.healPinterestFeed.mockResolvedValue({ board: { id: 'mb-1', items: [] }, changed: false });
- await expect(syncPinterestBoard('mb-1')).rejects.toMatchObject({ status: 400, code: 'NOT_LINKED' });
+ const result = await syncPinterestBoard('mb-1');
+ expect(result).toMatchObject({ aborted: true, added: 0 });
+ expect(net.fetchPublicText).not.toHaveBeenCalled();
+ expect(store.appendPinterestItems).not.toHaveBeenCalled();
+ });
+
+ it('aborts (no fetch) when a concurrent repoint wins the heal race', async () => {
+ store.getBoard.mockResolvedValue({
+ id: 'mb-1',
+ items: [],
+ pinterest: { feedUrl: 'https://www.pinterest.com/j/b/sec.rss', boardUrl: 'https://www.pinterest.com/j/b/sec/' },
+ });
+ // User repointed to a DIFFERENT board mid-heal: guard didn't write; the
+ // persisted feed is neither the section nor the healed board feed.
+ store.healPinterestFeed.mockResolvedValue({
+ board: { id: 'mb-1', items: [], pinterest: { feedUrl: 'https://www.pinterest.com/other/board.rss', boardUrl: 'https://www.pinterest.com/other/board/' } },
+ changed: false,
+ });
+
+ const result = await syncPinterestBoard('mb-1');
+ expect(result).toMatchObject({ aborted: true, added: 0 });
+ // Must NOT silently sync the user's newly-repointed feed.
expect(net.fetchPublicText).not.toHaveBeenCalled();
+ expect(store.appendPinterestItems).not.toHaveBeenCalled();
});
it('skips a pin whose download returns a non-image body', async () => {