fix(taste): a play still open, or closed unheard, no longer grades as a skip (#8127)

The taste build graded every play in its window, and a play with no
completion ratio and no played duration came out as completion 0: a song
playing during the rebuild, or a row the sweeper closed without hearing
how it ended, counted as abandoned and pushed its artist and tags
negative. Only plays whose completion is known are graded now; an open
play is graded once it ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-28 11:59:34 -05:00
co-authored by Claude Opus 5.5
parent 698ff23105
commit e2172e925e
3 changed files with 40 additions and 2 deletions
+4 -1
View File
@@ -196,6 +196,7 @@ JOIN tracks t ON t.id = pe.track_id
JOIN albums a ON a.id = t.album_id
WHERE pe.user_id = $1
AND pe.started_at > now() - ($2::float8 * INTERVAL '1 day')
AND (pe.completion_ratio IS NOT NULL OR pe.duration_played_ms IS NOT NULL)
AND NOT EXISTS (
SELECT 1 FROM quarantine q
WHERE q.user_id = $1 AND q.track_id = t.id
@@ -223,7 +224,9 @@ type ListPlayEngagementInputsForUserRow struct {
// completion ratio (precomputed column when present, else duration_played /
// track duration, clamped to [0,1]); age_days drives the time-decay. Genre
// is split into tags in Go; release_date derives the decade for the era
// facet. Quarantined tracks are excluded.
// facet. Quarantined tracks are excluded, and so is a play whose completion
// isn't known: one still open (playing now), or one the sweeper closed
// without hearing how it ended. Graded as 0 they would read as skips.
func (q *Queries) ListPlayEngagementInputsForUser(ctx context.Context, arg ListPlayEngagementInputsForUserParams) ([]ListPlayEngagementInputsForUserRow, error) {
rows, err := q.db.Query(ctx, listPlayEngagementInputsForUser, arg.UserID, arg.Column2)
if err != nil {
+4 -1
View File
@@ -7,7 +7,9 @@
-- completion ratio (precomputed column when present, else duration_played /
-- track duration, clamped to [0,1]); age_days drives the time-decay. Genre
-- is split into tags in Go; release_date derives the decade for the era
-- facet. Quarantined tracks are excluded.
-- facet. Quarantined tracks are excluded, and so is a play whose completion
-- isn't known: one still open (playing now), or one the sweeper closed
-- without hearing how it ended. Graded as 0 they would read as skips.
SELECT
t.id AS track_id,
t.artist_id,
@@ -23,6 +25,7 @@ JOIN tracks t ON t.id = pe.track_id
JOIN albums a ON a.id = t.album_id
WHERE pe.user_id = $1
AND pe.started_at > now() - ($2::float8 * INTERVAL '1 day')
AND (pe.completion_ratio IS NOT NULL OR pe.duration_played_ms IS NOT NULL)
AND NOT EXISTS (
SELECT 1 FROM quarantine q
WHERE q.user_id = $1 AND q.track_id = t.id
+32
View File
@@ -149,6 +149,38 @@ func TestBuildTasteProfile_PositiveVsNegative(t *testing.T) {
}
}
// A song playing now, and a play the sweeper closed without hearing how it
// ended, have no completion. Neither reads as a skip: the artist gets no
// negative weight from them.
func TestBuildTasteProfile_APlayWithNoKnownCompletionIsNotASkip(t *testing.T) {
pool := dbtest.Pool(t)
now := time.Now().UTC()
u := seedUser(t, pool, "tp-open")
playing := seedArtist(t, pool, "Playing Now")
track := seedTrack(t, pool, playing.ID, "Folk")
for i, ended := range []bool{false, true} {
started := now.Add(-time.Duration(i+1) * time.Hour)
_, err := pool.Exec(context.Background(), `
WITH s AS (
INSERT INTO play_sessions (user_id, started_at, last_event_at)
VALUES ($1, $3, $3) RETURNING id
)
INSERT INTO play_events (user_id, track_id, session_id, started_at, ended_at)
SELECT $1, $2, s.id, $3, CASE WHEN $4 THEN now() END FROM s
`, u.ID, track.ID, started, ended)
if err != nil {
t.Fatalf("seed play (ended=%v): %v", ended, err)
}
}
if err := BuildTasteProfile(context.Background(), pool, discardLogger(), u.ID, DefaultConfig()); err != nil {
t.Fatalf("build: %v", err)
}
if w, ok := artistWeight(t, pool, u.ID, playing.ID); ok && w < 0 {
t.Errorf("artist weight = %.3f, want no negative weight from plays of unknown completion", w)
}
}
// TestBuildTasteProfile_AggregationProtectsArtist: one early-skip among many
// completed plays must NOT make a loved artist net-negative (the user's
// concern that a track-dislike shouldn't tank the artist).