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

fix: prefer a stored Spotify URI over the bare ID so episodes keep their namespace (#8767)

[._.]/ Adam Eivyababdc2e4569
diff --git a/server/services/twinEnrichment.js b/server/services/twinEnrichment.js
index 329024d834..e965478821 100644
--- a/server/services/twinEnrichment.js
+++ b/server/services/twinEnrichment.js
@@ -156,9 +156,10 @@ export function topTrackCounts(entries, limit = 10) {
// 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) {
+ if (ev?.metadata?.trackUri) return String(ev.metadata.trackUri);
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 || '';
+ return 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.js
index 6c9c5a8fee..826329bed0 100644
--- a/server/services/twinEnrichment.test.js
+++ b/server/services/twinEnrichment.test.js
@@ -143,10 +143,11 @@ describe('rollupListen / rollupWatch', () => {
{ 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' } },
+ { kind: 'media.listen', title: 'Ep', metadata: { trackId: 'example123', 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 });
+ expect(rollupListen(mixed).novelty).toEqual({ total: 5, distinct: 3, repeats: 2, noveltyRatio: 0.6 });
});
it('rolls up only media.watch events with channels + novelty', () => {
const watches = [