Skip to content

fix(playback): answer a repeat terminate with the converged receipt - #4553

Merged
Quick104 merged 2 commits into
mainfrom
fix/admin-terminate-repeat
Nov 19, 2026
Merged

Quick104 merged 2 commits into
mainfrom
fix/admin-terminate-repeat

Conversation

@Quick104

@Quick104 Quick104 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: reaches #1206 C1 and C2 (the administrator terminate path; a first terminate behaves as before)

Other clients: N/A (no client-visible change; only the HTTP answer to a repeated administrator terminate changes, and the web admin already treats both answers as "session gone")

Terminating a playback session that an administrator already terminated answers 404. The receipt schema has an already_revoked field described as "the call converged", but no request could ever set it, and the admin API doc said the opposite of the schema. A developer integrating a third-party monitor hit this when a retry of a terminate came back as an error.

A repeat terminate now answers 200 with authority_revoked: true, already_revoked: true, delivery: "none" and client_notified: false, and sends nothing to the player.

Approach

The first terminate stops the session's playback attempt row under a stop ID reserved for administrator ends. A repeat read that stopped row and then discarded it, fell through to looking for a live session, found none and answered 404. The end claim now reports which earlier stop won the row, and a terminate that finds an administrator stop there converges. This works on the server that holds the session and through the cross-replica relay.

What still answers 404, on purpose:

  • an unknown session;
  • a session that ended because its player stopped it or it expired. No administrator ended it, and answering 200 already_revoked would let a monitor report a viewer's own stop as a termination;
  • a session whose player carried out an administrator's stop, because the player's own stop is what the attempt row records;
  • a Jellyfin-protocol play, which keeps no attempt row;
  • any ended session once its attempt row lapses, at least 24 hours after the play started.

A session copy still live on the answering server is ended and its player told, as before. docs/admin-api.md, the handler comments and the OpenAPI descriptions now say the same thing.

The operation was already tagged naturally idempotent, so this makes the behaviour match the tag. jellycompat has no terminate route. The user manual does not describe terminate receipts.

Validation

  • Go tests for the handlers and apiv2 packages pass on this branch. New cases cover the repeat on the local path and through the relay.
  • OpenAPI and web types regenerate with no diff. Changed-line lint passed on the implementer's branch before I split it; it was not rerun on this branch.
  • On an isolated sandbox with a key holding admin:monitor:read and admin:sessions:control: first terminate 200 with already_revoked: false; repeat 200 with already_revoked: true and delivery: "none"; unknown session 404; no credential 401; read-only key 403. That run used the implementer's combined branch, which also carried the two other changes now in separate pull requests.
  • Not run: two API servers. The relay path is covered by the Go test only.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-4553/

Risks

  • A repeat terminate changes from 404 to 200. A consumer that treated 404 as "already gone" still gets a success.
  • The converged answer depends on the attempt row, so it stops after that row lapses.

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.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code, GitHub CLI
  • Model(s): claude-opus-5-5 (implementation and sandbox testing), claude-fable-5-2 (triage, review of the full diff, split into single-concern branches, this description)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: none yet beyond the second model's read of the full diff; no independent adversarial pass has run

🤖 Generated with Claude Code

Note

Fix repeated admin playback terminate to return converged receipt

  • A repeated terminate for a session already stopped by an administrator now returns an already-revoked receipt and sends no new command to the player's lane. admin_playback_terminate.go handles the new ErrSessionEndedByAdmin sentinel.
  • playback_end_claim.go adds the sentinel, which wraps playback.ErrSessionNotFound, and endSessionAsAdmin distinguishes an admin stop from other causes using the attempt record's earlier winning stop ID. Player stops, expiration, abandonment, and expired or missing records still return not found.
  • Updates API schema descriptions in openapi.json and admin-api.md.
  • Behavioral Change: repeat terminate now returns a converged receipt instead of not found when a prior admin stop has a persisted attempt row; no additional client command is dispatched.

Macroscope summarized 28ec69b.

A terminate of a session the server already ended for an administrator
answered 404, although the receipt schema promises already_revoked. The
end claim read the stopped attempt row and discarded it. It now reports
the earlier stop, and a terminate that finds an earlier administrator
stop answers 200 with already_revoked, delivery none, and dispatches
nothing, locally and through the cross-replica relay.

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 19, 2026
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 31 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

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: acd6d18d-40c5-4b43-aeb6-a22316ef53f6
Commits

Reviewing files that changed from the base of the PR and between bd40bd9 and 28ec69b.

Files selected for processing: 8

  • contracts/api/v2/openapi.json
  • docs/admin-api.md
  • internal/api/handlers/admin_playback_relay_test.go
  • internal/api/handlers/admin_playback_terminate.go
  • internal/api/handlers/admin_playback_terminate_test.go
  • internal/api/handlers/playback_end_claim.go
  • internal/apiv2/admin_playback_terminate.go
  • web/src/api/v2/schema.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 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-19T16:11:17.680476Z 28ec69b New commits
🔒 Security Review ✅ Completed 2026-11-19T16:13:46.825430Z 28ec69b New commits
ℹ️ About Codex in GitHub

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

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

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

@silo-kody

silo-kody Bot commented Nov 19, 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 ❌

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code impact: compat Breaks a supported client or server path priority: P2 Limited scope, workaround exists, or polish labels Nov 19, 2026
Comment on lines +62 to 68
if receipt.Finalized || !claimStopFinalization(ctx, store, sessionID, receipt.StopID) {
if stopped {
return nativeEndClaim{}
}
return nativeEndClaim{earlierStopID: receipt.StopID}
}
return nativeEndClaim{store: store, record: record, receipt: receipt, owned: true}

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 medium

Finalization takeover returns a first-terminate receipt for a repeat

After an expired lease is reclaimed, endSessionAsAdmin succeeds and terminateLocal sends another dismissal with already_revoked: false. Preserve the earlier stop identity during takeover and return the converged result after finalization.

Prompt for LLM
File internal/api/handlers/playback_end_claim.go, lines 62-68:

Finalization takeover returns a first-terminate receipt for a repeat

If an earlier administrator stop is unfinalized and its lease has expired, this retry acquires the lease and returns a normal owned claim, so `endSessionAsAdmin` returns success and `terminateLocal` dispatches another dismissal with `already_revoked: false`. Preserve the earlier stop identity when taking over finalization and return the converged result after finishing it.

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.

Leaving this as it is. A takeover happens when the earlier terminate stopped the row and then died before finishing. This request is the one that finalizes the end and writes its history, and nothing shows the player was ever told, so it dispatches and reports already_revoked: false. already_revoked: true is reserved for a request that did nothing: the receipt documents it as "nothing was dispatched, delivery is none".

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That distinction makes sense. A finalization takeover is completing work the earlier request may not have finished, so dispatching the dismissal and returning already_revoked: false is consistent with the receipt’s meaning.

I withdraw the suggestion to return the converged receipt in that case.

Comment on lines +226 to +230
err := h.dropLiveSessionByID(ctx, sessionID)
if errors.Is(err, playback.ErrSessionNotFound) && claim.earlierStopID == adminStopID(sessionID) {
return ErrSessionEndedByAdmin
}
return err

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 medium

A stale replica dispatches another dismissal on a repeated terminate

If dropLiveSessionByID removes a stale session copy, the repeat sends another dismissal with already_revoked: false. Return the converged result after removal when earlierStopID identifies an administrator stop.

Prompt for LLM
File internal/api/handlers/playback_end_claim.go, lines 226-230:

A stale replica dispatches another dismissal on a repeated terminate

When an earlier administrator stop left a live session copy on another replica, `dropLiveSessionByID` succeeds and this branch returns nil, so the repeat dispatches another dismissal and reports `already_revoked: false`. Return the converged result after dropping the stale copy when `earlierStopID` identifies an administrator 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.

Leaving this as it is, for the same reason. If this server still holds a live copy, its player is still connected and has not been dismissed, so ending that copy and telling the player is real work this request did. Answering already_revoked: true with delivery: none there would report a dispatch that happened as one that did not. The relay test for a lane owner that never replied depends on the copy being ended and its player told.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That makes sense. A prior administrator stop in the attempt row does not necessarily mean this server’s live session copy has been dismissed. If the copy is still present, removing it and notifying its player is work performed by this request, so returning the normal termination receipt is appropriate.

I withdraw the suggestion. The converged receipt should apply when there is no live copy to end and the attempt row records an administrator stop.

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

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

One finding, in the documentation. The code change holds up: the new repeat tests fail on main with playback session not found and pass on this head, on the local path and through the relay.

Comment thread docs/admin-api.md Resolved
…attempt row records

A player that confirms an administrator's stop over the control socket can
win the attempt row under the administrator stop id, so a later terminate
converges instead of answering 404. Describe the answer by which stop the
row records, and cover the converged repeat in client_notified.

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

silo-kody Bot commented Nov 19, 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 ❌
⚠️ 4 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers
  • Detach mandatory cleanup from request cancellation and bound its lifetime
  • Preserve durable media identity and share identity-evidence precedence
  • Bound decoder throughput trades and share direct-play eligibility

@Quick104

Copy link
Copy Markdown
Contributor Author

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

Review summary

Reviewed head: 28ec69b21 (the author's be6a3dafc plus one docs commit from this review).

A repeat administrator terminate now converges instead of answering 404, and the code does what the description says. The end claim reports which stop won the attempt row, and only a row stopped under the administrator stop ID gives already_revoked. A player's own stop, an expiry, an abort, a Jellyfin play and a lapsed row still answer 404. Existing callers that check errors.Is(err, playback.ErrSessionNotFound), including the stop-command fallback, behave as before.

Addressed

  • The docs said a session whose player carried out an administrator's stop answers 404. When the player's confirmation over the control socket reaches the attempt row first, the server records an administrator end and a later terminate converges. docs/admin-api.md, the handler comment and the OpenAPI text now describe the answer by which stop the row records, and client_notified covers the converged repeat (28ec69b).

Checked and left as is

  • The relay's no-reply fallback still answers 503 to a repeat when the server holding the player's lane doesn't answer. That is needed: the request that timed out may itself have written the administrator stop, so the fallback can't tell a repeat from a first terminate whose answer was lost.
  • The two earlier threads about finalization takeover and a live local copy: I agree with the replies there. In both cases this request does real work, so already_revoked: false is the honest answer.

Validation

  • TestAdminTerminateRepeatConverges/terminate and the relayed repeat in TestAdminTerminateRelaysToTheLaneOwner fail on main with playback session not found and pass on this branch. To run them on main I removed one negative check that names ErrSessionEndedByAdmin, the error this PR adds.
  • A cross-provider review (Codex, gpt-6.2-sol) ran on be6a3dafc. Its docs finding is the one fixed above. Its other findings describe behaviour that is the same on main and went to the maintainers separately.
  • Validated features: Active sessions / now-playing / remote control — Server #1206 C1 and C2 have no recorded results yet, so no passed case can regress. The first terminate's answer is unchanged.
  • The web admin already shows already_revoked receipts (AdminSessionActions.tsx) and doesn't depend on the 404.

User manual: unaffected. The active-playback page doesn't describe terminate receipts.
Other clients: no client-visible change; Apple, Android and Roku don't call this endpoint. jellycompat has no terminate route.

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

Fit: it makes an operation already tagged naturally idempotent behave that way, within the existing contract field, and adds no setting. Readiness: the behaviour is shown by tests that fail on main, the author's sandbox run, and docs that now match the code. The only unproven path is two API servers, which is covered by the relay test alone.

@Quick104
Quick104 merged commit 53154a1 into main Nov 19, 2026
20 checks passed
@Quick104
Quick104 deleted the fix/admin-terminate-repeat branch November 19, 2026 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: compat Breaks a supported client or server path priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant