Skip to content

fix(playback): don't count a seek before a detached stop as watch time - #4622

Open
Quick104 wants to merge 6 commits into
mainfrom
fix/4618-detached-stop-seek
Open

Quick104 wants to merge 6 commits into
mainfrom
fix/4618-detached-stop-seek

Conversation

@Quick104

@Quick104 Quick104 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #4618
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-visible change); Android N/A (no client-visible change); Roku N/A (no client-visible change)

A seek shortly before a stop could be counted as watch time in admin playback history. When a stop is finalized from the attempt row, the play's measurement comes from the session's last save. That happens when the live session is gone after a restart, or lives on another API server. The attempt's latest progress sample and the stop's own final sample were then both judged against the stop time, so a seek between the save and the stop passed as played time once the stop came late enough. Real clients stop with a final sample, and in that case the row's seek sample was skipped entirely.

On a dev sandbox, an 80 s play with a 60 s seek, finalized this way, recorded 138 s played.

Approach

The attempt now records when it accepted its latest sample, in sample_accepted_at. An applied progress report sets it, and so does a stop's newer final sample, using the accepting server's clock, which is the clock the watch-time measurement uses. updated_at can't stand in for it, because replan commits, stops, idle expiry, and finalization claims also move it. A sample accepted before the column existed has no time (NULL reads as zero).

When the measurement came from a save rather than from the live copy the stop removed, finishStop now does two things:

  • It observes the row's latest sample at the time the row accepted it, so the seek is judged against the seconds that passed before it.
  • It then observes the stop's own newer sample at the stop. When the stop brings nothing newer, it instead closes the measurement at the stop from where the measurement stands (WatchTime.Close). A player paused there was paused until the stop, and no advance is credited, even when a seek back saved after the row's last report left that report ahead of the save.

A row whose sample has no time is finalized as before. WatchTime.Observe also keeps a confirmed pause pending when it replays a sample dated before the pause.

#4623 (#4615) and #4625 (#4616) are stacked on this branch. #4623 uses the same time, and #4625 changes the same stop statement.

Validation

  • Reproduced live on a dev sandbox, before and after, with a scripted native player. The run is: start, progress, pause, resume, a 60 s seek, a hard kill of the API server right after the seek's report, then the viewer's stop at 80 s. Main (6515ece) recorded 138.10 s played. This branch (a278ee8) records 75.06 s, which is the 12 s before the pause plus the 63 s after the seek. A control run without the seek recorded 78.1 s on both builds. A paused player stopped with no final sample recorded 68 s paused on both builds. Admin Playback History shows 2m 18s on main and 1m 15s on this branch.
  • Tests that fail before their change and pass here:
    • TestDetachedStopDoesNotCreditASeekBeforeIt on main: 900 s instead of 600 s with a final sample, 300 s instead of 0 without.
    • TestDetachedStopWithoutASampleKeepsThePauseUntilTheStop: 5 s paused instead of 605 s before the review's fix.
    • TestDetachedStopWithoutASampleDoesNotReplayAReportTheSaveIsPast: 60 s instead of 0.
    • TestWatchTimeObserve's case for a report from before a confirmed pause.
    • TestSampleAcceptedAtDB (Postgres, listed in scripts/ci/db-contracts.txt). It checks that a replan commit and a stop without a newer sample leave the sample time alone, that a stop with a newer final sample dates it to the stop, and that a NULL column reads as no time.
  • go test ./internal/api/handlers/ ./internal/playback/... ./internal/jellycompat/... against a migrated Postgres 18, and go run ./scripts/ci/migrationcheck.
  • Not checked: the v1.0 validation board (the session's GitHub token lacks read:project).

Evidence: https://evidence.siloserver.org/r/silo-server/4618-detached-stop-seek/

Risks

The change adds one nullable column with no default. The migration's version sorts before two migrations already on main, and Goose runs out of order here. During a rolling deploy, a replica on the previous version accepts progress without stamping the column. A row stamped earlier can then pair a newer sample with an older time, and the play between those two samples isn't credited.

These cases still lose or misplace a little time. Each needs a crashed finalizer, several API servers, or a race of milliseconds:

  • A stop finalized by a takeover after the winning server died still loses the progress sample before the stop's own final sample, because the row keeps only the latest one. That takeover gets what main records.
  • A progress report that wins the race with the stop's row update is judged at the stop.
  • A late finalizer counts paused time up to when it ran rather than to the stop. Main does the same.
  • A report that another server accepted just before the live server's save can be taken as already measured.

All four would close if the stop receipt carried the sample it replaced and when each was accepted, and if the save recorded which sequence it covers.

Follow-up: #4624 tracks the ends that still judge a sample accepted on another server against the stop time. Those are a stop handled by the API server that holds the live copy (including a session rebuilt from the save after a restart), a stream abort, and a confirmed remote pause. It waits on this PR.

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

Maintainer review. The PR rounds below ran on b68d5d1 (the branch with main merged in), then on 14f1cf3, and the final round on a278ee8. The head after that, 7d22771, adds a test only.

Member Plan round Background review (bc86d9e) Review r1 (b68d5d1) Review r2 (14f1cf3) Final (a278ee8)
Sol (gpt-6.2-sol, xhigh) no score 6/10 6/10 7/10 8/10
Opus (claude-opus-5-5, high) no score 8/10 7/10 8/10 8.5/10
Gemini (gemini-4-neon, xhigh) no score 7/10 6/10 unavailable (stopped when the head moved) 9/10

Fixed in review:

  • A detached stop with no final sample lost the paused time after the row's last sample.
  • A sample from before the column was dated to the row's last write.
  • A report older than a seek-back save was credited at the stop.
  • A replayed report from before a confirmed pause cleared the pause.
  • Test gaps on the stop-time stamp and on WatchTime.Close.

Answered: the four timing cases under Risks, and the live-copy, abort, and remote-pause ends tracked in #4624. Each predates this PR or is disclosed.

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: a plan round, a background council review, a maintainer code review at high effort, and three council rounds on this branch; see Council review.

When a stop is finalized from the attempt row, because the live copy is gone
after a restart or lives on another server, the measurement comes from the
copy's last save. Progress the row accepted after that save was judged
against the stop time, and so was the stop's own final sample, which skipped
the row's sample entirely. A seek between the save and the stop then passed
as played time once the stop came late enough.

The attempt now records when it accepted its latest sample, in a column no
other write moves: updated_at also changes on replan commits, stops, expiry
and finalization, so a stop finalized by the idle sweep or a takeover would
have dated the sample to the stop. The row's latest sample is observed at
that time, and the stop's own sample at the stop time, so the seek is judged
against the seconds that actually passed before it.

Closes #4618

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
@silo-kody

silo-kody Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@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-22T00:50:19.756870Z 7d22771 New commits
🔒 Security Review ✅ Completed 2026-11-22T00:52:06.848815Z 7d22771 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.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change records when the latest progress sample was accepted and uses that time when detached-stop handling reconstructs watch measurement. It preserves the timestamp through replans and stops without a newer final sample. Watch-time handling accounts for sample ordering and closing a measurement at stop. Tests cover timestamp persistence and detached-stop cases.

Changes: Playback watch-time measurement

Layer / File(s) Summary
Track sample acceptance time
internal/playback/protocol_store_v3.go, internal/playback/planstore/postgres.go, migrations/sql/20261120010601_add_playback_attempt_sample_accepted_at.sql, internal/playback/planstore/progress_lifecycle_db_test.go, scripts/ci/db-contracts.txt
Attempt records and PostgreSQL storage track when the latest sample was accepted. The timestamp is preserved through replans and stops without a newer final sample. The migration adds the nullable column, and the database test checks timestamp behavior.
Handle sample ordering and detached-stop measurement
internal/playback/watch_time.go, internal/playback/watch_time_test.go, internal/api/handlers/playback_service.go, internal/api/handlers/playback.go, internal/api/handlers/playback_realtime.go, internal/api/handlers/playback_service_test.go
Watch-time observation preserves a pending pause when an earlier sample arrives, and Close extends a measurement to stop time. Detached-stop handling observes the stored sample at its acceptance time and observes a newer final sample at stop time. End-sample observation takes explicit position and pause values. Tests cover detached-stop accounting and sample ordering.

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

Possibly related PRs

Suggested labels: go

Suggested reviewers: rhainland, blurbery, brady3035

Merge Risk: Low · up to a278e

Detached playback stops now avoid counting a seek before the stop as watch time in the common case. A narrow race between a concurrent progress report and the stop can still over-credit watch time slightly. It does not affect data integrity beyond the history figure, so it is low risk and can be handled in a follow-up.

Security architecture risk: Minimal · up to a278e

The inspected change improves playback-history accounting without establishing a new access, privilege, or failure-containment risk. The added database column requires coordinated migration and rollback ordering.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — For the inspected native client stop path, attacker-controlled position, pause state, and sequence remain associated with an attempt owned by the authenticated user and profile. The changed measurement processing does not select a different owner or media asset.

Trust Boundaries and Controls

  • observed — Acceptance and finalization times come from server clocks, not a new client timestamp field. Reported position remains client-controlled, and watch-time credit remains a heuristic bounded by the existing playback-rate and reporting-slack rule, not proof that content was watched.

Resilience and Maintainability Implications

  • observed — The inspected base and head retain the same finalization lease, cancellation-independent completion window, receipt recording, and stream-denial ordering. The new measurement branches execute within that existing protocol; they do not establish a new end-to-end exactly-once guarantee.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a seek before a detached stop is no longer counted as watch time. It matches the playback_service.go, planstore, and watch_time changes. It uses the conventional fix(p…
Linked Issues check Passed Objective [#4618]: when a stop finalizes a play from the attempt row, a seek before the stop must not count as played time. The row's latest sample must be judged at the time the row accepted it, not …
Out of Scope Changes check Passed The changes at head connect to the #4618 objective:
- finishStop (playback_service.go): the detached-path observation of the row's sample at its acceptance time, the stop-time observation of a newer…
Description check Passed The description is specific and related to the changeset. It explains the problem (a seek before a detached stop counted as watch time when finalized from the attempt row), the approach (a nullable sa…
Full details: Title check

Explanation

The title names the main change: a seek before a detached stop is no longer counted as watch time. It matches the playback_service.go, planstore, and watch_time changes. It uses the conventional fix(playback) prefix and is 70 characters, within a normal title length.

Full details: Linked Issues check

Explanation

Objective [#4618]: when a stop finalizes a play from the attempt row, a seek before the stop must not count as played time. The row's latest sample must be judged at the time the row accepted it, not at the stop time.

Status: Addressed by PR #4622 alone. No stack evidence was supplied, so no stack objective is assessed.

Evidence at the reviewed head (a278ee8, diff against merge base 6515ece):

  • finishStop (internal/api/handlers/playback_service.go) computes dated when the measurement was not carried over from the removed live copy, the row has a LastSample, and SampleAcceptedAt is non-zero. In that case it calls observeEndSample(session, record.LastSample.Position, record.LastSample.IsPaused, record.SampleAcceptedAt). The seek is therefore judged at the acceptance time, not at stop time.
  • A newer final stop sample is observed at time.Now(). A stop with no newer sample closes the measurement with the new WatchTime.Close, which credits no advance for a pause and keeps play after a seek. Rows without a timestamp use the prior behavior.
  • SampleAcceptedAt is stored in playback_v3_attempts (nullable column) and in AttemptRecordV3, and it is set on accepted progress and on a newer final stop sample. Replans keep it (planstore Postgres and memory stores, per the summary).
  • Tests: TestDetachedStopDoesNotCreditASeekBeforeIt and related handler tests, and TestSampleAcceptedAtDB in the database contract list. The PR reports that the handler test fails on main and passes on the branch. The live dev-sandbox reproduction is reported by the author (138.04 s before, 75.07 s after). I did not run these tests.

Unresolved: the diff confirms the finishStop and WatchTime logic but not the planstore and migration hunks in full. Those rely on the summary. Known gaps listed by the author (live-copy stops and stream aborts under #4624, takeover after a crash, rolling-deploy replicas, and lock-wait stop timing) lie outside the detached-path objective or are disclosed edge cases.

Full details: Out of Scope Changes check

Explanation

The changes at head connect to the #4618 objective:

  • finishStop (playback_service.go): the detached-path observation of the row's sample at its acceptance time, the stop-time observation of a newer final sample, and the Close branch for a stop with no newer sample. These form the fix.
  • WatchTime.Close (watch_time.go): a new method that the finishStop close branch calls. It supports the fix.
  • WatchTime.Observe (watch_time.go): a pending confirmed pause now applies only when the sample time is at or after the pause time. This changes behavior for every Observe caller, not only detached stops. It supports replayed samples at their arrival time, and TestWatchTimeObserve covers the case. I consider it connected, though it widens the effect beyond the detached path.
  • observeEndSample call sites (playback.go, playback_realtime.go): explicit position, pause state, and time arguments. The call site change supports the new timing.
  • protocol_store_v3.go, planstore/postgres.go, migration, and db-contracts.txt: the stored acceptance time and its contract test.
  • The three new handler tests and TestSampleAcceptedAtDB: they pin the fix.

No unrelated change appears in the summary or in the inspected diffs. The stacked #4623 and #4625 work is not part of this PR's changes.

Full details: Description check

Explanation

The description is specific and related to the changeset. It explains the problem (a seek before a detached stop counted as watch time when finalized from the attempt row), the approach (a nullable sample_accepted_at timestamp, finishStop reworked to observe the row's sample at its acceptance time, WatchTime.Close, and a confirmed-pause fix), validation (live reproduction, named tests, and Postgres DB contract test), and risks. It matches the raw summary's file-level changes and the PR objectives.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent 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: 611cbd34-5820-4063-b8dd-61591e875c19
Commits

Reviewing files that changed from the base of the PR and between bc86d9e and a278ee8.

Files selected for processing: 10

  • internal/api/handlers/playback.go
  • internal/api/handlers/playback_realtime.go
  • internal/api/handlers/playback_service.go
  • internal/api/handlers/playback_service_test.go
  • internal/playback/planstore/postgres.go
  • internal/playback/planstore/progress_lifecycle_db_test.go
  • internal/playback/protocol_store_v3.go
  • internal/playback/watch_time.go
  • internal/playback/watch_time_test.go
  • scripts/ci/db-contracts.txt

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

@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 labels Nov 20, 2026
@silo-triage

silo-triage Bot commented Nov 20, 2026

Copy link
Copy Markdown

The before/after measurements document the accounting fix, but the changed watch time is shown in admin playback history. Please add before-and-after captures of that screen with the same test data on desktop and phone-width web, identifying each build. The current evidence collection contains no screen captures.

Comment on lines +669 to +671
if accepted != nil && accepted.Sequence > record.LastSequence {
// The stop's own final sample, which arrived just now.
observeEndSample(session, accepted.Position, accepted.IsPaused, time.Now())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Bug high

Concurrent progress can be mistaken for a stop-time sample

A progress report accepted between ownedAttemptV2 and StopAttempt can cause a seek to be credited as watch time when the stop has no final sample or a stale sequence. Reconcile the receipt using the actual sample acceptance timestamp rather than the pre-stop sequence snapshot.

Prompt for LLM
File internal/api/handlers/playback_service.go, lines 669-671:

Concurrent progress can be mistaken for a stop-time sample

A progress report accepted after `ownedAttemptV2` reads the row but before `StopAttempt` wins is treated as a stop-time sample, so a seek can still be credited as watch time when a stop has no final sample or a stale final sequence. Reconcile the receipt against the actual sample acceptance timestamp rather than assuming every sequence newer than the pre-stop snapshot arrived with the stop.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

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.

Confirmed against 14f1cf3, but this predates the PR. Main observes a sample that wins the race between ownedAttemptV2 and StopAttempt at the stop time too, from the older saved measurement, so this PR narrows the case rather than causing it. The window is the gap between the handler's row read and the stop's update, which is normally milliseconds. Closing it means having the stop write return the sample it replaced along with that sample's time, which changes the stored receipt. I've left that for the maintainers to decide on as a follow-up, and I'm leaving the thread open.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Understood. The race predates this PR, and the PR narrows rather than introduces it. The thread remains open for the maintainers to decide whether to pursue the receipt change as a follow-up.

Would you like to track the remaining race as a Kody issue?

Comment on lines +443 to +445
SET last_sequence = $2, last_sample = $3, sample_accepted_at = $4, updated_at = NOW()
WHERE session_id = $1::uuid AND expires_at > NOW() AND stopped_at IS NULL AND last_sequence < $2`,
sessionID, sample.Sequence, sampleJSON)
sessionID, sample.Sequence, sampleJSON, time.Now())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Bug high

Sample acceptance time is captured before the row lock is acquired

A higher-sequence report waiting for the row lock can receive an earlier sample_accepted_at timestamp, causing a detached stop to discard the latest sample or judge a seek against the wrong interval. Record the acceptance time after acquiring the row lock.

Prompt for LLM
File internal/playback/planstore/postgres.go, lines 443-445:

Sample acceptance time is captured before the row lock is acquired

The timestamp is captured before the update acquires the attempt row lock, so a higher-sequence report waiting on a concurrent transaction can receive a timestamp earlier than the sample it supersedes. A detached stop can then discard the latest sample as older than the saved measurement or judge a seek against the wrong interval; record the acceptance time after acquiring the row lock.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

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.

Checked against 14f1cf3. This only happens when two progress reports for one attempt race on the row lock. The report that waited can carry a stamp a few milliseconds earlier than the one that held the lock. At worst, the later report is treated as already measured, and the play lost is whatever advanced between two reports that arrived within one lock wait, which is milliseconds. Postgres NOW() would have the same problem, since it's the transaction start time, and the stamp needs the accepting server's clock to match the watch measurement. No change here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agreed that PostgreSQL NOW() would not fix the ordering issue: it reflects the transaction start time. Keeping the accepting server’s clock is also consistent with the measurement clock.

I would qualify the impact assessment, though. A row-lock wait is not necessarily limited to milliseconds, and a delayed report can carry a much larger position change, such as a seek. Without a bound on lock waits or the measurement logic’s effect in that case, I can’t conclude that the maximum error is only a few milliseconds of lost play time.

No change requested; I’d keep the finding as a potential timing risk rather than characterize its impact as bounded.

@coderabbitai coderabbitai Bot added the go Pull requests that update go code label Nov 20, 2026

@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 bc86d9e)

I found three cases where a detached stop can still miscount watch time, plus a regression when API replica clocks differ.

AI disclosure. Reviewed by gpt-6.2-sol through the Codex harness in T3 Code.

Comment thread internal/playback/planstore/postgres.go Outdated
normalized_request, start_response, request_digest, expires_at, server_bitrate_cap_kbps,
last_sequence, last_sample, stopped_at, COALESCE(stop_receipt->>'stop_id', ''), updated_at,
desired_tracks, created_at, login_session_id
desired_tracks, created_at, login_session_id, COALESCE(sample_accepted_at, updated_at)

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.

S1 · Medium. Require the timestamp to match the sample during a rolling upgrade.

Once an upgraded replica stamps sequence 1, an older replica can accept sequence 2 and change last_sample and last_sequence while leaving the sequence 1 timestamp in place. The non-null value passes the fallback at internal/playback/planstore/postgres.go:186. If the saved measurement already contains sequence 1, observeEndSample drops sequence 2 because its borrowed timestamp is at or before the saved measurement (internal/api/handlers/playback.go:1718). A detached stop then loses valid viewing. Store the stamped sequence alongside the timestamp and check that it matches, or make the migration refresh the timestamp when a legacy write advances the sequence.

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.

Still true at 14f1cf3, and the Risks section discloses it. It needs a row stamped by an upgraded replica and then advanced by an older replica, so it can only happen during a rolling deploy, and only for plays that span it. The effect is an undercount of the play between those two samples. The NULL-column change in 14f1cf3 doesn't touch this case, because the stamp is set. Pairing the stamp with its sequence would close it at the cost of a second column. I'm leaving that decision to the maintainers and leaving the thread open.

}
if accepted != nil && accepted.Sequence > record.LastSequence {
// The stop's own final sample, which arrived just now.
observeEndSample(session, accepted.Position, accepted.IsPaused, time.Now())

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.

S2 · Medium. Carry the accepted sample's timestamp in the stop receipt.

A sample newer than the handler's snapshot can be a progress report that won the race with a stop that sent no final sample. ApplyProgress stamps and locks the attempt before updating the lifecycle row (internal/playback/planstore/postgres.go:441–460). If that second update waits on a lock, the stop can read the previous sequence and wait behind the progress transaction for seconds. At internal/api/handlers/playback_service.go:669–671 the stop judges the winning report at finalization time. A 30-second seek reported 1 second after the prior sample can therefore count as 30 seconds of viewing after a 15-second wait. The same time substitution changes a true final report's result when history finalization runs late. Return and persist the timestamp paired with the accepted sample in the stop receipt, and observe the sample at that time on first finalization and replay.

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.

Confirmed, but this predates the PR. Main also judged the stop's sample at time.Now() when finalization ran, so a stop that waited on a lock or a lapsed lease credited it the same way before this branch. The fix is the same receipt change the Kody and CodeRabbit threads need: carry the accepted sample's time in the stop receipt. I'm leaving that for the maintainers to decide on as one follow-up, and leaving this thread open.

// save. Progress does not trigger a save, so the saved measurement
// can predate it. A sample it already holds credits nothing.
observeEndSample(session, time.Now())
if !fromRemovedCopy && record.LastSample != nil {

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. Preserve the sample the stop replaced before granting any finalization claim.

The stop CAS overwrites the preceding progress sample (internal/playback/planstore/postgres.go:518–523). A second caller can read that stopped row and claim finalization before the first caller reaches its separate lease update (internal/api/handlers/playback_service.go:538–571). Both callers can stay healthy. With the new test's saved position of 100, seek to 400 and final position of 1000, that finalizer sees only 1000 and credits 900 seconds instead of 600 (internal/api/handlers/playback_service.go:661–671). Store the preceding sample and its timestamp in the same transaction as the stop receipt when a final sample supersedes it, then use that pair regardless of who gets the claim.

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.

Still true at 14f1cf3, and the Risks section discloses it. A finalizer that reads the stopped row sees only the final sample. It records what main records for the same timeline (900 s in the test's numbers), while the first finalizer records 600 s. The history upsert keeps the larger overlapping value, so a retry after a crash can raise a 600 s row to 900 s. That's main's figure and not a new overcount. Storing the replaced sample and its time with the stop receipt would fix this along with the S2 and Kody cases. I'm leaving it for the maintainers to decide on as that follow-up, and leaving the thread open.

// or not, at the time at. A sample from before the measurement's latest one
// is left out.
func observeEndSample(session *playback.Session, position float64, paused bool, at time.Time) {
if session.Watch.Measured && !at.After(session.Watch.Until) {

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. Use sample order to decide whether a saved measurement already includes a report.

A detached stop now compares a timestamp from the progress replica (internal/playback/planstore/postgres.go:445) with the saved measurement from the replica that held the live session (internal/api/handlers/playback.go:1662–1664). If the latter clock is 3 seconds ahead, genuine progress reported 2 seconds after the saved observation sorts before it and is discarded at internal/api/handlers/playback.go:1718. A stop without a final sample then loses the viewing and the position still advances. Persist the last observed progress sequence with the watch snapshot to detect duplicates, and use a shared or offset-adjusted time source for the elapsed-time calculation.

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.

Checked. Main also compared one API server's clock with another's: it compared the stopping server's time.Now() with a measurement saved by the server that held the live copy. So clock skew between replicas affected the result before this PR as well. It matters only at the level of seconds, which NTP-synced hosts stay well under. No change here.

@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 bc86d9e)

I found one low-severity test gap and no defects. The new finishStop order (the row's sample at its accepted time, then the stop's own final sample at now) is right for every caller I traced: the client stop, the replayed stop, FinishOtherEnd, endSessionAsAdmin, and the sweep's finishInterruptedNativeEnd. It also improves the post-stop readers, which now judge a stopped row's final sample at the stop time instead of at the takeover or sweep time. A dedicated column is the right boundary, because updated_at and the lifecycle activity_at are both moved by other writes.

Written by Claude Code (claude-opus-5-5) as an automated adversarial review.

Comment thread internal/playback/planstore/postgres.go Resolved

@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: 10ae3095-6a4f-4b60-849f-53b0193c0034
Commits

Reviewing files that changed from the base of the PR and between e66dc6e and bc86d9e.

Files selected for processing: 8

  • internal/api/handlers/playback.go
  • internal/api/handlers/playback_service.go
  • internal/api/handlers/playback_service_test.go
  • internal/playback/planstore/postgres.go
  • internal/playback/planstore/progress_lifecycle_db_test.go
  • internal/playback/protocol_store_v3.go
  • migrations/sql/20261120010601_add_playback_attempt_sample_accepted_at.sql
  • scripts/ci/db-contracts.txt

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

Comment on lines 658 to 674
session.Watch = carried
h.fillDetachedSession(ctx, session, record.CreatedAt)
fromRemovedCopy := carried.Measured && session.Watch.Until.Equal(carried.Until)
if accepted != nil && (accepted.Sequence > record.LastSequence || !fromRemovedCopy) {
// The latest accepted sample: the stop's own, or, when the
// measurement was restored from the last save rather than handed
// over by the copy this end removed, progress accepted since that
// save. Progress does not trigger a save, so the saved measurement
// can predate it. A sample it already holds credits nothing.
observeEndSample(session, time.Now())
if !fromRemovedCopy && record.LastSample != nil {
// The measurement was restored from the last save rather than handed
// over by the copy this end removed. Progress does not trigger a
// save, so the row's latest sample can be newer than it. Judge that
// sample at the time the row accepted it, not now, so a seek before
// the stop is not credited as watch time.
observeEndSample(session, record.LastSample.Position, record.LastSample.IsPaused, record.SampleAcceptedAt)
}
if accepted != nil && accepted.Sequence > record.LastSequence {
// The stop's own final sample, which arrived just now.
observeEndSample(session, accepted.Position, accepted.IsPaused, time.Now())
}
if record.CurrentPlanID != "" {
// The attempt holds the plan the last replan committed. The live row

@coderabbitai coderabbitai Bot Nov 20, 2026 •

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 · Heavy lift

Judge the pre-stop progress sample at its acceptance time.

StopPlaybackV2 reads record at playback_service.go:530, before store.StopAttempt at line 538. record is not read again after the update, and StopAttempt returns only a receipt. If a progress sample commits between the read and the update, record.LastSequence is behind the row. Two cases follow:

  • The stop has no final sample, or one not newer than the row: the receipt carries the stored progress sample. Line 669 sees that sample's sequence as newer than the stale record.LastSequence, and observes it at time.Now().
  • The stop has a newer final sample: the stored progress sample is replaced. It is never judged at its acceptance time, and the stop's final is observed at time.Now().

In both cases, WatchTime.Observe can credit a seek made shortly before the stop as played time. The credit is bounded by the time since the earlier measured sample, not by the seek's own time.

Required behavior: a progress sample accepted before a stop must be judged at its own acceptance time. The sequence test must use the row state that the stop's update replaces. The correction is open: the store can return the prior sample and its acceptance time with the receipt, or the attempt can be read inside the stop's update.

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.

This is the same race as the Kody thread on the earlier lines. Main observes that sample at the stop time too, so the PR narrows the case rather than introducing it. The fix it needs, a stop write that returns the replaced sample and its time, changes the stored receipt. I'm leaving that for the maintainers to decide on as a follow-up, and leaving this thread open.

@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 bc86d9e)

The core fix — a dedicated sample_accepted_at timestamp stamped with the accepting server's clock and two-step observation in detached finishStop — addresses the main detached-stop seek case cleanly. Three verified issues remain in the code this PR changes (detailed in the inline comments below):

  1. Medium (internal/api/handlers/playback_service.go:661): !fromRemovedCopy skips record.LastSample even when the removed copy never saw it (single-replica FinishOtherEnd takeovers and multi-replica realtimeStopHistory).
  2. Low (internal/api/handlers/playback_service.go:671): finalizeStopV2 / finalizeRealtimeStop can wait 30–60 s for a lapsed finalization lease and still judge accepted against time.Now() using a stale pre-stop record.
  3. Low (internal/playback/planstore/postgres.go:186): Postgres vs MemoryPlanStoreV3 parity gaps on SampleAcceptedAt (Postgres fabricates a moving non-zero timestamp when last_sample IS NULL; MemoryPlanStoreV3 omits the documented LastSampleAt fallback; finishStop passes record.SampleAcceptedAt without guarding IsZero()).

AI-assisted review generated with Antigravity (T3 Code) using Gemini 4 Neon (gemini-4-neon).

// save. Progress does not trigger a save, so the saved measurement
// can predate it. A sample it already holds credits nothing.
observeEndSample(session, time.Now())
if !fromRemovedCopy && record.LastSample != nil {

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.

Severity: Medium

Trigger: Any withEndWatch caller (internal/api/handlers/playback_realtime.go:206, internal/api/handlers/playback_realtime.go:266, internal/api/handlers/playback.go:1550, internal/api/handlers/stream.go:831) passes a removed local copy's Watch whose Until is at least as new as savedWatch, so fromRemovedCopy is true, while record.LastSample holds a newer sample that copy never saw:

  • Single-replica race: abortPlaybackSession or expireSessionCopy removes the live session, then a client StopPlaybackV2 wins StopAttempt with a final sample before claimNativeEnd reads GetAttempt (internal/api/handlers/playback_end_claim.go:48-68). claimNativeEnd reads the post-stop row (record.LastSequence == receipt.Accepted.Sequence), wins claimStopFinalization, and calls FinishOtherEnd(withEndWatch(ctx, session), claim, session.ID).
  • Multi-replica: Another replica accepted progress (or a stop) after the removed copy's last observation, and this replica runs realtimeStopHistory or FinishOtherEnd.

Impact: Both if !fromRemovedCopy && record.LastSample != nil (line 661) and if accepted != nil && accepted.Sequence > record.LastSequence (line 669) are false when record.LastSequence == receipt.Accepted.Sequence, silently dropping the unseen progress or winning stop sample from session.Watch (EndPositionSeconds advances while PlayedSeconds misses that viewing). On realtimeStopHistory when a caller also supplies a newer final sample (accepted.Sequence > record.LastSequence, as in stacked #4623), skipping line 661 skips a seek in record.LastSample and judges the final sample directly against the stale removed copy at now, re-introducing #4618.

Evidence: internal/api/handlers/playback_service.go:660-672, internal/api/handlers/playback_end_claim.go:48-68,133-135, internal/api/handlers/playback_realtime.go:206,266, internal/api/handlers/playback.go:1550, internal/api/handlers/stream.go:831, internal/api/handlers/playback.go:1717-1722.

Suggested repair: Remove the !fromRemovedCopy gate on line 661 so record.LastSample is always offered to observeEndSample at record.SampleAcceptedAt (with a zero-time fallback). Because ApplyProgress stamps sample_accepted_at before persistProgressV2 updates the live copy's session.Watch.Until, any sample the removed copy already observed satisfies !at.After(session.Watch.Until) and is already a no-op in observeEndSample.

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.

Confirmed, but this predates the PR. Main had the same !fromRemovedCopy gate on the end observation, so a sample that the removed copy never saw went unmeasured there too. The issue that tracks live-copy ends is #4624, which waits on this PR. This review's council also found a related case. After a restart, a media request can rebuild the live session from the last save, and the stop then takes the live-copy path, which judges the row's sample at the stop. That case belongs in #4624 too. I'm leaving this thread open.

}
if accepted != nil && accepted.Sequence > record.LastSequence {
// The stop's own final sample, which arrived just now.
observeEndSample(session, accepted.Position, accepted.IsPaused, time.Now())

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.

Severity: Low

Trigger: StopPlaybackV2 (internal/api/handlers/playback_service.go:530,538,557) or realtimeStopHistory (internal/api/handlers/playback_realtime.go:166,184,207) reads record before StopAttempt, then enters finalizeStopV2 (internal/api/handlers/playback_service.go:570-608) where ClaimStopFinalization returns false because a competing caller claimed the 30 s stopFinalizationLease and crashed/stalled before finalizing. This happens both when a concurrent stop won StopAttempt after record was read (!first) and when this caller won StopAttempt (first) but lost the first claim. finalizeStopV2 polls for up to 30 s (up to 60 s across finalizeRealtimeStop's two rounds at internal/api/handlers/playback_realtime.go:241-251), re-reading receipt each iteration without refreshing record or passing the time StopAttempt accepted final.

Impact: The comment on line 670 ("The stop's own final sample, which arrived just now") and the plan-round premise that the read-to-CAS gap is only milliseconds do not hold across a lease takeover. Line 671 judges accepted at time.Now() 30–60 s after StopAttempt actually accepted it (even though sample_accepted_at already recorded the true time in the store), allowing a seek of up to ~60–120 s in the winning stop's sample to pass as played time.

Evidence: internal/api/handlers/playback_service.go:530-608,669-672, internal/api/handlers/playback_realtime.go:166-209,241-251.

Suggested repair: Capture stoppedAt := time.Now() at StopAttempt and pass it into finalizeStopV2 / finishStop for the first == true case (preserving the pre-stop record.LastSample while judging accepted at stoppedAt instead of a delayed time.Now()). When !first (another stop won the row), refresh record via GetAttempt once finalization is claimed so record.LastSequence == receipt.Accepted.Sequence and record.SampleAcceptedAt is used.

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.

This is the same case as S2 above. Main judged the stop's sample at the finalization time too, so this predates the PR. The remedy is the same follow-up, carrying the accepted sample's time in the stop receipt, and it's left for the maintainers. I'm leaving this thread open.

Comment thread internal/playback/planstore/postgres.go Resolved
Quick104 and others added 3 commits November 21, 2026 23:56
Resolve the db-contracts.txt conflict by keeping both lists, and update
the observeEndSample call that main added in playback_realtime.go to the
new signature, keeping its behavior.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A stop with no final sample, finalized from the attempt row, observed the
row's sample only at the time the row accepted it, so a player that was
still paused when the stop came lost that stretch of paused time. Observe
the sample again at the stop, as main and the live-copy stop path do; an
unmoved position credits no play, so a seek before the stop still counts
for nothing.

Also check that a stop with a newer final sample dates it to the stop.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reading a missing sample_accepted_at as updated_at dated a sample accepted
before the column existed to whatever last moved the row, such as a replan
commit after a seek. A detached stop then replayed the stale position after
the saved measurement and judged later play against it. Read the missing
time as none, and finalize such a row as main did.

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

@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 b68d5d1. That's this branch with current main merged in. The merge resolved a scripts/ci/db-contracts.txt conflict and moved one new observeEndSample caller from main, in playback_realtime.go, to the new signature without changing what it does.

Two defects this PR introduces are below. I'm fixing both in commits on this branch, so there's no need to change them yourself. The earlier review threads get replies where they are.

Written by Claude Code (claude-opus-5-5) as a maintainer review.

Comment thread internal/playback/planstore/postgres.go Resolved
@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
@silo-kody

This comment has been minimized.

A stop with no sample newer than the row's re-observed the row's sample at
the stop. After a seek back that a replan saved without a report, that
sample is older than the save and ahead of it, so the gap back to it was
credited as watch time. Close the measurement from its own state instead:
paused time runs to the stop and no advance is credited.

Replaying the row's sample could also come from before a pause the save
had confirmed since, and dropped that pause. A sample dated before a
confirmed pause now leaves it pending.

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

silo-kody Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@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.

The second council round, on 14f1cf3, found two more cases this branch handled worse than it should. Both are fixed in a278ee8, so there's no need to change anything yourself. I pushed that commit before posting this, so the findings are anchored on the fixed lines.

Written by Claude Code (claude-opus-5-5) as a maintainer review.

case accepted != nil && accepted.Sequence > record.LastSequence:
// The stop's own final sample, which arrived just now.
observeEndSample(session, accepted.Position, accepted.IsPaused, time.Now())
case accepted != nil && dated && session.Watch.Measured:

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.

Medium. After a backward seek that a replan saved without a progress report, re-observing the row's sample at the stop credited the rewind as play.

Trigger: the player reports 160, seeks back to 100, and a replan saves the measurement at 100. A stop with no final sample is then finalized from the row. The row's sample predates the save, so its dated replay was skipped, as it should be. The closing observation then applied 160 at the stop, judged the 60 s gap back against 30 s of elapsed time, and credited it. Main does the same, and 14f1cf3 brought that back when it restored main's condition for the paused case.

Fixed in a278ee8. When the stop brings no sample newer than the row's, and the row's sample has a time, finishStop now calls a new WatchTime.Close(now). It extends the measurement from its own last position and pause state, so paused time runs to the stop and no advance is credited. A row whose sample has no time (accepted before the column existed) is finalized as main did. TestDetachedStopWithoutASampleDoesNotReplayAReportTheSaveIsPast failed on 14f1cf3 with 60 s played and passes now. Found by the Sol council member.

if !w.pausedAt.IsZero() {
// A sample from before the confirmed pause, replayed at the time it
// arrived, doesn't show the player resumed: the pause stays pending.
if !w.pausedAt.IsZero() && !now.Before(w.pausedAt) {

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.

Low. Replaying a row sample dated before a confirmed pause cleared the pause.

Trigger: a playing report commits on another API server after the pause worker reads the attempt but before it saves the confirmed pause. A detached stop later replays that report at its own time, which is before pausedAt. Observe read it as "resumed at some unknown point" and cleared the pending pause, so a paused final sample lost the paused stretch and could credit a seek made while paused. Main never replayed the row's sample, so it kept the pause.

Fixed in a278ee8. Observe now settles a pending pause only for a sample at or after pausedAt. The new TestWatchTimeObserve case "a report from before a confirmed pause keeps the pause" failed before the change, with 0 s paused, and passes with 90 s. Live sampling only observes at the current time, so it never reaches the new branch. Found by the Sol and Opus council members.

@silo-kody

silo-kody Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104

Copy link
Copy Markdown
Contributor Author

Maintainer review summary

Reviewed head: 7d22771. The last change to behavior is a278ee8; 7d22771 only adds a test.

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

What happened on the branch

  • Merged current main (b68d5d1). The only conflict was in scripts/ci/db-contracts.txt. Main had added a new observeEndSample caller in playback_realtime.go, which I moved to the new signature without changing what it does.
  • Fixed four defects the change had introduced, and closed two test gaps. Each fix came with a test that fails without it:
    • cbcbf5d: a paused player lost its paused time when a stop with no final sample was finalized from the attempt row. This held on the original head too.
    • 14f1cf3: a sample from before the new column was dated to the row's last write.
    • a278ee8: after a seek back that a replan saved, the row's older report was credited at the stop. Separately, a replayed report from before a confirmed pause cleared that pause.
    • cbcbf5d and 7d22771: tests for the stop-time stamp and for WatchTime.Close.
  • Replied to every earlier review thread, and resolved the threads these commits fix.

Validation

  • Live on a dev sandbox, before and after, with a scripted native player. A 60 s seek, a hard kill of the API server, then a stop at 80 s recorded 138.10 s played on main and 75.06 s on this branch. Admin Playback History shows 2m 18s on main and 1m 15s here.
  • Two control runs matched main: without the seek, 78.1 s on both builds; a paused stop with no final sample, 68 s paused on both.
  • Tests that fail on the base or on the pre-fix head and pass here are listed in the PR body. The handler, playback, planstore, and jellycompat packages pass against a migrated Postgres.
  • Evidence: https://evidence.siloserver.org/r/silo-server/4618-detached-stop-seek/, rebuilt for this head with desktop and phone captures of Playback History. At phone width the table scrolls sideways, so the Watch Time column is off screen. The layout is the same on main.

Validated features: not checked, because the v1.0 validation board couldn't be read from this session. Admin playback history watch time is the only behavior that changes.

User manual: no change needed. The manual doesn't describe how watch time is measured.

Other apps: no client-visible change, so Apple, Android, and Roku have nothing to do.

Council (gpt-6.2-sol xhigh, claude-opus-5-5 high, gemini-4-neon xhigh). Gemini's round 2 was stopped when the head moved.

Member r1 (b68d5d1) r2 (14f1cf3) final (a278ee8)
Sol 6/10 7/10 8/10
Opus 7/10 8/10 8.5/10
Gemini 6/10 unavailable 9/10

Left for the maintainers

  • Maintainer decision: a follow-up on stop timing. Four narrow cases remain, listed under Risks in the PR body: a takeover after a crashed finalizer, a report racing the stop's update, a late finalizer counting pause up to when it ran, and a report taken as already measured across servers. Each needs a crash, several API servers, or a millisecond race, and each matches or beats main. The fix that closes all four is for the stop receipt to carry the sample it replaced and when each was accepted, and for the watch save to record the sequence it covers. That's a contract change to the stored receipt.
  • [bug] A seek before a stop on the server holding the live session can count as watch time #4624 scope. It should also cover a session rebuilt from the save after a restart, a stream abort, and a confirmed remote pause. Those ends still judge the row's sample at the stop.
  • Rolling deploy (disclosed): while old and new replicas run together, a row stamped by a new replica and advanced by an old one doesn't credit the play between those two samples.

Why these scores

  • Fit: this fixes the accuracy of watch history, which the admin history page reports, without adding a setting or a new API. The cost is one nullable column and a timestamp written on each progress report. That's negligible on low-end hardware.
  • Readiness: the bug was reproduced live and is gone on this head, and every regression the review found is fixed with a test that fails without its fix. The score is 8 rather than 9 because of the narrow timing cases above and the validation board that wasn't read.

Written by Claude Code (claude-opus-5-5) as a maintainer review.

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 go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] A seek before a detached stop can be counted as watch time

1 participant