GRI-2073: unassign a device from a playlist #214

Merged
vivy merged 6 commits from feature/GRI-2073-unassign-device-playlist into dev 2026-11-15 12:34:52 +00:00
Member

Closes #209.

Summary

  • DELETE /api/v1/devices/{device_id}/playlist: removes the assignment, same ContentAssign permission and campus-visibility rules as POST, idempotent (204 whether or not a row existed), pushes PlaylistCleared to the device's live connection.
  • New ServerControl::PlaylistCleared message (additive, old clients read it as Unknown).
  • Client: drops state.playlist to None on receipt; the existing idle-screen path takes over. Cache and manifest untouched.
  • plan/decisions/0014-unassigned-device-shows-idle.md: the "what does an unassigned device show" decision the issue asked for, before building anything.
  • plan/server/rest-api.md and plan/shared/protocol.md updated.

Panel side (checkbox, Save-time diffing, Devices-screen "none") is #210, not in this PR.

Test plan

  • cargo test -p shared -p client --lib — new wire-format and session tests pass
  • cargo test -p server --test playlist_integration (against a real Postgres) — unknown device → 404, no-assignment unassign → idempotent 204, assign-then-unassign removes the row and pushes PlaylistCleared, retried unassign stays idempotent
  • scripts/local-gates.sh --rust-only — every gate passed locally
Closes #209. ## Summary - `DELETE /api/v1/devices/{device_id}/playlist`: removes the assignment, same `ContentAssign` permission and campus-visibility rules as `POST`, idempotent (`204` whether or not a row existed), pushes `PlaylistCleared` to the device's live connection. - New `ServerControl::PlaylistCleared` message (additive, old clients read it as `Unknown`). - Client: drops `state.playlist` to `None` on receipt; the existing idle-screen path takes over. Cache and manifest untouched. - `plan/decisions/0014-unassigned-device-shows-idle.md`: the "what does an unassigned device show" decision the issue asked for, before building anything. - `plan/server/rest-api.md` and `plan/shared/protocol.md` updated. Panel side (checkbox, Save-time diffing, Devices-screen "none") is #210, not in this PR. ## Test plan - [x] `cargo test -p shared -p client --lib` — new wire-format and session tests pass - [x] `cargo test -p server --test playlist_integration` (against a real Postgres) — unknown device → 404, no-assignment unassign → idempotent 204, assign-then-unassign removes the row and pushes `PlaylistCleared`, retried unassign stays idempotent - [x] `scripts/local-gates.sh --rust-only` — every gate passed locally
GRI-2073: unassign a device from a playlist
All checks were successful
CI / cargo fmt (pull_request) Successful in 29s
CI / the pre-push hook (pull_request) Successful in 44s
CI / cargo clippy (pull_request) Successful in 2m7s
CI / cargo deny advisories (pull_request) Successful in 1m58s
CI / cargo deny (pull_request) Successful in 2m14s
CI / repository boundary (pull_request) Successful in 40s
CI / frontend-web (pull_request) Successful in 1m41s
CI / cargo test (pull_request) Successful in 3m53s
CI / Notify gate failed (pull_request) Has been skipped
CI / CI (pull_request) Successful in 5s
5f3512eebf
DELETE /api/v1/devices/{device_id}/playlist removes the assignment and
pushes PlaylistCleared to the device's live connection, idempotently.
The client drops to its existing idle screen on receipt, per ADR 0014.
vivy requested changes 2026-11-15 10:29:49 +00:00
Dismissed
vivy left a comment

One gap blocks this, everything else reads well (route, permission + campus check, idempotent 204, client drops the playlist and keeps the cache).

A device that is offline when it is unassigned keeps showing the old playlist for ever. unassign_playlist only pushes PlaylistCleared to a live connection. On reconnect, ws.rs:432 calls push_current_assignment, which returns Ok(()) when there is no assignment (handlers.rs:611), so nothing tells the client. The client still has state.playlist = Some(..) in its store and plays it. This is exactly the case #209 exists to stop: a screen must never keep showing old content.

Fix: in push_current_assignment, when there is no assignment (and when the assigned playlist was deleted), push ServerControl::PlaylistCleared instead of returning. It is idempotent on the client. Please add an integration test: assign, disconnect, unassign, reconnect -> the first control frame is playlist_cleared.

Non-blocking: ADR 0014 should say this reconnect rule too.

One gap blocks this, everything else reads well (route, permission + campus check, idempotent 204, client drops the playlist and keeps the cache). **A device that is offline when it is unassigned keeps showing the old playlist for ever.** `unassign_playlist` only pushes `PlaylistCleared` to a live connection. On reconnect, `ws.rs:432` calls `push_current_assignment`, which returns `Ok(())` when there is no assignment (`handlers.rs:611`), so nothing tells the client. The client still has `state.playlist = Some(..)` in its store and plays it. This is exactly the case #209 exists to stop: a screen must never keep showing old content. Fix: in `push_current_assignment`, when there is no assignment (and when the assigned playlist was deleted), push `ServerControl::PlaylistCleared` instead of returning. It is idempotent on the client. Please add an integration test: assign, disconnect, unassign, reconnect -> the first control frame is `playlist_cleared`. Non-blocking: ADR 0014 should say this reconnect rule too.
GRI-2073: push PlaylistCleared on reconnect after an offline unassignment
Some checks failed
CI / the pre-push hook (pull_request) Successful in 44s
CI / cargo fmt (pull_request) Successful in 30s
CI / cargo deny (pull_request) Successful in 1m50s
CI / cargo clippy (pull_request) Successful in 2m57s
CI / cargo deny advisories (pull_request) Successful in 2m37s
CI / repository boundary (pull_request) Successful in 28s
CI / cargo test (pull_request) Failing after 3m33s
CI / frontend-web (pull_request) Successful in 2m30s
CI / CI (pull_request) Failing after 46s
CI / Notify gate failed (pull_request) Successful in 12s
57016c9e1f
push_current_assignment returned Ok(()) when a reconnecting device had
no assignment, so a device that went offline before being unassigned
kept its last playlist forever. Push PlaylistCleared in that case too.
push_current_assignment was pushing PlaylistCleared on any reconnect
with no current assignment, including a device that connects before
ever being assigned - breaking existing ws_integration tests that
rely on that ordinary sequence. Track the debt explicitly instead:
unassign_playlist marks pending-clear only when its own push found no
live connection, and push_current_assignment consumes that mark to
decide whether to resend PlaylistCleared on reconnect.
GRI-2073: cargo fmt
All checks were successful
CI / cargo fmt (pull_request) Successful in 1m3s
CI / the pre-push hook (pull_request) Successful in 1m19s
CI / cargo clippy (pull_request) Successful in 3m44s
CI / cargo deny advisories (pull_request) Successful in 2m32s
CI / cargo deny (pull_request) Successful in 2m55s
CI / repository boundary (pull_request) Successful in 47s
CI / cargo test (pull_request) Successful in 4m33s
CI / frontend-web (pull_request) Successful in 1m50s
CI / Notify gate failed (pull_request) Has been skipped
CI / CI (pull_request) Successful in 20s
cf5a74e9df
vivy approved these changes 2026-11-15 12:34:49 +00:00
vivy left a comment

Approved on cf5a74e. The offline case is fixed: unassign marks a pending clear when the push reaches nobody, and the reconnect pays it; a never-assigned device gets no push. Covered by a_reconnect_after_an_offline_unassignment_clears_the_playlist.

Known limit, not blocking the test deploy: pending_clear is in memory only. If the server restarts while an unassigned device is still offline, the mark is lost and that device keeps its old playlist after it reconnects. Follow-up: keep the mark in the database (or let the client report its playlist id in hello).

Approved on cf5a74e. The offline case is fixed: unassign marks a pending clear when the push reaches nobody, and the reconnect pays it; a never-assigned device gets no push. Covered by a_reconnect_after_an_offline_unassignment_clears_the_playlist. Known limit, not blocking the test deploy: pending_clear is in memory only. If the server restarts while an unassigned device is still offline, the mark is lost and that device keeps its old playlist after it reconnects. Follow-up: keep the mark in the database (or let the client report its playlist id in hello).
vivy merged commit 46a980cf99 into dev 2026-11-15 12:34:52 +00:00
vivy deleted branch feature/GRI-2073-unassign-device-playlist 2026-11-15 12:34:53 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Grimoirix/grimoire-of-digital-signage!214
No description provided.