Plex sw_lastWatched picks highest season/episode index, not most recent viewedAt
Describe the bug
sw_lastWatched ("Newest episode view date") for Plex shows does not return the most
recent view date. It returns the viewedAt of whichever watch-history entry has the
highest parentIndex/index (season/episode number), regardless of when that entry
was actually viewed.
apps/server/src/modules/rules/getter/plex-getter.service.ts, sw_lastWatched case
(~line 406-425):
watchHistory.sort((a, b) => b.parentIndex - a.parentIndex);
const newestSeason = watchHistory.filter(
(el) => el.parentIndex === watchHistory[0].parentIndex,
);
newestSeason.sort((a, b) => b.index - a.index);
return new Date(+newestSeason[0].viewedAt * 1000);
This sorts by season/episode number and never looks at viewedAt to pick the entry —
it only reads viewedAt off whatever entry lands on top after that sort.
To Reproduce
- Watch a late episode/season of a show once, a long time ago.
- Watch an earlier episode of the same show recently (a rewatch, a different user catching up, etc.).
- Add a rule using
Plex.sw_lastWatched. - The rule sees the old date from step 1, not the recent watch from step 3.
Expected behavior
sw_lastWatched should reflect the most recently viewed watch-history entry
(max(viewedAt)), not the entry with the highest season/episode number.
Related: #2731 was the same symptom for Jellyfin ("Newest episode view date does not
correctly return view date of newest episode in a season") and was fixed there by
walking watched episodes in order. The Plex path still has the original bug — the
getWatchHistory call itself is already sorted viewedAt:desc
(plex-api.service.ts getWatchHistory), so the season/episode re-sort in the getter
is what discards that ordering.
Device
- Maintainerr: current
main(confirmed bug still present, only the[]-guard from #3083 has been added since) - Media server: Plex
Correcting myself — this isn't a bug. I missed the existing test coverage for this exact behavior before filing.
sw_lastWatched is explicitly the "date of the newest-numbered watched episode",
not "most recent view of anything". That's tested directly in
plex-getter.service.spec.ts (sw_lastWatched (id 13) - Newest episode view date),
and it matches the semantic #2731 settled on for the Jellyfin equivalent
(getLastWatchedShowDate) — the season/episode sort is intentional, not a
leftover bug.
The property I actually wanted for "has anything in this show been watched
recently, regardless of episode number" is lastViewedAt ("Last view date",
Plex prop 7), which does max(watch history viewedAt, item's own lastViewedAt)
across all history — no season/episode filtering.
Closing — my Maintainerr rule was pointing at the wrong property (sw_lastWatched
instead of lastViewedAt), not a bug in the getter. Sorry for the noise.