You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(playback): record an admin stop as terminated when the player's stop lands first - #4625
Closes#4616
Related issue: N/A
Validation tasks: none
Other clients: Apple N/A (no client change needed); Android N/A (no client change needed); Roku N/A (no client change needed)
An administrator's stop could be recorded in history as end_reason: "stopped", as if the viewer had stopped. The stop command recorded nothing durable when it was sent. When the player confirmed, the server removed the live session at once and stopped the attempt under the administrator's stop id afterwards. A player that sends its own stop as it leaves, as the web player and Android do, could reach the attempt first, and its stop was recorded as the viewer's. On a Silo dev deployment with a transcode node, the web player showed "An administrator ended this playback session" while history recorded stopped.
This is stacked on #4622 and targets its branch, because both change the attempt's stop statement; review that one first. It does not depend on #4623.
Approach
The attempt now records each pending stop, by command id and when it was sent, written before the stop goes out and only when this server holds the player's control socket. The stop that wins the attempt copies whether one was pending into its stop receipt, in the same update that wins, so retries, takeovers and the lifecycle sweep all read the same answer. A client stop that won while one was pending records terminated.
Each stop withdraws only its own entry, when it can't be sent or the player refuses it, so overlapping stops, sent from any server, don't clear each other. An entry older than 30 seconds no longer counts, so one whose command was lost (a restart, a failed fallback, a refusal that reached another server) can't turn a much later viewer stop into the administrator's. A stop to a player with no control socket records nothing: its fallback ends the session under the administrator's stop id. Neither write touches updated_at, which the idle expiry reads as activity.
The progress and replan answers (410 after an administrator's end) and a repeat terminate are unchanged.
Validation
Reproduced live before and after on a dev sandbox (on this branch's first version, afb0d87; the review since changed how the pending stops are stored, not the path shown) with a transcode node, with the web player in headless Chromium playing an episode the node transcodes. Main recorded stopped in both runs while the player showed the administrator's notice; this branch records terminated in all three runs.
A scripted native player that sends its own stop before confirming: stopped on main, terminated here. Controls on this branch: a viewer's stop with no command records stopped, and a viewer's stop after the player refused the admin stop records stopped.
A new handler test fails on main (the admin-stopped plays record stopped) and passes here; its viewer-stop cases pass on both. New Postgres and memory-store tests pin the receipt flag, per-command withdrawal, the 30 s window and that updated_at doesn't move; the Postgres ones are listed in scripts/ci/db-contracts.txt.
Review fixes: the handler cases "a later stop's refusal leaves the earlier one" and "viewer stop before a stop's fallback" fail on 01b493d and pass here. TestAdminStopMarksPerCommandDB pins that withdrawing one stop leaves another.
go test ./internal/api/handlers/ ./internal/playback/... ./internal/apiv2/ with a freshly migrated Postgres, golangci-lint on the changes, make verify-migrations.
v1.0 validation board: no task links this change, and the passed transcode-node failover cases, which end sessions through the same stop paths, see no change (no pending administrator stop, so the receipt flag stays unset).
One nullable JSONB column, added without a default. During a rolling deploy, a stop that an older replica sends doesn't set the mark, so that play can still record stopped, as before.
The admin stop command now makes one bounded write (up to 1 s) before it reaches the player, under the command ledger's lock, and a refused stop makes one on the socket reader.
A viewer who stops on their own within moments of an administrator's stop reaching their player is recorded as terminated. A control socket that connects in the instant between the lane check and the send gets an unmarked stop, which records as before this change.
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
Plan round on 4eb4d4a86 (before implementing): Sol, Opus and Gemini, no scores. Adopted then: decide the reason in the stop's own update and keep it in the receipt (Opus, Sol); scope the mark to its command (Sol); include the lifecycle sweep's caller (Gemini). Keeping the mark on the no-socket path (Opus, Gemini) was reversed in review.
The background review this PR opened with: Sol posted findings on afb0d87 (no score recorded); no Opus or Gemini review appears on the PR.
Fixed: a second stop's refusal or failed send erased the first stop's mark (now one entry per command); a stop with no control socket left a mark for the viewer's own stop; the replan test couldn't fail. Answered: the refusal clear stays on the socket reader (the pause confirmation already spends the same budget there) and the mark write stays under the ledger lock (moving it lets a stale command take a mark it never withdraws). Left open for the maintainers: progress, replan and a repeat terminate still judge an administrator's end by the stop id alone, and a socket that connects between the lane check and the send gets an unmarked stop.
AI Disclosure
Harness: Claude Code in T3 Code
Tool(s): Claude Code, GitHub CLI, T3 Code delegated reviews (Codex, Claude, Antigravity), Playwright (web player capture)
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 before implementing, a code review at high effort, a background review, and three council rounds in a maintainer review; see Council review.
Note
Record player stops as terminated when an admin stop is pending
When an admin issues a stop, the server marks the attempt (MarkAdminStop) before dispatching. If the player's own stop reaches the server first within the 30-second AdminStopPendingFor window, the stop receipt records AdminStopRequested and the end reason becomes terminated.
ClearAdminStop withdraws a mark when a stop is refused or fails to dispatch, and can transfer it to another pending stop command for the same session.
Implemented in both the in-memory store (protocol_store_v3.go) and PostgreSQL (postgres.go); PostgreSQL persists marks in new admin_stop_command_id/admin_stop_requested_at columns.
Risk: Behavioral Change — stops that previously recorded stopped now record terminated when an admin stop was pending within 30 seconds; see endReasonForStop in playback_service.go and the new migration.
…top lands first
An administrator's stop command recorded nothing durable when it was sent.
When the player confirmed, the server removed the live session at once and
stopped the attempt under the administrator's stop id afterwards. A player
that sends its own stop as it leaves, as the web player and Android do, could
reach the attempt first, and history recorded the play as stopped by the
viewer.
The attempt now carries the pending stop's command id and when it was sent,
set before the stop goes out. The stop that wins the attempt copies whether
one was pending into its receipt, in the same update, and a client stop that
won while it was pending records terminated. Only that command clears the
mark, when it can't be sent or the player refuses it, and a mark older than
30 seconds no longer counts, so one whose command was lost can't relabel a
later viewer stop. The mark doesn't touch updated_at, which the idle expiry
reads as activity.
Closes#4616
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The change tracks pending administrator stop requests and includes their status in stop receipts. When a client stop wins while an administrator stop is pending, handler paths use that status to select the playback end reason.
Changes: Administrator stop attribution
Layer / File(s)
Summary
Record pending administrator stops internal/playback/protocol_store_v3.go, internal/playback/protocol_store_progress_v3_test.go, internal/playback/planstore/postgres.go, internal/playback/planstore/progress_lifecycle_db_test.go, migrations/sql/20261120011304_add_playback_attempt_admin_stop_command.sql, scripts/ci/db-contracts.txt
Stop receipts record whether an administrator stop was pending. The memory and PostgreSQL stores mark and clear pending stops, with a 30-second attribution window. The migration adds the PostgreSQL marker columns. Tests cover marker behavior and expiration.
Dispatch stops and resolve end reasons internal/api/handlers/admin_playback_commands.go, internal/api/handlers/admin_playback_commands_test.go, internal/api/handlers/playback_realtime.go, internal/api/handlers/session_ws.go, internal/api/handlers/playback_service.go, internal/api/handlers/playback_end_claim.go, internal/api/handlers/playback_lifecycle_sweep.go, docs/admin-api.md, docs/playback-api.md
The handler marks an administrator stop before dispatch and clears the mark on specified failures. Stop receipt state is passed to end-reason selection and lifecycle finalization. Tests cover stop orderings, and the API documentation describes the resulting terminated reason.
sequenceDiagram
participant AdminCommandHandler
participant PlanStoreV3
participant Player
participant StopFinalizer
AdminCommandHandler->>PlanStoreV3: MarkAdminStop(sessionID, commandID)
AdminCommandHandler->>Player: Dispatch administrator stop
Player->>PlanStoreV3: StopAttempt
PlanStoreV3-->>StopFinalizer: StopReceiptV3 with AdminStopRequested
StopFinalizer->>StopFinalizer: Select playback end reason
Loading
Possibly related PRs
Silo-Server/silo-server#3184: Defines the end-reason contract that this change updates for administrator and client stop races.
Suggested reviewers:rhainland, blurbery
Merge Risk: Low · up to b1dc7
This change records a player stop that follows an administrator stop as terminated. The attribution is time-window based, so the documentation should say it is an attribution rule, not proof that the player carried out the command. There is no established functional defect, so merge risk is low.
Security architecture risk: Minimal · up to b1dc7
The change makes administrator-stop attribution durable without expanding playback-control authority. No introduced design-level issue materially affecting security, session revocation, or failure containment was identified in the reviewed paths.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The inspected change affects attribution for the identified playback attempt and its history/lifecycle finalization. Marker mutations are session-scoped, and withdrawal additionally requires the matching command ID; no broader data-store or environment authority is introduced by these operations.
Trust Boundaries and Controls
observed — Viewer stop requests validate stop identity, reject reserved server stop IDs, and check user/profile ownership before mutating an attempt. Socket results must match the socket session and known command ownership before withdrawing a pending stop; the store then enforces command-scoped withdrawal.
Resilience and Maintainability Implications
observed — Pending-command handoff selects another stop from replica-local memory, while the PostgreSQL marker and winning receipt are durable. The expiry window bounds how long a stranded marker can affect attribution after interruption; it is not a durable inventory of every outstanding command.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title describes the main change: an administrator stop is recorded as terminated when the player's stop reaches the attempt first. The changeset adds pending admin-stop marks, a receipt flag, and …
Linked Issues check
Objective [#4616]: when an administrator stop wins or races a client stop, playback history must record terminated, whichever stop reaches the attempt first. Stack scope: the stacked parent #4622 is…
Out of Scope Changes check
All changes since the previous review relate to the #4616 fix. The heir hand-off (ClearAdminStop with heir, pendingRealtimeStop) covers overlapping admin stops. The no-socket withdrawal follows th…
Description check
The description is specific and closely tied to the changeset. It names the bug (an administrator stop recorded as end_reason "stopped"), explains the approach (pending admin-stop marks written before…
Full details: Title check
Explanation
The title describes the main change: an administrator stop is recorded as terminated when the player's stop reaches the attempt first. The changeset adds pending admin-stop marks, a receipt flag, and end-reason resolution that returns terminated for this case, which matches the title.
Full details: Linked Issues check
Explanation
Objective [#4616]: when an administrator stop wins or races a client stop, playback history must record terminated, whichever stop reaches the attempt first. Stack scope: the stacked parent #4622 is contained in the merge base, and no other stack member is required. Stack review evidence is unavailable, and this PR states it does not depend on #4623. Evidence from the whole-PR summary and the incremental diff (afb0d87..b1dc724, internal/api/handlers/playback_realtime.go): (1) the admin stop mark is set before dispatch (markAdminStop, dispatchSequenced), as the issue requests; (2) the winning StopAttempt copies the pending flag into the stop receipt in the same update (planstore/postgres.go, protocol_store_v3.go); (3) endReasonForStop returns terminated for a client stop when that flag is set; (4) the mark is cleared when dispatch fails or the player refuses the stop, which the issue also requests. The later commit changes the no-control-socket path to withdraw the mark, and hands the mark to another unanswered stop on the same replica (pendingRealtimeStop). This is consistent with the issue's clear-on-rejection rule. A viewer stop that wins before the no-socket fallback is recorded as stopped. The issue does not require terminated in that case, because the player never received or acknowledged the admin command. The PR description still says a no-socket stop keeps its mark, which is stale. Uncertainty: the assessment relies on the summary and one focused diff read, not a full test run. The 30-second window and the rolling-deploy gap are documented limits. The HTTP finalizer measurement side effect has no stated acceptance criterion.
Full details: Out of Scope Changes check
Explanation
All changes since the previous review relate to the #4616 fix. The heir hand-off (ClearAdminStop with heir, pendingRealtimeStop) covers overlapping admin stops. The no-socket withdrawal follows the clear-on-undelivered rule. The change in stopPlaybackSessionWithResult uses the accepted progress sample's position for the stopped attempt. It ties to the measurement handoff side effect named in the issue, but the PR description does not state it. Earlier changes (handler, planstore, protocol store, migration, tests, CI contract, docs) remain connected to the same fix. No unrelated change is found in the reviewed evidence. Reviewer follow-up, not a scope failure: the PR description's no-socket text is stale and conflicts with the later commit, and the accepted-sample position change should be described in the PR description.
Full details: Description check
Explanation
The description is specific and closely tied to the changeset. It names the bug (an administrator stop recorded as end_reason "stopped"), explains the approach (pending admin-stop marks written before dispatch, copied into the stop receipt, cleared on refusal or failed dispatch, 30-second window, no updated_at change), and lists the affected stores, migration, and tests. It also records validation and risks. The description is detailed and on-topic, so it meets the lenient check.
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
The reason will be displayed to describe this comment to others. Learn more.
P2 — A slow refusal clear can make an answered pause terminate playback. The socket loop at internal/api/handlers/playback_control_socket_v2.go:445 processes frames serially. Hold the attempt row while this clear runs, then send a pause with a 250 ms deadline. Its immediate completion can sit unread for up to one second, and internal/api/handlers/admin_playback_commands.go:279 runs the fallback that ends the session. Keep reading frames and cancel their timers as results arrive, while processing the database updates in order outside the reader.
The reason will be displayed to describe this comment to others. Learn more.
Not changing this one. The mechanism is real, but it's the same exposure the pause confirmation already accepts on this reader (realtimeProgressAttempt with the same 1 s realtimeReceiptReadBudget, kept "well inside the default command deadline"), and here only a refused stop pays it. Moving the clear off the reader isn't free: the HTTP stop doesn't wait on the per-session result queue, so a viewer stop right after a refusal could win before an asynchronous clear lands and record terminated. I've left it to the maintainers whether sub-second custom deadlines are worth a tighter budget on reader-side store calls generally.
MarkAdminStop(commandB) restores a pending mark after CompleteReplan. The test therefore passes even if the replan deletes command A's mark.
Use a separate attempt for the replan-survival case. Stop that attempt immediately after CompleteReplan and assert AdminStopRequested. Keep command replacement and command-scoped clearing in a separate case.
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: fb58ac99-b21f-482c-8270-1eb7e38ceff8
Commits
Reviewing files that changed from the base of the PR and between bc86d9e and afb0d87.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Review of 01b493d (this PR's change on top of #4622's current head, which I merged in first; the only conflicts were the finishStop call sites #4622 reshaped, and finishStop now reads the receipt's flag).
The approach holds: the player's own stop can reach any replica, so the mark has to be durable, and copying it into the receipt in the update that wins the attempt is the one place every finalizer already reads. The PR's handler test fails on the base for the administrator-stop cases and passes for the viewer-stop cases, as described.
Verified defects, each already raised in an earlier thread on this PR. I'm fixing both in a commit on this branch, so there's no need to change them yourself:
Medium: a second stop's refusal or failed send erases the first stop's mark. Stop A is delivered and the player starts leaving, then stop B (a second click mints a new command id) takes the mark over. If the player refuses B, or B's socket write fails, clearing B leaves no mark, and A's HTTP stop records stopped. A new handler case reproduces it. Fix: when a stop's mark is withdrawn and another stop of the same session is still unanswered on this replica, the mark passes to that stop.
Low: a stop with no control socket keeps its mark. Nothing was sent, so no player is carrying it out, but a viewer stop before the fallback records terminated. If the replica restarts before its in-memory fallback timer runs, that lasts for the whole 30 s while playback continues. The fallback's own stop id already records terminated when it wins, so the mark adds nothing there. It also contradicts the new playback-api.md text ("being sent to the player"). Fix: withdraw the mark on a missing lane too, before scheduling the fallback.
Also fixed: TestAdminStopMarkDB re-marked before it checked that the mark survives a replan, so that check couldn't fail. It now reads A's mark straight after CompleteReplan.
Not changed, with reasons, in the earlier threads and the summary: the refusal clear on the socket reader (the same 1 s budget the pause confirmation already spends on that reader), and the write under the ledger lock (inline below).
Maintainer decision: history now says terminated for a play whose client stop won with the mark, but attemptEndedByAdmin (410 vs 404 on a late progress or replan) and a repeat terminate's already_revoked still look only at the stop id. The PR keeps them unchanged on purpose. The player in that case has already left, so I'd leave them and note the split in the docs, rather than widen this PR.
A second administrator stop took the attempt's pending mark over from the
first. When the player refused the second one, or its send failed, clearing
it left no mark, and the first stop's player recorded `stopped`. Withdrawing
a stop's mark now hands it to another stop of the session still unanswered
on this replica.
A stop that could not reach the player because it has no control socket
also withdraws its mark now. Nothing is carrying it out, so a viewer stop
before the fallback is the viewer's own, and the fallback records the
administrator's end under its own stop id.
TestAdminStopMarkDB now checks the mark right after the replan, before a
second stop replaces it.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Describe the attribution as a heuristic.
If the viewer independently stops while an administrator command is pending, the stop also records terminated. The pending mark does not prove that the player carried out the command. Describe the time window as an attribution rule rather than proof of cause.
The attempt held a single pending-stop slot, so overlapping stops had to
hand it back and forth through each replica's in-memory command records.
That handover could race a refusal on the socket reader and restore a stop
the player had already refused, and it couldn't see a stop sent from
another replica before the player's control socket moved.
admin_stop_commands now holds each pending stop as {command_id: sent_at}.
A stop withdraws only its own entry, and the stop that wins the attempt
records the administrator's end when any entry is inside the window. A
stop marks only when this replica holds the player's lane, so a stop to a
player with no control socket writes nothing.
The migration hasn't merged anywhere, so it is rewritten in place.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewed head: 703adb1 (this PR's change on top of #4622 at 7d22771, which I merged in first). Rechecked on the same head: the validation board, CI, and overlap with main.
Fit: 9/10 · Readiness: 8/10 — conditional (assuming CI is green)
Fit: this makes the administrator's playback history say who ended a play, which is what the admin log is for. It does that on the server, for every native client, with one nullable column, no setting and no API change. Admin commands are rare, so the extra write per stop costs a low-end box nothing noticeable.
Readiness: the approach is sound and each behavior change is covered by a test that failed before it. The administrator-stop cases of the PR's handler test fail on the base. The two cases I added fail on 01b493d. The validation board check has now run and found no affected case. One open decision remains (below), and the final head wasn't shown live again after the review changed how pending stops are stored. The path the author reproduced live is unchanged.
Addressed
A second stop's refusal or failed send erased the first stop's mark (raised in the earlier review and by all three council members). Each pending stop now has its own entry (admin_stop_commands, {command_id: sent_at}), and a stop withdraws only its own. A round-2 handover between stops was replaced in 703adb1, because it could race a refusal and couldn't see a stop sent from another server. The migration hasn't merged anywhere, so it was rewritten in place.
A stop to a player with no control socket kept its mark, which turned the viewer's own stop into terminated for up to 30 s if the server restarted before its fallback ran. Such a stop now records nothing, and its fallback records the administrator's end under its own stop id.
The replan test couldn't fail. It now checks the mark straight after the replan.
The commandLocal lock comment and the playback-api.md wording now match the code.
Answered, not changed
The refusal clear is a store write of up to 1 s on the socket reader, the same budget the pause confirmation already spends there. Making it asynchronous would let a viewer stop sent right after a refusal win before the clear lands.
The mark write runs under the handler-wide command lock (disclosed in the PR). Moving it before the lock would let a stale or duplicate command take a mark it never withdraws.
A failed mark or withdrawal falls back to the old behavior or lapses after 30 s. The rolling-upgrade gap is in the PR's risks.
Left for the maintainers
Maintainer decision: history now records terminated when the player's own stop won with a stop pending, but progress and replan (410 vs 404) and a repeat terminate's already_revoked still judge an administrator's end by the stop id alone. The player has already left in that case, so I'd keep this PR as it is and document the split. Unifying them would change what clients get back.
Low: a control socket that connects in the instant between the lane check and the send gets an unmarked stop, which records as before this change. Skipping the send when no lane is open would close it. A retry under the same command id on another server after the socket moved, and expired entries left on the row by a failed withdrawal, are smaller still.
Checks
Validated features: no validation task links this PR or [bug] An administrator's stop can be recorded as stopped by the viewer #4616, and no passed case covers an administrator's stop or a history end reason. The nearest are the Distributed transcode nodes failover cases (Server and Web admin), which end sessions through the same stop paths: no behavior change, because with no administrator stop pending admin_stop_commands is NULL and the receipt flag stays unset, so endReasonForStop returns what it did before. Validation tasks: none.
User manual: unaffected. The Active playback page describes Stop and Terminate but not history end reasons. The repository's API docs are updated in this PR.
Apple/Android parity: not applicable; this is a server change and needs no client change.
CI:Go vet and contracts ran for 47 minutes without finishing a step, on this PR and on fix(playback): don't count a seek before a detached stop as watch time #4622, while main finishes that job in 5 to 9 minutes. The same targets pass on 703adb1 locally in under two minutes (vet, the darwin node build, route inventory, OpenAPI and the v2 contract diff), so it looks like a stuck runner. I re-ran the job.
Tests:internal/playback/..., internal/api/handlers and internal/apiv2 against a freshly migrated Postgres, golangci-lint on the changes, and make verify-migrations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bugSomething isn't workingpriority: P2Limited scope, workaround exists, or polishsize/L200–499 added + deleted lines (all files); change volume, not priority.stackedBase is another open PR; merge in stack order named in the body
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #4616
Related issue: N/A
Validation tasks: none
Other clients: Apple N/A (no client change needed); Android N/A (no client change needed); Roku N/A (no client change needed)
An administrator's stop could be recorded in history as
end_reason: "stopped", as if the viewer had stopped. The stop command recorded nothing durable when it was sent. When the player confirmed, the server removed the live session at once and stopped the attempt under the administrator's stop id afterwards. A player that sends its own stop as it leaves, as the web player and Android do, could reach the attempt first, and its stop was recorded as the viewer's. On a Silo dev deployment with a transcode node, the web player showed "An administrator ended this playback session" while history recordedstopped.This is stacked on #4622 and targets its branch, because both change the attempt's stop statement; review that one first. It does not depend on #4623.
Approach
The attempt now records each pending stop, by command id and when it was sent, written before the stop goes out and only when this server holds the player's control socket. The stop that wins the attempt copies whether one was pending into its stop receipt, in the same update that wins, so retries, takeovers and the lifecycle sweep all read the same answer. A client stop that won while one was pending records
terminated.Each stop withdraws only its own entry, when it can't be sent or the player refuses it, so overlapping stops, sent from any server, don't clear each other. An entry older than 30 seconds no longer counts, so one whose command was lost (a restart, a failed fallback, a refusal that reached another server) can't turn a much later viewer stop into the administrator's. A stop to a player with no control socket records nothing: its fallback ends the session under the administrator's stop id. Neither write touches
updated_at, which the idle expiry reads as activity.The progress and replan answers (
410after an administrator's end) and a repeat terminate are unchanged.Validation
stoppedin both runs while the player showed the administrator's notice; this branch recordsterminatedin all three runs.stoppedon main,terminatedhere. Controls on this branch: a viewer's stop with no command recordsstopped, and a viewer's stop after the player refused the admin stop recordsstopped.stopped) and passes here; its viewer-stop cases pass on both. New Postgres and memory-store tests pin the receipt flag, per-command withdrawal, the 30 s window and thatupdated_atdoesn't move; the Postgres ones are listed inscripts/ci/db-contracts.txt.TestAdminStopMarksPerCommandDBpins that withdrawing one stop leaves another.go test ./internal/api/handlers/ ./internal/playback/... ./internal/apiv2/with a freshly migrated Postgres, golangci-lint on the changes,make verify-migrations.Evidence: https://evidence.siloserver.org/r/silo-server/4616-admin-stop-end-reason/
Risks
One nullable JSONB column, added without a default. During a rolling deploy, a stop that an older replica sends doesn't set the mark, so that play can still record
stopped, as before.The admin stop command now makes one bounded write (up to 1 s) before it reaches the player, under the command ledger's lock, and a refused stop makes one on the socket reader.
A viewer who stops on their own within moments of an administrator's stop reaching their player is recorded as
terminated. A control socket that connects in the instant between the lane check and the send gets an unmarked stop, which records as before this change.Checklist
Council review
Plan round on
4eb4d4a86(before implementing): Sol, Opus and Gemini, no scores. Adopted then: decide the reason in the stop's own update and keep it in the receipt (Opus, Sol); scope the mark to its command (Sol); include the lifecycle sweep's caller (Gemini). Keeping the mark on the no-socket path (Opus, Gemini) was reversed in review.The background review this PR opened with: Sol posted findings on afb0d87 (no score recorded); no Opus or Gemini review appears on the PR.
Review rounds: 3, last reviewed 703adb1
Fixed: a second stop's refusal or failed send erased the first stop's mark (now one entry per command); a stop with no control socket left a mark for the viewer's own stop; the replan test couldn't fail. Answered: the refusal clear stays on the socket reader (the pause confirmation already spends the same budget there) and the mark write stays under the ledger lock (moving it lets a stale command take a mark it never withdraws). Left open for the maintainers: progress, replan and a repeat terminate still judge an administrator's end by the stop id alone, and a socket that connects between the lane check and the send gets an unmarked stop.
AI Disclosure
Note
Record player stops as
terminatedwhen an admin stop is pendingMarkAdminStop) before dispatching. If the player's own stop reaches the server first within the 30-secondAdminStopPendingForwindow, the stop receipt recordsAdminStopRequestedand the end reason becomesterminated.ClearAdminStopwithdraws a mark when a stop is refused or fails to dispatch, and can transfer it to another pending stop command for the same session.admin_stop_command_id/admin_stop_requested_atcolumns.stoppednow recordterminatedwhen an admin stop was pending within 30 seconds; seeendReasonForStopin playback_service.go and the new migration.Macroscope summarized b1dc724.