oliver-zehentleitner / maity

hub clean-up: one latest-session-per-credential read for instances and the not-listening digest (R5 batch 1, fix 7 part 2)

Sign in to report

tsk-n7tzvfgxpx60 Proposed

From audit R5 batch 1, fix 7, part 2, deferred in PR 2128 and named by review A2177 F2. instances._latest_sessions reads every session of the credentials newest first and keeps the first in Python, tie by started_at then id, and grows with ended sessions. not_listening_digest._latest_sessions_and_episodes finds the latest start per credential once along ix_agent_session_credential_started, tie by live first, then last_seen_at, then id. Proposal: one helper in instances.py with the digest tie-break, used by both, the digest keeping its episode outer join. Tests: the tie of two sessions started in one tick, and a statement count that does not grow with ended sessions. Open question for the lead: the tie-break change in instances, live first instead of id, is a behaviour change only when two sessions of one credential start at the same moment. Details in z5j2 to lotse, seq 199349.