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: count a synced Spotify play and an imported play of the same track as one listen identity (#8767)
[._.]/ Adam Eivy3e4fa7c374f4
diff --git a/server/services/twinEnrichment.js b/server/services/twinEnrichment.jsindex 92a3cedee1..329024d834 100644--- a/server/services/twinEnrichment.js+++ b/server/services/twinEnrichment.js@@ -152,9 +152,13 @@ export function topTrackCounts(entries, limit = 10) {// shapes: sync's `trackId`, import's `trackUri`, then isrc, then title —// falling to dedupeKey only as a last resort (per-play, so it never collapses// repeats, which is the safe direction). Using trackUri keeps two different-// imported tracks that share a title from collapsing into one "repeat".+// imported tracks that share a title from collapsing into one "repeat". A bare+// sync ID is namespaced as a track URI so a live play and an imported play of+// the same track share one key; episode URIs keep their own namespace (#8767).function listenNoveltyKey(ev) {- return ev?.metadata?.trackId || ev?.metadata?.trackUri || ev?.metadata?.isrc || ev?.title || ev?.dedupeKey || '';+ const trackId = ev?.metadata?.trackId;+ if (trackId) return String(trackId).startsWith('spotify:') ? String(trackId) : `spotify:track:${trackId}`;+ return ev?.metadata?.trackUri || ev?.metadata?.isrc || ev?.title || ev?.dedupeKey || '';}function watchNoveltyKey(ev) {return ev?.metadata?.videoId || ev?.url || ev?.title || ev?.dedupeKey || '';diff --git a/server/services/twinEnrichment.test.js b/server/services/twinEnrichment.test.jsindex 4c44d0204d..6c9c5a8fee 100644--- a/server/services/twinEnrichment.test.js+++ b/server/services/twinEnrichment.test.js@@ -137,6 +137,17 @@ describe('rollupListen / rollupWatch', () => {// 3 plays, 2 distinct URIs → not collapsed by shared title.expect(r.novelty).toEqual({ total: 3, distinct: 2, repeats: 1, noveltyRatio: 0.667 });});+ it('counts a live trackId and an imported trackUri for the same track as one identity', () => {+ const mixed = [+ { kind: 'media.listen', title: 'Song', metadata: { trackId: 'example123' } },+ { kind: 'media.listen', title: 'Song', metadata: { trackUri: 'spotify:track:example123' } },+ { kind: 'media.listen', title: 'Song', metadata: { trackId: 'other456' } },+ { kind: 'media.listen', title: 'Ep', metadata: { trackUri: 'spotify:episode:example123' } },+ ];+ expect(rollupListen(mixed.slice(0, 2)).novelty).toEqual({ total: 2, distinct: 1, repeats: 1, noveltyRatio: 0.5 });+ // Same title, different id stays distinct; an episode never collides with a track.+ expect(rollupListen(mixed).novelty).toEqual({ total: 4, distinct: 3, repeats: 1, noveltyRatio: 0.75 });+ });it('rolls up only media.watch events with channels + novelty', () => {const watches = [{ kind: 'media.watch', title: 'V1', metadata: { videoId: 'v1', channel: 'Chan', topics: ['tech'] } },