#2767·Tautulli

History grouping merges unrelated items when rating keys collide (DB import / key reuse)

Author: ethanrweberCreated Aug 1, 2026Updated Aug 18, 2026
Labelstype:bugpriority:mediumstatus:awaiting-triagetopic:history

Describe the Bug

After a database import (or rating-key reuse), plays get grouped under — and displayed as — completely different shows, and "Regroup play history" re-creates the damage instead of fixing it.

Mechanism: play-history grouping links a new play to a previous one using only user_id + rating_key, with no time window and no check that the two rows are the same content. Plex rating keys are server-local integers, so two situations produce colliding keys that this match then merges:

  1. Database import from another Plex server (Settings > Import — a built-in feature): every imported row carries the old server's numbering, which the new server reuses for unrelated items.
  2. Same-server key recycling: Plex can hand a deleted item's rating key to new, unrelated media (keys are SQLite rowids).

In my database a play of "Apocalypse Hotel" S1E2 (23-min episode, new server) was grouped under an "Adventure Time" S8E7 play from 11 months earlier (old server, same rating key) and displayed as Adventure Time. My imported history of 3,308 rows contained 201 rating keys referring to different content before vs. after migration; 8 plays ended up displayed as the wrong show.

Why the watched-check doesn't prevent it: the guard that should stop grouping onto a finished play is undermined by an argument mix-up when the colliding items have different runtimes. In ActivityProcessor.group_history() (plexpy/activity_processor.py):

python
prev_watched = helpers.check_watched(
    session['media_type'], prev_session['view_offset'], session['duration'],
    marker_first, marker_final
)

The previous row's view_offset is judged against the new row's duration (introduced by 085cfa4b in v2.12.5, then in write_session_history(); since refactored into group_history()). A 100%-watched 11-minute episode (offset ~693,000 ms) reads as ~50% of a 23-minute episode (duration ~1,381,000 ms) — "unfinished" — so the new play is treated as a resume of unrelated content. For same-content grouping the two durations are equal, so the mix-up is normally invisible.

Regroup can't repair it: Settings > "Regroup play history" replays the same (user_id, rating_key) match over the whole table, so it re-derives the same wrong groups — and reverts any manual fixes. There is no built-in way to recover once a database contains colliding keys.

Happy to provide sanitized rows from the affected database (session_history + session_history_metadata excerpts showing the collision and the resulting reference_id chain), or a generated minimal reproduction database.

Closest existing issues: #564 and #283 discuss cross-server rating-key conflicts generally, but not the grouping match or the check_watched() duration mix-up.

Steps to Reproduce

  1. Run Tautulli against Plex server A; watch show X (user U).
  2. Migrate to Plex server B (fresh library scan) and import the Tautulli database via the built-in import.
  3. Pick any item Y on server B and check its rating key against the imported history: SELECT id FROM session_history WHERE user_id = <U> AND rating_key = <Y's key> — with a few thousand imported rows there are many hits (201 of 3,308 in mine).
  4. As user U, watch Y to the end, where Y is longer than X (the final view_offset must exceed X's recorded offset — grouping also requires prev_session['view_offset'] <= new_session['view_offset']).
  5. History shows the Y play grouped under — and displayed as — X. Clicking the row opens Y's info page.

Expected Behavior

A play should only be grouped with a previous play of the same content, and a fully-watched previous play should not be treated as a resume. At minimum, check_watched() should receive the previous session's duration instead of the new session's; matching on guid would address key collisions more completely.

Screenshots

None available unfortunately. I already fixed the affected rows locally with a custom script. I can provide a DB excerpt if that would be helpful though.

Relevant Settings

  • Group Play History: enabled (group_history_tables = 1)
  • TV/Movie watched percent: 85 / 85, watched_marker = 3 (defaults)
  • History imported from another Plex server via Settings > Import

Tautulli Version

v2.17.2

Git Branch

master

Git Commit Hash

c7153deb6e3017b8dda46c8448fe548a61c5a47a

Platform and Version

Docker (linuxserver/tautulli v2.17.2-ls237) on Ubuntu 24.04

Python Version

3.14.5

Browser and Version

Chrome 138 (bug is not browser-specific though)

Link to Logs

https://gist.github.com/ethanrweber/578b43e68f04ac0b884419d47082ee07