{"record":{"id":"3c67662d9d62fa46","repo":"tonhowtf/omniget","slug":"player-spotify-heartbeat-resync-failed","errorCode":null,"errorMessage":"[player] spotify heartbeat resync failed","messagePattern":"\\[player\\] spotify heartbeat resync failed","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/lib/study-music/player-store.svelte.ts","lineNumber":722,"sourceCode":"    this._spotifyHeartbeatHandle = setInterval(() => {\n      if (!this.isSpotify()) return;\n      void this.spotifyResyncFromSdk();\n    }, intervalMs);\n  }\n\n  private stopSpotifyHeartbeat() {\n    if (this._spotifyHeartbeatHandle) {\n      clearInterval(this._spotifyHeartbeatHandle);\n      this._spotifyHeartbeatHandle = null;\n    }\n  }\n\n  private async spotifyResyncFromSdk() {\n    try {\n      const state = await spotifySdk.getCurrentState();\n      if (state) this.applySpotifyState(state);\n    } catch (e) {\n      console.warn(\"[player] spotify heartbeat resync failed\", e);\n    }\n  }\n\n  private async loadSpotifySettings() {\n    if (this._spotifySettingsLoaded) return;\n    this._spotifySettingsLoaded = true;\n    try {\n      const res = await pluginInvoke<{\n        heartbeat_enabled?: boolean;\n        heartbeat_interval_ms?: number;\n      }>(\"study\", \"study:music:spotify:settings:get\", {});\n      this._spotifyHeartbeatEnabled = res?.heartbeat_enabled ?? true;\n      const ms = Number(res?.heartbeat_interval_ms ?? 30_000);\n      this._spotifyHeartbeatMs = Number.isFinite(ms)\n        ? Math.min(\n            MusicPlayerStore.SPOTIFY_HEARTBEAT_MAX_MS,\n            Math.max(MusicPlayerStore.SPOTIFY_HEARTBEAT_MIN_MS, ms),\n          )","sourceCodeStart":704,"sourceCodeEnd":740,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src/lib/study-music/player-store.svelte.ts#L704-L740","documentation":"Non-fatal warning: the periodic Spotify heartbeat failed to resync local player state with the Web Playback SDK (spotifySdk.getCurrentState() threw), so the UI may temporarily show stale playback state.","triggerScenarios":"spotifySdk.getCurrentState() rejects or the SDK is not yet initialized when the heartbeat timer fires spotifyResyncFromSdk().","commonSituations":"Spotify Web SDK not loaded/connected yet, browser suspended the tab/SDK, Spotify session dropped, or heartbeat firing before player readiness.","solutions":["Verify the Spotify SDK/player is initialized before starting the heartbeat","Check network/session state; re-authenticate or reconnect the Spotify player if needed","Guard the resync: skip if SDK is not ready","Increase heartbeat interval to reduce SDK pressure"],"exampleFix":"// before\nconst state = await spotifySdk.getCurrentState();\n// after\nif (!spotifySdk.isReady()) return;\nconst state = await spotifySdk.getCurrentState();\nif (!state) return;\nthis.applySpotifyState(state);","handlingStrategy":"try-catch","validationCode":"if (!this._spotifyPlayerReady || !this._spotifyConnected) return;","typeGuard":"function hasSpotifyState(s: unknown): s is SpotifyPlaybackState {\n  return !!s && typeof s === \"object\" && \"track_window\" in s;\n}","tryCatchPattern":"try {\n  const state = await spotifySdk.getCurrentState();\n  if (state) this.applySpotifyState(state);\n} catch (e) {\n  console.warn(\"[player] spotify heartbeat resync failed\", e);\n  if (++this._resyncFailures > 3) this.reconnectSpotify();\n}","preventionTips":["Start the heartbeat only after the SDK player is ready","Track consecutive resync failures and reconnect after a threshold","Avoid tight heartbeat intervals that stress the SDK","Handle tab-suspension (visibilitychange) to pause/resume the heartbeat"],"tags":["spotify","playback-sync","audio-player"],"backgroundTag":"upstream-api-error","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}