Repository navigation
fix(audiobooks): track Audiobookshelf plays accurately in admin sessions and history - #3108
Conversation
…in admin history An Audiobookshelf play mirrors into a native playback session started on the book's first file, while its syncs report the position in the whole book. Admin Playback History took the first file's length as the duration, so a multi-file book was marked completed once the listener passed the end of the first track. The ABS play start now records the book's total length on the session, and the history row uses it. Closes Silo-Server#3098 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… carries
Audiobookshelf clients send their last position and listening time in
the body of POST /session/{sid}/close, and Audiobookshelf applies it as
a final sync before closing. Silo ignored the body, so everything after
the last periodic sync was lost from the resume position, the session's
listening time and the admin Playback History row written at close. A
close with a body now applies it like a sync first; an empty body still
closes without one.
Closes Silo-Server#3099
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… through local sessions Some Audiobookshelf clients, Plappa and Prologue on iOS among them, never open a session with /play. They stream the files directly and post their local session to /session/local or /session/local-all every few seconds while playing. Silo kept the resume position from those posts, but the play never appeared in admin live sessions or Playback History. A local session updated within the last two minutes is now mirrored into a native playback session, as a /play session is. Its ID is derived from the account, profile and client session ID, so every report of one play reaches the same session and history row. It carries the book's length and the client name from deviceInfo. These clients send no stop, so the session takes its own 90-second idle window: the play ends 90 seconds after the last report. Older reports (offline listening synced late, or an old session sent again) still only move the resume position. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…, and name their clients An Audiobookshelf session sync carries timeListened, the seconds played since the previous sync. Admin watch time instead inferred playing from how far the position moved, which drops a whole sync interval whenever it contains a seek and the first interval when a client resumes from its own saved position. With AudioBooth, a 2.5-minute listen around a scrub was recorded as 1:43. A sync's timeListened is now credited directly, capped at the time that actually passed so a client cannot claim more. Sessions started with /play were also all named "Audiobookshelf". The deviceInfo clients send in the /play body now names them, as it already does for local sessions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eport A play reported only through /session/local was measured from its first report, so the stretch before it (ten seconds with Plappa) was never counted. The native session now starts measuring at the startTime and startedAt the client reports, and the usual seek check still decides whether that stretch was played. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sions The live sessions view measured an Audiobookshelf play's whole-book position against the session's first file, so a book whose first track is 44 seconds showed 57:09 / 0:43. The session's timeline length now syncs to playback_sessions_sync, and the view uses it in place of the file's duration when it is set. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Local-session plays credit the change in the client's running listening total, capped at the time that passed, instead of inferring it from position. Listening above 2x speed now counts. - A play is measured from the client's start only when it began moments ago. A session rebuilt for an older play takes the client's total as its baseline, so a later skip is not credited. - Local-session plays are report-only and never count toward stream limits: the client may be playing a downloaded copy. - A close's final sync is best effort, so a body that cannot be read or a sync that fails still closes the session; a session already closed applies no final sync. - A local-all batch syncs the admin views once, deviceInfo without a version keeps the header's version, and the book-length sum is shared. Co-Authored-By: Claude Opus 5.5 <[email protected]>
file_duration is the length position_seconds is measured against. For a multi-file Audiobookshelf book that is now the whole book rather than the session's first file, so the field's description says so. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cking
- A local session that reports no listening total is measured from its
position again, instead of counting nothing.
- Only the highest listening total a session has seen is its baseline,
so a late or repeated report cannot count the same listening twice.
- A close body without a currentTime ({}, null) is no final sync rather
than a sync to position 0.
- A final sync that fails on the session row still writes the resume
position and the native session's position.
- When deviceInfo names the client, the version comes only from it.
- A live report looks its session up once, and whether it started one
is returned beside the ABS result instead of stored on it.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
|
| h.deps.NativeSessions.RegisterReconstructed(native) | ||
| return true |
There was a problem hiding this comment.
Unbounded session-map growth occurs because RegisterReconstructed admits every distinct local-session ID without admission checks, while ReportOnly excludes these entries from stream limits; an authenticated user with access to one audiobook can repeatedly submit fresh IDs and current updatedAt values to accumulate arbitrarily many live entries, consuming memory and amplifying full-session synchronization and database reconciliation. Enforce a separate per-principal cap for report-only sessions atomically with registration.
Prompt for LLM
File internal/audiobooks/abs/native_sessions.go:
Line 242 to 243:
Unbounded session-map growth occurs because RegisterReconstructed admits every distinct local-session ID without admission checks, while ReportOnly excludes these entries from stream limits; an authenticated user with access to one audiobook can repeatedly submit fresh IDs and current updatedAt values to accumulate arbitrarily many live entries, consuming memory and amplifying full-session synchronization and database reconciliation. Enforce a separate per-principal cap for report-only sessions atomically with registration.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Agreed: report-only sessions are outside stream limits, so nothing capped them. Fixed in 7ed5167. SessionManager.RegisterReportOnly counts the account's live report-only sessions and registers the new one only while there are fewer than ten. The check and the insert happen under the manager's lock, so they're atomic. A report over the cap still saves the resume position; the play just isn't tracked. A session already live under the same derived ID always gets its update, so a cap reached later never cuts off a play already being tracked. These sessions also end 90 s after their last report, so a client can't keep a slot without reporting.
There was a problem hiding this comment.
The fix you describe in 7ed51674b addresses the original concern: the atomic per-account cap bounds live report-only sessions without consuming stream slots, while existing sessions keep receiving updates and rejected registrations still preserve resume progress.
The 90-second idle expiry also releases inactive slots. Based on that description, this resolves the reported unbounded live-session growth.
| if began, ok := sess.beganRecently(now); ok { | ||
| native.StartedAt = began | ||
| } else { | ||
| native.ReportedListening = sess.TimeListening |
There was a problem hiding this comment.
Listening-time undercount occurs because new local sessions without a positive timeListening never seed Watch from startTime and startedAt, so the first UpdateProgressReported call initializes Observe at the current position and omits prior listening. Initialize the watch baseline from the reported start position and recent start timestamp so the supported position-only fallback retains the first interval.
if began, ok := sess.beganRecently(now); ok {
native.StartedAt = began
native.Watch.Observe(sess.StartTime, false, began)
} else {
native.ReportedListening = sess.TimeListening
}Prompt for LLM
File internal/audiobooks/abs/native_sessions.go:
Line 237 to 240:
Listening-time undercount occurs because new local sessions without a positive timeListening never seed Watch from startTime and startedAt, so the first UpdateProgressReported call initializes Observe at the current position and omits prior listening. Initialize the watch baseline from the reported start position and recent start timestamp so the supported position-only fallback retains the first interval.
Suggested Code:
if began, ok := sess.beganRecently(now); ok {
native.StartedAt = began
native.Watch.Observe(sess.StartTime, false, began)
} else {
native.ReportedListening = sess.TimeListening
}
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Agreed. Fixed in 7ed5167, as suggested. When the client says the play began within the last two minutes, the new session's watch time is started at the reported startTime and startedAt. A client that sends no timeListening now gets the stretch before its first report counted by the normal seek check. Clients that send a total are unaffected, since crediting the total already used startedAt as the start. Added a "new play without a total" test case.
There was a problem hiding this comment.
Thanks—based on your description, 7ed5167 addresses this finding. Seeding the watch baseline from startTime and startedAt preserves the first interval for position-only clients while leaving reported-total accounting unchanged.
The “new play without a total” test covers the reported regression. No further change is needed for this suggestion.
| // The final sync needs the same item access a periodic one does, and | ||
| // none applies to a session already closed: a repeated close must not | ||
| // send its stale position to the user's other clients. | ||
| if final != nil && sess.ClosedAt == nil && h.audiobookVisible(r.Context(), a, sess.ContentID) { |
There was a problem hiding this comment.
Finalization data loss and a race condition arise from the ClosedAt snapshot check: it discards a later close with a further final position that could improve the same play's listening time and history, yet lets concurrent closes both observe an open session and apply final syncs before either closes it. Use a serialized, session-ID-keyed finalization operation that rejects duplicate or stale submissions, accepts legitimate advances, and updates resume/native playback state only for the accepted finalization.
Kody rule violation: Make playback finalization monotonic and consume dispatch state only after success
Prompt for LLM
File internal/audiobooks/abs/progress.go:
Line 441:
Finalization data loss and a race condition arise from the ClosedAt snapshot check: it discards a later close with a further final position that could improve the same play's listening time and history, yet lets concurrent closes both observe an open session and apply final syncs before either closes it. Use a serialized, session-ID-keyed finalization operation that rejects duplicate or stale submissions, accepts legitimate advances, and updates resume/native playback state only for the accepted finalization.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
The race is real. Two closes could both see the session open and both apply a final sync, adding the listening time twice. Fixed in 7ed5167. The final sync and the close are now one UPDATE … WHERE closed_at IS NULL that reports whether that request closed the session. Only the request that closes it updates the resume position and the native session, and notifies other clients. Every other close, whether concurrent, retried or late, returns 204 and changes nothing. Checked on a test server: two closes with different positions left the first close's position and listening time in the history row.
▎
▎ I haven't made a later close with a further position replace the first one. Once a session is closed the play is over: the native session and its history row are finished, and a close that arrives after that isn't new listening on that play. The resume position already never moves backwards.
There was a problem hiding this comment.
Agreed. Based on your description of 7ed51674b, the atomic UPDATE … WHERE closed_at IS NULL resolves the concurrent-close race: only the winning request applies the final sync and triggers the resume/native-session updates and notifications.
My original suggestion was too broad in requiring later closes with a further position to be accepted. First-close-wins is a valid finalization contract: once the play is closed, retries and late requests should be no-ops, not reopen or revise its history. A greater position alone does not establish new listening.
The reported two-close test supports that behavior. I would consider this finding addressed as described; accepting later advances is not necessary.
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
e0138407-bf70-4b08-a2fd-8d466aacb3ed
Files selected for processing: 21-
cmd/silo/session_sync.gocontracts/api/v2/openapi.jsoninternal/api/handlers/playback.gointernal/api/handlers/playback_sessions.gointernal/api/handlers/playback_test.gointernal/apiv2/admin_sessions.gointernal/apiv2/profiles.gointernal/audiobooks/abs/native_sessions.gointernal/audiobooks/abs/native_sessions_test.gointernal/audiobooks/abs/play_response.gointernal/audiobooks/abs/progress.gointernal/audiobooks/abs/session_local.gointernal/audiobooks/abs/session_local_test.gointernal/playback/session.gointernal/playback/session_activity.gointernal/playback/session_remote_transport_test.gointernal/playback/watch_time.gointernal/playback/watch_time_test.gointernal/worker/reconciler.gomigrations/sql/20261026180735_playback_session_timeline_duration.sqlweb/src/api/v2/schema.ts
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
-
…lo-Server#3108 - Keep the frozen /api/v1 session file_duration as the file's duration; only the v2 session reads report the whole book's length. - Cap the reported plays one account can have live at ten. They are outside stream limits, so nothing else bounded them. - Close an Audiobookshelf session and apply its final sync in one statement that reports whether this request closed it. Of concurrent or repeated closes only that one updates the resume position, the native session and other clients. - Measure a new reported play from where and when the client says it began even when it reports no listening total. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
|
|
The Evidence page covers Activity and Playback History at desktop and phone width, but it does not show the changed resume behavior: a final session-close sync now updates the resume position. Please add a before-and-after capture of the affected client resuming from that position, or matching before-and-after API response excerpts for the resume position. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
There was a problem hiding this comment.
Actionable comments posted: 2

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
6a56a7cf-8b37-49ca-8171-cbe5d4e23ae5
Files selected for processing: 10-
internal/api/handlers/playback_sessions.gointernal/apiv2/admin_sessions.gointernal/apiv2/profiles.gointernal/audiobooks/abs/file_handler_public_track_test.gointernal/audiobooks/abs/native_sessions.gointernal/audiobooks/abs/progress.gointernal/audiobooks/abs/session_local_test.gointernal/audiobooks/abs_playback_session_store.gointernal/playback/session.gointernal/playback/session_remote_transport_test.go
Files skipped from review as they are similar to previous changes: 1-
- internal/api/handlers/playback_sessions.go
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.
-
- A sync whose session row fails to save writes nothing else: the client gets an error and syncs again, and the retry would count the same listening twice. - A sync's or close's listening time is bounded to [0, 1 day] before it is added to the session's stored total. - Remove the breaking-change approvals Silo-Server#3050 added; they match no change now that Silo-Server#3050 is in main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
|
|
The v2 household session response now returns the whole-book timeline in Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
Added to the evidence page: before-and-after Audiobookshelf API excerpts for the same requests on both builds. A regular account sets progress to 600, opens a session, syncs at 700, then closes with a final position of 900. Reading the progress back gives 700 on main (48b895f) and 900 on this branch (77749bc). |
|
Think this should be ready :) |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

Minor · Preserve absent listening fields separately from explicit zero. · native_sessions.go:151-158
internal/audiobooks/abs/native_sessions.go:151-158
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick winPreserve absent listening fields separately from explicit zero.
A sync body with
currentTimebut no listening field reachesUpdateProgressListenedwithlistened == 0.WatchTime.Creditthen drops the position interval while advancing its baseline. The mirrored native session carries that undercount into the admin historyWatchvalue.Do not route every zero through
Observe. An explicittimeListening: 0ortimeListened: 0is accepted by this request type and means that the client reported no listening.Observecould count a forward seek as playback. Preserve field presence and useUpdateProgressonly when neither listening field was supplied.Suggested fix
type syncPayload struct { CurrentTime float64 `json:"currentTime"` // Accept both spellings: real ABS clients send "timeListening"; an older // silo-plugin draft used "timeListened". UnmarshalJSON merges them. - TimeListening float64 `json:"timeListening"` - TimeListened float64 `json:"timeListened"` + TimeListening *float64 `json:"timeListening"` + TimeListened *float64 `json:"timeListened"` } // timeDelta returns the accumulated listening time from whichever spelling // the client used. Both fields are tried; non-zero wins. It is bounded to // [0, maxSyncListeningSeconds], so a client cannot lower the stored total or // overflow it. func (p syncPayload) timeDelta() float64 { - delta := p.TimeListened - if p.TimeListening != 0 { - delta = p.TimeListening + var delta float64 + if p.TimeListened != nil { + delta = *p.TimeListened + } + if p.TimeListening != nil && *p.TimeListening != 0 { + delta = *p.TimeListening } return min(max(delta, 0), maxSyncListeningSeconds) } +func (p syncPayload) hasListening() bool { + return p.TimeListening != nil || p.TimeListened != nil +} + @@ - h.updateNativePlaybackProgress(ctx, sess.ID, p.CurrentTime, p.timeDelta()) + h.updateNativePlaybackProgress(ctx, sess.ID, p.CurrentTime, p.timeDelta(), p.hasListening())-func (h *Handler) updateNativePlaybackProgress(ctx context.Context, sessionID string, position, listened float64) { +func (h *Handler) updateNativePlaybackProgress(ctx context.Context, sessionID string, position, listened float64, listeningReported bool) { if h == nil || h.deps.NativeSessions == nil || sessionID == "" { return } - if err := h.deps.NativeSessions.UpdateProgressListened(sessionID, position, listened); err != nil { + var err error + if listeningReported { + err = h.deps.NativeSessions.UpdateProgressListened(sessionID, position, listened) + } else { + err = h.deps.NativeSessions.UpdateProgress(sessionID, position, false) + } + if err != nil {

Minor · Do not use incomplete metadata as the whole-book duration. · native_sessions.go:205-253
internal/audiobooks/abs/native_sessions.go:205-253
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick winDo not use incomplete metadata as the whole-book duration.
bookDurationSecondsignores zero-duration files while summing the others. A multi-file book such as[3600, 0]therefore gets a positiveTimelineDurationof3600in both native-session paths. Admin history then uses that partial value and can mark playback complete after the first file, before the book ends.Treat the whole-book duration as unknown unless every file has a positive duration. Make that state explicit so admin history omits completion and does not fall back to the first file's duration.

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
bb6a7832-60db-406d-80df-97a26fb75e8c
Files selected for processing: 11-
cmd/silo/session_sync.gocontracts/api/v2/fixtures/list_home_sections_item_limit_out_of_range.jsoncontracts/api/v2/fixtures/list_library_sections_item_limit_out_of_range.jsoncontracts/api/v2/openapi.jsoninternal/api/handlers/playback_sessions.gointernal/api/handlers/playback_test.gointernal/apiv2/admin_sessions.gointernal/apiv2/profiles.gointernal/playback/session.gointernal/worker/reconciler.goweb/src/api/v2/schema.ts
Files skipped from review as they are similar to previous changes: 1-
- web/src/api/v2/schema.ts
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
-
# Conflicts: # internal/audiobooks/abs/native_sessions.go # internal/audiobooks/abs/progress.go # internal/playback/session.go # internal/playback/session_activity.go # internal/worker/reconciler.go
|
Should be good here. |
Quick104
left a comment
There was a problem hiding this comment.
Review of df5b940 (this branch with current main merged in; I pushed that merge because main had changed progress.go and session.go underneath it).
The whole-book length, the close's final sync and the reported listening time work on a single server: on a dev sandbox, a /play session that synced three times across a 200-second scrub and then closed with a final body recorded 900 s of book length and 40 s played, which is right. The findings below are the multi-server gaps in those three parts, which I'm fixing on this branch, and two problems in the tracking of plays reported only through /session/local, which need a maintainer decision.
🤖 Claude Code (claude-opus-5-5)
…multi-server close On more than one API server, Audiobookshelf plays lost what this branch records: - A close that reaches a server without the native session records the play through FinishDetached, which read neither the book length synced to playback_sessions_sync nor the close's final sync. LiveSession now reads timeline_duration_seconds, the detached snapshot takes it, and the close applies its accepted final sync to the row it hands to the stop. - A /play sync credited only its own timeListened, so a sync handled elsewhere lost its listening. Syncs now pass the row's running total to UpdateProgressReported, which credits how far it rose since the last total the session saw; UpdateProgressListened goes. A report that does not raise the total no longer moves the listening baseline, so a delayed lower total cannot shrink the next rise's cap. The AdminPlaybackSessionView doc comment is back on the alias. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
|
Review summary (head
|
… follow-up Plays that clients report only through /session/local were mirrored into report-only native sessions held in one server's memory, outside the playback lifecycle every other play uses. A play resumed after its idle expiry reused an ID whose lifecycle row was already stopped, so Activity hid it for up to 25 hours; a server that died mid-play lost its history row; and servers could hold competing copies of one play. This removes that tracking (ReportOnly, IdleGrace, RegisterReportOnly and the /session/local mirroring) so the whole-book length, the close's final sync and the reported listening time can land on their own. Local sessions move the resume position, as before. A follow-up rebuilds the tracking on the lifecycle path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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:
|
Problem
Closes #3098
Closes #3099
Related issue: N/A
Validation tasks: none
Admins can't trust what Activity and Playback History show for Audiobookshelf-compatible plays, in three ways:
This change measures plays against the whole book, applies the close's final sync, and counts the listening time clients report.
Plays that apps report only through
/session/local(Plappa, Prologue) still don't appear in Activity or Playback History; #4244 tracks that. An earlier version of this PR tracked them, and the maintainer review took that part out (see Risks).Approach
Session.TimelineDuration, because ABS positions are in the whole book while the session runs on the first file. Playback History uses it. Activity readsplayback_sessions_sync, so a migration adds a nullabletimeline_duration_secondscolumn, and the live query prefers it to the file's duration.PATCH /session/{sid}sync before closing, as Audiobookshelf does. This is best effort: a body that can't be read, or a sync that fails, still closes the session, and a session that is already closed applies nothing.timeListened, the seconds since the previous sync. The ABS session row keeps the running total, and the native session credits how far that total rose past the highest one it saw, so a sync another server handled still counts and a late or repeated one counts nothing. A client that never sends listening time is measured from its position, as before.deviceInfoclients send with/playnames the session, so Activity shows "AudioBooth iOS 1.12" instead of "Audiobookshelf".No API shape changes. For these sessions,
file_durationon the admin and household session reads now carries the book's length, and its OpenAPI description says so. jellycompat doesn't change. The Apple and Android clients use the native API, so they need no change.Validation
gofmtare clean,go veton the changed packages is clean, andlint-changed(golangci-lint v2.12.2) reports 0 issues.internal/playback,internal/audiobooks/...,internal/worker,internal/apiv2,internal/api/handlersandcmd/silopass. New tests cover the book length in a history row, the close's final sync (including an unreadable body, an already-closed session and a close on another server), and crediting reported listening and its caps.file_durationdescription. The web tests andverify-apiv2-contractwere not run; the web change is a generated comment.goose validateandmigrationcheckpass.verify-local-pathspasses.9d371b0,dcdec18): current main merged in; a close on another server now keeps the book length and final sync in history;/playsyncs credit the session's running listening total, so a sync handled by another server still counts; tracking of local-session-only plays moved to Track Audiobookshelf plays that apps report only through local sessions #4244.make test-goand the Postgres DB-contract tests, since there was no local database. The migration ran on a test server with existing sessions and history.dcdec18: a scripted ABS client on a 3-file book (15:00) resumed at 7:12, synced every 10 s for a minute and closed with a final sync. Activity showed7:32 / 15:00and history1m 5s of 15m 0s, Partial. On main, the same steps show7:32 / 5:00and1m 0s of 5m 0s, Completed.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-3108/
Surface and build: web admin Activity and Playback History at desktop width, on a dev sandbox. Before is
feae205b(main); after is this branch atdcdec189. The pairs show Activity during an ABS play and Playback History after it closes.Risks
playback_sessions_sync; the down migration drops it. Rows written before it read as the file's duration, as today./session/localkept them in one server's memory, outside the playback lifecycle. A play that resumed after its 90-second idle expiry was hidden from Activity for up to 25 hours, a server dying mid-play lost its history row, and servers could hold competing copies. It was removed indcdec18; Track Audiobookshelf plays that apps report only through local sessions #4244 rebuilds it on the lifecycle path.Checklist
AI Disclosure
/code-review, high effort) reviewed the branch diff against main for correctness in two passes. The first pass found ten issues. The main ones were time spent over-counted after an idle expiry and not counted above 2× speed, the live view still using the first file's length, closes that failed on a bad body, and report-only plays taking stream slots. All were fixed except two: dependence on the device clock, recorded above under Risks, and sharing the sync handler's access check, which would have merged its separate 403 and 404 responses. The second pass found ten more. The main ones were no time counted for clients that send no listening total, an empty close body syncing position 0, out-of-order reports counting listening twice, and the undocumented change tofile_duration. All were fixed except two: plays first seen mid-play, recorded above under Risks, and folding the duration check into the existing snapshot comparison, which a linter flags. The device-clock and mid-play risks left with the local-session tracking. A maintainer review ofdf5b940(Claude Code, claude-opus-5-5, with a cross-check by Codex gpt-6.1-sol) found the multi-server close and listening-time gaps, fixed in9d371b0, and the local-session tracking problems that led to its removal indcdec18.Note
Fix Audiobookshelf play tracking with book timeline durations and final sync data
currentTime. Final position and listening time are applied atomically in the close SQL, and the final sync is mirrored only when this call actually closed the session. Repeated or concurrent closes report false.timeline_duration_secondscolumn onplayback_sessions_sync.ClosePlaybackSessionin abs_playback_session_store.go changes theABSPlaybackSessionStoreinterface signature (final-sync data plus a boolean return). Sync listening-time deltas are clamped to 0–1 day insyncPayload.timeDelta, and admin history entries switch to timeline duration when positive, changing reported durations for multi-file books.Macroscope summarized dcdec18.