Skip to content

fix(playback): keep the watch time after the last report when an admin stops - #4623

Open
Quick104 wants to merge 9 commits into
fix/4618-detached-stop-seekfrom
fix/4615-admin-stop-watch-time
Open

Quick104 wants to merge 9 commits into
fix/4618-detached-stop-seekfrom
fix/4615-admin-stop-watch-time

Conversation

@Quick104

@Quick104 Quick104 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #4615
Related issue: N/A
Validation tasks: unavailable (the v1.0 board could not be read from this session; see Validation)

Other clients: Apple N/A (no client change needed); Android N/A (no client change needed); Roku N/A (no client change needed)

When an administrator stops a session and the player confirms over the control socket, history lost the watch time between the player's last progress report and the stop. Players report every 10 seconds, so up to that much of each admin-stopped play went missing from played_seconds, and end_position_seconds stayed at the last report. On a Silo dev deployment, a 16.8 s play stopped by an administrator recorded 10.0 s.

This is stacked on #4622 and targets its branch; review that one first.

Approach

The player's confirmation carries no position, so the server estimates it. When the player confirms an admin stop, the stop submits a final sample that advances where the session last saw the player playing by the time from that sighting to when the stop was sent. The sighting is the latest observation of the play's watch-time measurement: a progress report, a confirmed resume, or a seek replan. The estimate reads the position and pause state from the measurement itself, so it can't drift from the measurement that later judges it, and it never runs past the end of the file.

Nothing is added when:

  • the player is paused, or a pause it confirmed is still being applied when the stop arrives;
  • the session last saw the player more than 12 s before the stop (one report interval plus slack), so it has missed a report;
  • the play has no progress report yet;
  • another API server accepted the latest report and the session can't place it against what it measured since. Whether the session saw a report is told by its sequence, not by comparing two servers' clocks.

A report another server accepted that the session never saw is measured first, at the time it was accepted. When the measurement saved on the session's lifecycle row is newer than the session's own, the estimate starts from it, as the finalizer would, and the finalizer is handed the measurement the estimate came from. The finalizer already measures a final sample newer than the last report, so watch time and the end position move by the same amount.

If the player's own stop reaches the attempt first, its exact position still wins, as before. Adding the position to the stop result instead would be exact but needs a protocol field and client changes; this fixes current clients without either. The admin API docs describe the exception.

Validation

  • Reproduced live on a dev sandbox built from the head with a scripted native player: progress every 10 s, admin commands confirmed at once. A stop 6.7 s after the report at 10 s records 16.74 s played and an end of 16.74 for a 16.77 s play (main recorded 10.02 s for 16.78 s). A player that reported once at 10 s and was stopped at 40 s ends at 10.05 s: nothing added. An admin pause at 12 s, resume at 14 s and stop at 16.75 s records 12.72 s; the play between the report and the pause isn't counted, because the session measures a confirmed resume at the last report's position. A player that reported a pause at 12 s records 12.02 s.
  • TestRealtimeConfirmedStopCreditsPlayAfterTheLastReport (10 cases), TestRealtimeConfirmedStopAfterAPendingPauseAddsNothing and TestRealtimeConfirmedStopKeepsANewerSavedMeasurement: every case that changes behavior fails on the head before review (ae363a1), for example a seek back from 900 to 895 recorded 14 s ending at 909 instead of 8 s ending at 903, and a silent player 12 s ending at 912 instead of nothing. The playing and paused cases pass on both. Two saved-measurement cases guard a regression an intermediate review commit introduced. TestRealtimeConfirmedStopKeepsABridgePlaysMeasurement records 0 s on f8b4545ab and 10 s on fix(playback): don't count a seek before a detached stop as watch time #4622's head and on this head.
  • go test ./internal/api/handlers/ ./internal/playback/.... Lint is left to CI (golangci-lint wasn't installed where the review ran).
  • Not checked: the v1.0 validation board (the session's GitHub token lacks read:project).

Evidence: https://evidence.siloserver.org/r/silo-server/4615-admin-stop-watch-time/

Risks

The credit is an estimate. A player that was buffering, or paused without reporting it, within 12 s of the stop can be credited time it didn't play, and the resume position moves with it. Near the end of a file that can cross the watched threshold. Before this change the same play lost up to 10 s instead.

When another server accepted the latest report, the estimate compares two servers' clocks. Skew can shift the credit within the 12 s cap, and a report placed on the wrong side of a seek the session measured can put the end position at the pre-seek report.

Some cases add nothing that could have: a stop right after a confirmed resume whose provider scrobble is still running, and a session rebuilt after a restart before its next report. A pause confirmation whose receipt read failed is never applied to the session, so a stop after it can be credited as playing.

Admin ends the player doesn't confirm (terminate, or a stop that falls back after its deadline) still end at the last report.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

Council review

Rounds: plan round on 4eb4d4a86, background review of 2063b9aca, then five maintainer-review rounds; last reviewed 6352b1bcc.

Member Plan Background (2063b9a) R1 (ae363a1) R2 (0ee51af) R3 (cc7adbc) R4 (498ea90) R5 (6352b1b)
Sol (gpt-6.2-sol, xhigh) no score 5/10 4/10 5/10 6/10 6/10 7/10
Opus (claude-opus-5-5, high) no score 7/10 6.5/10 7/10 8/10 8/10 8/10
Gemini (gemini-4-neon, xhigh) no score 6/10 4/10 5/10 8/10 8.5/10 9/10

Fixed in review: the estimate now starts from the latest observation (confirmed pause and resume, resume after a paused report, seek replan, a retried report after a seek); a report another server accepted is measured first, told by sequence; a newer saved measurement is used and carried to the finalizer; a pending pause confirmation adds nothing; a silent player adds nothing; the reads ahead of the stop write are bounded and the write keeps its own deadline; the admin API docs. After round 5, 290b6a429 applies that round's repairs: it measures an unseen report when finishing a stop another request took, carries the estimate's measurement only after the stop write succeeds, and strengthens the failed-read test. f8b4545ab then moves the final-sample code into its own function for the lint, with no behavior change. 61bcd5c3b fixes a regression from 290b6a429: a confirmed stop of a bridge-only play recorded no watch time, because an empty measurement was carried to the finalizer. None of the three was reviewed by the council again.

Answered: an exact player position needs a protocol field; terminate and deadline fallbacks stay out of scope; cross-server races that need another server to save in a sub-second window are left as described in Risks.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code, GitHub CLI, T3 Code delegated reviews (Codex, Claude, Antigravity)
  • Model(s): claude-opus-5-5 (implementation and review fixes), gpt-6.2-sol, gemini-4-neon (review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: see Council review.

Note

Credit up to 12s of watch time after the last report on admin-confirmed stop

  • When an admin confirms a realtime stop, the handler now records when the stop command was sent (playback_realtime.go) and can credit play time from the latest playing observation up to that send time, capped at 12 seconds and at the known media duration.
  • Estimation is skipped when the player is paused, the latest report cannot be ordered against the session copy, a pause/resume result is still pending, or another realtime result is still queued for the session (session_ws.go).
  • The measurement anchor can fall back to a newer saved measurement when the live session copy lacks it; a bounded read error disables estimation.
  • Bridge-only final positions are preserved when no sequenced sample exists.
  • Adds broad synctest coverage for playing, paused, pause/resume, seek, retry, cross-replica, and pending-pause scenarios, plus docs in admin-api.md.
  • Behavioral Change: stopped sessions may now record slightly higher watch time and a later end position than before; check playedSinceLastReport and realtimeStopFinal in playback_realtime.go if history totals look unexpected.

Macroscope summarized 61bcd5c.

…n stops

When an administrator stops a session and the player confirms over the
control socket, the confirmation carries no position, so the play ended at
the player's last progress report. Players report every 10 seconds, so up to
that much of each admin-stopped play was missing from played_seconds and the
end position.

The admin stop now submits a final sample that advances the last report by
the time from when the attempt accepted it to when the stop was sent, at most
12 seconds (the report interval plus slack) and never past the end of the
file. A player whose last report was paused, or whose pause an administrator
confirmed, gets nothing added. When the player's own stop reaches the
attempt first, its exact position still wins.

Closes #4615

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 20, 2026
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

The realtime admin-stop path now uses command send time and playback state to estimate eligible playback after the latest progress report. It can record a final sample and update stop-history position. Tests and API documentation cover timing, pause, and report conditions.

Changes: Admin stop history

Layer / File(s) Summary
Capture and pass stop timestamps
internal/api/handlers/playback_realtime.go, internal/api/handlers/session_ws.go
Realtime command records capture SentAt. The WebSocket handler passes it to stop recording, except when another realtime result is pending.
Estimate and finalize the stop sample
internal/playback/session.go, internal/playback/watch_time.go, internal/api/handlers/playback_realtime.go
Stop finalization selects a usable watch-time anchor and may add a final sample for recent, unpaused playback. The position is capped at a known media duration.
Validate and document stop accounting
internal/api/handlers/playback_service_test.go, internal/api/handlers/session_ws_pause_state_test.go, docs/admin-api.md
Tests cover timing, pause and report ordering, pending pauses, and saved measurement reads. The API documentation describes when confirmed stops can add playback after the last report.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant playbackCommandRecord
  participant handleRealtimeClientMessage
  participant recordRealtimeStoppedSession
  participant realtimeStopHistory
  playbackCommandRecord->>handleRealtimeClientMessage: provide stop result with SentAt
  handleRealtimeClientMessage->>recordRealtimeStoppedSession: pass SentAt or zero when another result is pending
  recordRealtimeStoppedSession->>realtimeStopHistory: request stop history finalization
  realtimeStopHistory->>realtimeStopHistory: resolve watch-time anchor and derive eligible final sample
Loading

Possibly related issues

Possibly related PRs

  • Silo-Server/silo-server#4552: Both PRs address watch-time accounting and history position for administrator stops; this PR uses the saved or live measurement as an estimate anchor.
  • Silo-Server/silo-server#2821: This PR adds the watch-time measurement that the admin-stop estimate uses.

Suggested reviewers: rhainland, brady3035

Merge Risk: Low · up to 61bcd

Confirmed admin stops now credit play time after the last progress report. In a narrow case, a newer saved watch measurement can be dropped and slightly less watch time recorded if a second saved-watch read fails. The impact is bounded and the fix is small, so this can be resolved before or shortly after merge.

Security architecture risk: Low · up to 61bcd

A confirmed stop still affects only the matching playback session. The remaining risk is to history accuracy: if another server finishes recording the stop, it can preserve the final position but calculate a different amount of watched time.

Retained concerns

  • Low · reliability · inferred: The stop receipt persists the estimated position but not the measurement used to derive it. If the worker is interrupted after the stop write, a replay can finalize the same position against an older saved measurement. The lease protects who finalizes the stop, but does not make the resulting played_seconds independent of who finalizes it.
Security review details

Security Blast Radius

  • inferred — The changed path affects the matched session's attempt and history, and can change the final position or completion status passed to that session's configured watch providers. The acknowledgement cannot select another session, profile, or media file for the estimate.

Trust Boundaries and Controls

  • observed — The existing acknowledgement check requires a remembered command for the socket's session and a completed result before stop processing. The estimate uses a timestamp recorded at server dispatch, not a timestamp or position supplied in the acknowledgement.

Resilience and Maintainability Implications

  • observed — A pending confirmed pause or resume, a paused measurement, or a stale or unreconcilable observation suppresses extrapolation without blocking the stop. These controls bound the estimate; they do not recover the original measurement after worker loss.

Hardening Proposals

  • proposed — Persist the inputs needed to replay an accepted estimate with its stop receipt, and use them only when that estimate actually won the sequence check. Validate that uninterrupted finalization and lease takeover produce the same history for the same receipt.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: admin-stop playback now keeps watch time accrued after the last progress report. It is specific and scoped to the playback fix. The changeset implements a server-side …
Linked Issues check Passed Issue #4615 requires that admin-stopped playback history include watch time up to the stop and advance end_position_seconds past the last progress report. The issue allows estimating time from the las…
Out of Scope Changes check Passed The changes introduced by this PR (playback_realtime.go, session_ws.go, session_ws_pause_state_test.go, playback_service_test.go, session.go, watch_time.go, and docs/admin-api.md) all connect to the a…
Description check Passed The description is detailed and directly related to the changeset. It explains the problem (watch time lost between the last player progress report and an admin-confirmed stop), the estimation approac…
Full details: Title check

Explanation

The title names the main change: admin-stop playback now keeps watch time accrued after the last progress report. It is specific and scoped to the playback fix. The changeset implements a server-side estimate of final watch time on confirmed admin stops, which matches the title.

Full details: Linked Issues check

Explanation

Issue #4615 requires that admin-stopped playback history include watch time up to the stop and advance end_position_seconds past the last progress report. The issue allows estimating time from the last report for clients that do not send a stop position. The reviewed head implements that estimate. The summary of playback_realtime.go adds a final sample when a confirmed admin stop arrives within 12 s of the latest measurement, the player is not paused, and the position advances. The sample is capped at media duration. The same sample advances the end position, and the session measurement is set to the anchor used. session.go (PositionSequence), watch_time.go (Latest), and session_ws.go (SentAt) supply the inputs. Skip conditions (pause, pending pause or resume, stale observation, unplaceable report, no progress report) are implemented as the issue's estimation option requires. The new tests named in the summary cover these cases. The whole-PR diff from merge base 7d22771 also contains the stacked #4622 commits (a278ee8, 7d22771 test), so the measurement behavior they provide is present at the reviewed head. Stack review evidence is unavailable, so the stacked #4622 behavior is established only from the whole-PR diff and summary, not from separate review. Test results and the sandbox run were reported by the author and were not re-executed here.

Full details: Out of Scope Changes check

Explanation

The changes introduced by this PR (playback_realtime.go, session_ws.go, session_ws_pause_state_test.go, playback_service_test.go, session.go, watch_time.go, and docs/admin-api.md) all connect to the admin-stop watch-time objective. Tests cover the estimate. The docs describe the new exception. The new session and watch-time accessors supply the anchor and sequence the estimate needs. The bridge-play repair in 61bcd5c carries the session's own measurement on a confirmed stop, which is part of the same stop-history path. No change was found that is unrelated to #4615. The #4622 commits in the whole-PR diff are stacked-branch work, and they are not counted as out-of-scope changes of this PR.

Full details: Description check

Explanation

The description is detailed and directly related to the changeset. It explains the problem (watch time lost between the last player progress report and an admin-confirmed stop), the estimation approach, the 12-second cap, the affected files and tests, the admin API docs update, validation steps, and risks. It matches the summary of changes in playback_realtime.go, session_ws.go, playback/session.go, watch_time.go, and the test files.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T03:48:36.809275Z 61bcd5c New commits
🔒 Security Review ✅ Completed 2026-11-23T03:50:11.071632Z 61bcd5c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@silo-triage silo-triage Bot added bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes priority: P2 Limited scope, workaround exists, or polish stacked Base is another open PR; merge in stack order named in the body labels Nov 20, 2026
@silo-triage

silo-triage Bot commented Nov 20, 2026

Copy link
Copy Markdown

The measurements cover the watch-time estimate and its controls, but the changed history values and end/resume position are user-visible. Please add before-and-after captures showing the affected admin playback history on desktop and phone-width web, plus the resulting resume position in a client, with each build identified. The current evidence collection contains no captures.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2063b9acab

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial review (gpt-6.2-sol, reviewed 2063b9a)

AI disclosure: Codex in T3 Code, using gpt-6.2-sol.

return nil
}
played := min(sentAt.Sub(record.SampleAcceptedAt), maxPlayedSinceLastReport).Seconds()
position := last.Position + played

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S3 (Medium). Keep an estimated position from latching completion. On a one-hour file at the default 90% threshold, a player can report 3235 seconds, stall for seven seconds, and then confirm the stop. The estimate becomes 3242 seconds and is persisted as the accepted position (playback_realtime.go:261, :268). The stop writer records completed history, clears the resume point, and latches watched state (watchstate/service.go:148, :163, userstore/threshold.go:46, userstore/pgstore/progress.go:133). A multi-episode file can also mark its later episodes watched (playback.go:1120). Keep the estimate for resume and watch time while basing completion and its side effects on player-reported progress.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changed; leaving this open for the maintainers. Since 0ee51af the estimate only applies to a player the session saw playing within 12 s of the stop, and it starts from that sighting, so a stall longer than one report interval no longer gets credit. A shorter stall just before the watched threshold can still cross it, as the PR's Risks section says. Keeping completion on reported progress alone would leave a player that really played past the threshold unmarked, which is today's behavior. The exact answer is a position in the stop result, which needs a protocol field and client releases.

🤖 Claude Code (claude-opus-5-5)

if last == nil || last.IsPaused || session.IsPaused || record.SampleAcceptedAt.IsZero() {
return nil
}
played := min(sentAt.Sub(record.SampleAcceptedAt), maxPlayedSinceLastReport).Seconds()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S4 (Low). Compare timestamps from a common clock. Postgres stores the wall time of the API replica that accepts the progress (planstore/postgres.go:443, :445). The stop timestamp is taken on the socket replica (playback_realtime.go:369). If the progress replica is four seconds behind, a real two-second gap becomes six seconds of estimated playback. Stamping progress with the API clock addresses comparisons with that API's own watch timestamps. This subtraction compares two API clocks. Use a shared time basis for the estimate or skip it when the clocks cannot be compared. Capture the stop timestamp where the socket write begins so time waiting for the lane does not shift the cutoff (admin_playback_commands.go:288, realtime_hub.go:209).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changed; leaving this open as a disclosed risk. Since 0ee51af, on a single server, or when the replica holding the session measured the latest report itself, the estimate compares two times from that replica's own clock. Two clocks are compared only when another replica accepted the latest report. Even then, skew can't add more than 12 s, and a gap that skew pushes past 12 s now credits nothing rather than the full cap.

🤖 Claude Code (claude-opus-5-5)

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial review (claude-opus-5-5, reviewed 2063b9a)

I checked the estimate against both StopAttempt stores, the finishStop measurement from #4622, the client-stop-wins path, and a progress sample landing between the attempt read and the compare-and-set. In that last case the estimate's sequence equals the new row sequence, so both stores ignore it and the newer real sample wins. The new tests pass at this head. Two notes, both low:

  1. Low: the 12 s clamp credits the case the estimate fits worst. See the inline comment on playback_realtime.go.

  2. Low, scope note (follow-up, not a blocker): terminate keeps the same undercount. Trigger: an admin uses terminate instead of stop on a playing session. Impact: history still ends at the last progress report, up to about 10 s short, which is the #4615 symptom. Evidence: terminateLocal (admin_playback_terminate.go) records the play through endSessionAsAdmin at revoke time from the live copy or the attempt row. notifyTerminated sends CommandTerminate through RealtimeHub.Send without rememberRealtimeCommand, so the player's confirmation never reaches recordRealtimeStoppedSession, and the CommandTerminate arm of the switch in session_ws.go never runs. Repair: if terminate should match stop, apply the same estimate where the admin end is recorded, using the revoke time as sentAt. Otherwise say in the PR that only stop is covered.

AI disclosure: written by an automated reviewer (Claude Code, claude-opus-5-5).

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial review (Gemini 4 Neon, reviewed 2063b9a)

Verified the claims, callers, preconditions, and multi-replica behavior of the post-report admin-stop credit against 2063b9ac (stacked on bc86d9e4). Checked callers of realtimeStopHistory, recordRealtimeStoppedSession, rememberRealtimeCommand, finishStop, observeEndSample, StopAttempt, and the lifecycle sweep, plus MemoryPlanStoreV3 vs Postgres parity, Jellyfin-compat, bridge plays, and terminate paths. Five verified findings are attached inline (four Medium behavioral/ordering issues and one Low test-coverage gap).

AI disclosure: reviewed by Antigravity (Gemini 4 Neon) in T3 Code.

Comment thread internal/api/handlers/session_ws.go Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ae363a179c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of ae363a1 (2063b9a with #4622's current head merged in).

Low: the admin API docs now describe the old behavior. docs/admin-api.md (the played_seconds paragraph of the session history section) says a stop without a final position, "such as an administrator stop the player confirms, ends the measurement at the last progress report." That is the case this PR changes: a confirmed admin stop now adds the time since the session last saw the player, and moves end_position_seconds with it. Anyone checking history numbers against the docs will see values the docs rule out. Repair: keep the general rule and name the confirmed admin stop as the one exception, with its limits (a paused player, a player last seen more than 12 s before the stop, or a pause still being applied gets nothing). I'm fixing this in a commit on this branch, so there's no need to change it yourself.

The other defects I verified already have threads from the earlier reviews, and I'm fixing them on this branch too. I'll reply in each with the commit:

  • The estimate starts from the attempt row's last report, so a confirmed pause and resume, a resume after a paused report, or a seek replan since that report is ignored. Verified with a seek back from 900 to 895 one second after the report and a stop at 9 s: the play records 14 s ending at 909, where 8 s ending at 903 is right.
  • A report another replica accepted is never measured before the estimate, so the estimate is judged against the socket replica's older measurement.
  • A pause the player confirmed is still being applied when the stop is confirmed, so the stop's snapshot reads as playing and 7 s of a paused player's time is credited.
  • A player whose reports stopped a minute earlier is credited the full 12 s.
  • The file lookup shares the stop write's budget and gates the estimate.

🤖 Claude Code (claude-opus-5-5)

… the player

The estimate started from the attempt row's last report, so a confirmed
pause and resume, a resume after a paused report, or a seek replan since
that report was ignored: a seek back from 900 to 895 and a stop at 9 s
recorded 14 s played ending at 909. It now starts from the live copy's
latest observation, after first measuring a report another replica
accepted that the copy never saw.

A player last seen more than one report interval plus slack before the
stop gets nothing added instead of the full 12 s, and so does a stop
confirmed while the player's pause or resume confirmation is still being
applied, since the stop's snapshot doesn't show it yet. The file lookup
gets its own budget and no longer gates the estimate. The admin API docs
describe the exception.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added size/L 200–499 added + deleted lines (all files); change volume, not priority. and removed size/M 50–199 added + deleted lines (all files); change volume, not priority. labels Nov 22, 2026
The estimate read the session's position next to its measurement's time,
and the two can disagree: a retried report after a seek moves the
position back without the measurement, and a session rebuilt after a
restart restores the measurement but not the position, so a stop could
end the play near zero. It now reads the position and pause state the
measurement last saw.

Whether the copy saw the attempt's latest report is now told by
sequence, not by comparing two servers' clocks. A report the copy never
saw is measured only when it is newer than what the copy measured since;
otherwise their order is unknown and nothing is added. The measurement
saved on the session's lifecycle row is used when it is newer than the
copy's, as the finalizer does, so the stop no longer hides it behind a
fresh measurement started at that report.

The file lookup moves after the attempt read with a 2 s budget, and the
result looks the file up again after finalization if it failed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: d3555522-43cd-480a-a31c-a0cfa65e56e9
Commits

Reviewing files that changed from the base of the PR and between 0ee51af and cc7adbc.

Files selected for processing: 5

  • docs/admin-api.md
  • internal/api/handlers/playback_realtime.go
  • internal/api/handlers/playback_service_test.go
  • internal/playback/session.go
  • internal/playback/watch_time.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Quick104 and others added 3 commits November 22, 2026 02:10
… it came from

When the saved measurement was the newer one, the estimate was built
from it but the finalizer read it again: a second read that failed
judged the final sample against the removed copy's older measurement,
and 880 s of saved play were recorded as 7 s. The stop now carries the
measurement it estimated from. A save it can't read skips the estimate,
since the finalizer may still find it, and a newer report it adopts now
sets the pause state even when the save is the anchor.

The saved-watch read gets the same 2 s budget as the file lookup, and
neither runs when nothing can be estimated. The admin API docs say a
session rebuilt after a restart adds nothing until its next report.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… an estimate

A stop confirmed while a pause was still being applied skipped the
anchor entirely, so a report another replica accepted was never
measured: the play ended at it with none of the play before it counted.
The copy is now brought up to that report whenever the row has one, and
only the estimate waits for the stop's send time.

The stop write gets its own deadline after the optional reads. An
already-stopped row skips the anchor, the file lookup runs only when the
session has no timeline duration, and a save that wins leaves the
session's snapshot as it was. A failed first read of the save is
covered by a test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… end

Skipping the anchor on a row another stop already took also skipped
measuring a report the copy never saw, so a worker finishing that stop
ended the play at the report without its time. Only the estimate now
needs an open row.

The measurement an estimate came from is carried to the finalizer only
once the stop write succeeds, so a failed write records the admin end
from the snapshot as it was. The failed-save-read test now starts from a
copy that measured a report, so it fails if a read error is treated as
no save.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 290b6a4296

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: a9886c15-987c-42f3-ad97-c5ef0ae4020b
Commits

Reviewing files that changed from the base of the PR and between cc7adbc and 290b6a4.

Files selected for processing: 3

  • docs/admin-api.md
  • internal/api/handlers/playback_realtime.go
  • internal/api/handlers/playback_service_test.go
Files skipped from review as they are similar to previous changes: 1

  • docs/admin-api.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

…ction

realtimeStopHistory passed the lint's complexity limit once the estimate
grew its reads, and the estimate test passed the function length limit.
The final sample now comes from realtimeStopFinal, and the test's plays
and its confirmation helper move out of the test function. No behavior
changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added the size/XL 500–999 added + deleted lines (all files); change volume, not priority. label Nov 22, 2026
@silo-triage silo-triage Bot removed the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Nov 22, 2026
@Quick104

Quick104 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Review summary

Reviewed head: 61bcd5c, on #4622's current head (7d22771, merged into this branch in ae363a1). This covers only this PR's change on top of #4622.

Fit: 8/10 · Readiness: 8/10 — conditional (assuming CI is green)

Fit: this fixes real lost watch time inside the existing watch-time measurement, with no new setting or API surface. It stretches one principle: the exact position belongs to the player, so the server estimates it. That's justified by fixing current clients without a protocol field and new client releases. Readiness: the approach is sound and the behavior was shown live and by tests that fail on the head before review. What holds it below 9: the estimate can cross the watched threshold, which needs a decision (below); a few low-severity multi-server windows remain; and the last three commits came after the final council round.

What changed in review

The posted findings and the earlier review threads are fixed on this branch:

  • The estimate started from the attempt row's report. A confirmed pause and resume, a resume after a paused report, a seek replan, or a retried report after a seek was ignored, so a seek back from 900 to 895 recorded 14 s ending at 909. It now starts from the latest observation of the play's measurement, and reads position and pause state from the measurement itself.
  • A report another server accepted wasn't measured before the estimate. It is now measured first, at the time it was accepted. Whether the session saw a report is told by sequence, not by comparing two servers' clocks. When their order is unknown, nothing is added.
  • A newer measurement saved on the session's lifecycle row is used as the starting point, as the finalizer would use it. When a final sample is estimated, that measurement is carried to the finalizer. A save that can't be read skips the estimate.
  • A stop confirmed while a pause confirmation is still being applied adds nothing.
  • A player last seen more than 12 s before the stop adds nothing; before, it got the full 12 s.
  • The file and save reads ahead of the stop write are bounded at 2 s, and the write has its own deadline.
  • A confirmed stop of a play whose progress came only through the bridge recorded no watch time: 290b6a4 carried the estimate's measurement to the finalizer even when there was no estimate, which left it empty. Fixed in 61bcd5c, which carries the session's own measurement. TestRealtimeConfirmedStopKeepsABridgePlaysMeasurement records 0 s on f8b4545 and 10 s on fix(playback): don't count a seek before a detached stop as watch time #4622's head and here.
  • The pending-pause test now releases its lock when a confirmation fails, so a failure reports instead of hanging.
  • docs/admin-api.md described a confirmed admin stop as ending at the last report. It now describes the exception and its limits.

Left for the maintainers

  • Maintainer decision: an estimate can cross the watched threshold. A player stalled a few seconds just below 90% can be marked watched, with its resume point cleared. Keeping completion on reported positions only would leave a player that really played past the threshold unmarked, as it is today.
  • Accepted, low: when another server accepted the latest report, skew between servers' clocks can move the credit within 12 s, and in a narrow case put the end at the pre-seek report. Another server saving a measurement in a sub-second window between two reads can change which measurement the final sample is judged against. A stop right after a confirmed resume whose provider scrobble is still running adds nothing. A pause confirmation whose receipt read failed is never applied, so a later stop can count the pause as play. A session rebuilt after a restart adds nothing until its next report. Terminate and deadline fallbacks still end at the last report.
  • Pre-existing, not from this PR: SessionManager.updateProgress sets the position on a replayed report it has already seen, so a retried report after a seek moves the live position back. A confirmed resume then measures from it. This affects live measurement too, so it belongs in its own change.

Validation

  • Live on a dev sandbox built from 290b6a4, with a scripted native player:
    • A stop 6.7 s after the report records 16.74 s for a 16.77 s play; main recorded 10.02 s.
    • A player silent for 30 s ends at its 10.05 s report; the PR's first head recorded 22.03 s.
    • An admin pause and resume, then a stop, records 12.72 s with the player at 14.75 s. The play before the pause isn't counted.
    • A paused player records 12.02 s.
  • f8b4545 only moves code, for the lint. 61bcd5c changes only the bridge branch, which the sandbox runs didn't exercise.
  • Tests that fail on ae363a1 and pass here: 7 of the 10 cases of TestRealtimeConfirmedStopCreditsPlayAfterTheLastReport, both cases of TestRealtimeConfirmedStopAfterAPendingPauseAddsNothing, and the failed-read case of TestRealtimeConfirmedStopKeepsANewerSavedMeasurement.
  • go test ./internal/api/handlers/ ./internal/playback/... and make lint-changed pass on 61bcd5c.
  • Validated features: not checked. The v1.0 board couldn't be read from this session.
  • User manual: unaffected. The site doesn't describe how watch time is measured around an admin stop.
  • Apple and Android: server-only change; no client change needed.

Council

Sol (gpt-6.2-sol, xhigh), Opus (claude-opus-5-5, high), Gemini (gemini-4-neon, xhigh). Five rounds in this review, after the earlier background review:

Member 2063b9a ae363a1 0ee51af cc7adbc 498ea90 6352b1b
Sol 5/10 4/10 5/10 6/10 6/10 7/10
Opus 7/10 6.5/10 7/10 8/10 8/10 8/10
Gemini 6/10 4/10 5/10 8/10 8.5/10 9/10

The last round's repairs are in 290b6a4, f8b4545 is a lint refactor, and 61bcd5c fixes a bridge regression from 290b6a4 that two review bots found. None was reviewed by the council again.

Evidence: https://evidence.siloserver.org/r/silo-server/4615-admin-stop-watch-time/

🤖 Claude Code (claude-opus-5-5)

An admin stop of a play whose progress came only through the bridge
submits the session's position as its final sample without an estimate.
Since the estimate's measurement became the one carried to the
finalizer, that branch carried an empty measurement, so the play was
recorded with no watch time. It now carries the session's own
measurement.

The pending-pause test also releases the side-effect lock when a
confirmation fails, so a failure reports instead of hanging.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: 17a4cd45-2f71-4578-8445-b1817c9d024a
Commits

Reviewing files that changed from the base of the PR and between f8b4545 and 61bcd5c.

Files selected for processing: 2

  • internal/api/handlers/playback_realtime.go
  • internal/api/handlers/playback_service_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

slog.WarnContext(ctx, "failed to record realtime stop attempt", "session", session.ID, "error", err)
return unarbitratedRealtimeStop(watchstate.PlaybackStopResult{})
}
if final != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Data Integrity & Integration · Quick win

Keep the selected measurement when no final sample is estimated.

When the saved measurement is newer than the attempt's last accepted sample, realtimeStopAnchor selects it but returns no estimate. realtimeStopHistory then sets session.Watch only when a final sample exists. The older live measurement therefore reaches finalization. finishStop restores the newer save only if its second read succeeds. If that read fails, the stop history records the older measurement.

Assign the selected measurement whenever it is measured:

Suggested fix

--- "a/internal/api/handlers/playback_realtime.go"
+++ "b/internal/api/handlers/playback_realtime.go"
@@ -200,12 +200,12 @@
 		slog.WarnContext(ctx, "failed to record realtime stop attempt", "session", session.ID, "error", err)
 		return unarbitratedRealtimeStop(watchstate.PlaybackStopResult{})
 	}
-	if final != nil {
+	if final != nil || estimatedFrom.Measured {
 		// The finalizer judges the final sample against the measurement it
 		// was built from, even if a second read of the save fails or finds
 		// nothing newer.
 		session.Watch = estimatedFrom
 	}
 	// An administrator end that finalized the receipt without a history row
 	// (nothing to record, or a failed write) is written from this snapshot.
 	// Whoever finalized a receipt wrote the admin log and told providers, so
Committable suggestion

IMPORTANT
Review the replacement and indentation, then test before committing.

Suggested change
if final != nil {
if final != nil || estimatedFrom.Measured {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes priority: P2 Limited scope, workaround exists, or polish size/XL 500–999 added + deleted lines (all files); change volume, not priority. stacked Base is another open PR; merge in stack order named in the body

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant