Repository navigation
fix(audiobooks): record Audiobookshelf plays in admin playback history - #2965
Conversation
Closing an Audiobookshelf session stopped its native playback session without running the session manager's finish hooks, so the play never reached admin playback history. Only sessions a client abandoned, which expire through the native stale-session cleanup, were recorded. Closing now finishes the native session, which records the play the same way a Jellyfin-compatible stop does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016wJkeovgRDcHgJXkibXhY7
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
The change is visible: closing an Audiobookshelf session can add a row to the admin Playback History. The Evidence section has only an after capture and does not identify the build or commit for it. Please add before-and-after captures of the same Playback History screen for the same test play, and name the build or commit for each capture. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
|
There are a few more issues with the ABS layer that i'll fix, starting with this one. This should be ready for review |
| return | ||
| } | ||
| if err := h.deps.NativeSessions.StopSession(sessionID); err != nil { | ||
| if err := h.deps.NativeSessions.FinishSession(ctx, sessionID); err != nil { |
There was a problem hiding this comment.
Medium, disclosed, maintainer decision. Every normal close now writes an admin history row, and for a multi-file audiobook that row is wrong. The native session is started on files[0] while ABS syncs set its position to the whole-book currentTime. buildAdminHistoryEntry then uses the first track's Duration and sets completed once the position passes the watched fraction of that track. For a book of 30-minute tracks closed one hour in, the row shows a 30-minute duration, 60 minutes watched, and completed. RecordHistory keeps completed once it is set.
Before this PR only abandoned sessions reached this path, through expiry; now every closed session does. The fix belongs in how the history row gets the book's duration, not in this close call, so it is tracked separately in #3098. Whether to merge this PR first or wait for that fix is a maintainer call. No change is needed here from you.
|
Review summary for cedf888. This fixes a real gap: an Audiobookshelf session closed normally ended its native playback session with What I checked
Left for the maintainers
Validated features: none affected. No case on the v1.0 board is recorded as passed. The Audiobookshelf compatibility task (#1247) covers authentication, browsing, playback, and access restrictions, and this change touches none of them. User manual: unaffected. The Audiobookshelf compatibility and audiobooks pages on siloserver.org don't describe admin Playback History. Apple and Android: no follow-up. The change is server-side and only affects the admin history row. jellycompat already finishes sessions this way. Fit: 8/10 · Readiness: 8/10 — conditional
|
Problem
Related issue: N/A
Validation tasks: none
Audiobookshelf listening sessions that a client closes normally never show up in the admin Playback History page. Only sessions a client abandons get recorded, because those expire through the native stale-session cleanup, which writes history. Admins see a partial, skewed picture of audiobook listening: clean plays are missing and abandoned ones are present.
POST /abs/api/session/{sid}/closeended the mirrored native playback session withSessionManager.StopSession, which removes the session without running finish hooks. The admin history row is written by the finish hookPlaybackHandler.handleFinishedSession.Approach
ABS close now ends the native session with
FinishSession, the same path jellycompat uses for a finished play, so the existing finish hook records the row. The ABS handler already owns progress (the native session has progress persistence disabled), so the hook writes only the admin history row, not watch progress. The ABS handler's existing live-session sync still clears the row from the live sessions view.Watch time comes from the native session's measured progress, so it reflects the ABS sync heartbeats rather than the end position.
The existing close test now also checks that the finish hook runs once for the closed session.
Validation
gofmt: clean on the changed files.go test ./internal/audiobooks/...: Cleanmake lint-changed: CleanEvidence
No before image as nothing was recorded before.
Build is 8c90021+dirty
Surface and build: web admin, Playback History, after playing and closing a book in an Audiobookshelf client.
Risks
Plays of multi-file audiobooks record the first file's duration, since the native session is started on the first file while the ABS position covers the whole book.
completedcan therefore be set early for those books. Abandoned ABS sessions already record history this way through expiry; this change makes it apply to closed sessions too.Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Run finish hooks on Audiobookshelf session close to record plays in admin history
Changes ABS native-session cleanup so closing a playback session calls
FinishSessionwith the request context instead ofStopSession. The finish hooks write the admin playback history row before the existing post-close sync runs.PlaybackSessionManagerinterface in native_sessions.go: the stop contract is replaced by a context-aware finish contractTestHandleSessionCloseFinishesNativePlaybackSessionand now asserts a registered finish hook runs exactly oncePlaybackSessionManageroutside this package must switch from the removedStopSessionmethod toFinishSessionMacroscope summarized cedf888.