feat(Player): "loading" status while a melody downloads + playback_failed report (F-068)

A play that needed a download was ACKed SUCCESS and then nothing was
visible until playback started — and a failed download was only logged.

- New PlayerStatus::LOADING: status/playback publishes action "loading"
  (pid/speed/duration/source set) before the ACK, then "playing" on success
  or "idle" on failure.
- On failure after the ACK, control/reports gets
  { "type": "playback_failed", "payload": { "pid", "reason" } } (and a WS
  INFO of the same). The download task re-checks bells-disabled/overload
  before playing.
- playback.stop / forceStop during LOADING cancels the pending start
  ("Download cancelled — playback will not start"); the transfer finishes
  and is discarded. New plays are refused until it does, since the task
  still owns pid/_melodySteps. A mutex serialises the task's cancel-check +
  play() against the cancel path.
- "loading" is MQTT-only: v1 tablets map unknown WS playback actions to
  "unavailable" (F-061 symptom). system.status reports LOADING; the v1
  adapter maps it to "idle".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-29 20:25:27 +03:00
co-authored by Claude Opus 5.5
parent 46a1a2567f
commit b01e755c92
10 changed files with 238 additions and 34 deletions
+48
View File
@@ -80,6 +80,7 @@ Check `git log -- src/Version.hpp` for the real bump history before tagging a ne
| F-065 | `stopping` playback state formally documented (duration reached, bells finishing the current loop) — kept on `status/playback`, not suppressed | v2.3.0 | Stable |
| F-066 | Fix: stale retained `status/playback` — republished with the Player's real state on every MQTT (re)connect | v2.3.0 | Stable |
| F-067 | Specific `playback.play` / `playback.stop` ACK messages (busy, invalid params, not found, load failed, bells disabled, overload…) instead of a generic "Playback command failed"; `url` no longer sticky | v2.3.0 | Stable |
| F-068 | `loading` playback state while a melody downloads (MQTT `status/playback`), cancellable by `playback.stop`; `playback_failed` event on `control/reports` when an ACKed play never starts | v2.3.0 | Stable |
---
@@ -1292,3 +1293,50 @@ semantics used by the validator (`is<uint32_t>` on negatives/floats/2^32, `is<in
non-strings/null) confirmed with a host-side test.
Subsystem: `src/Player/Player.hpp`, `src/Player/Player.cpp`, `src/BellEngine/BellEngine.hpp`, `src/BellEngine/BellEngine.cpp`, `src/Communication/Handlers/PlaybackHandler/PlaybackHandler.hpp`, `src/Communication/Handlers/PlaybackHandler/PlaybackHandler.cpp`, `src/RFRemote/RFRemote.cpp`
---
### F-068 — `loading` state + `playback_failed` report for downloaded melodies
When a `playback.play` needed a download, the board replied SUCCESS and then nothing was visible until
playback started — and if the download failed, nothing at all (only a log line). The app had no way to
show progress or learn that the play it was told "succeeded" never happened.
**New `PlayerStatus::LOADING`.** The download branch of `Player::command()` now sets `LOADING` (published
on `status/playback` as `action: "loading"` with `pid`/`speed`/`duration`/`source` set, `started_at` 0)
*before* returning the SUCCESS ACK (`Melody download started — playback begins when it completes`),
then signals `MelodyDL`. The download task then:
- success → re-checks `playbackBlockedReason()` (bells may have been disabled / a bell overloaded
during the download) → `play()` → `playing`;
- any failure → `setStatus(STOPPED)` → `idle`, then `CommunicationRouter::sendPlaybackFailedNotification(pid, reason)`:
`control/reports` `{ "type": "playback_failed", "payload": { "pid", "reason" } }` plus a WebSocket INFO
of the same shape. Reasons are the F-067 strings (`Melody download failed`, `Melody failed to load: …`,
the two `Playback blocked: …`).
**Stop while loading = cancel.** `playback.stop` (and `forceStop()` from RF / the overload guard) during
`LOADING` sets `_cancelDownload` and goes `idle` immediately (ACK `Download cancelled — playback will
not start`). The HTTP transfer can't be aborted, so `MelodyDL` finishes it and discards the result
without playing or reporting. Until it does, `_downloadInFlight` stays true and new plays are rejected
with `Playback blocked: a cancelled melody download is still finishing — try again shortly` — the task
still owns `pid`/`_melodySteps`, so letting a fast-path play in would race it (previously a second play
during a download could rewrite `pid`/`url` under the running download).
**Race handling.** `_loadingMutex` (FreeRTOS mutex) serialises the download task's
"check cancel → play()/STOPPED" against `cancelLoading()`'s "re-check LOADING → cancel → STOPPED", so a
stop can't land between the cancel check and `play()`; if the task wins, the stop falls through to a
normal `forceStop()` of the playback that just started. The download itself runs outside the lock.
**`loading` is MQTT-only.** `setStatus()` skips the WebSocket broadcast for `LOADING`: the v1 tablet app
(`dart-message-handler.dart`) maps any unknown playback action to `PlaybackStatus.unavailable` — the
F-061 symptom — so WebSocket clients keep seeing `idle` → `playing` exactly as before. `playback_failed`
*is* sent over WebSocket, because v1 ignores unknown INFO types. `system.status` / `system.get_all`
report `"LOADING"`; `LegacyResponseAdapter` maps it to `"idle"` for v1 callers; the heartbeat's
`state` reports `idle` (unchanged payload).
**Phone app subscription.** `playback_failed` lives on `control/reports`, so the phone app now needs
that topic too (spec updated). It carries no `req_id` (as for every report) — correlate by `pid`; only
one download can be pending.
Verified: `pio run -e vesper-std-v1`, `-e agnus-v1` and `-e bespoke-rs485-v1` build clean.
Subsystem: `src/Player/Player.hpp`, `src/Player/Player.cpp`, `src/Communication/CommunicationRouter/CommunicationRouter.hpp`, `src/Communication/CommunicationRouter/CommunicationRouter.cpp`, `src/Communication/Handlers/SystemHandler/SystemHandler.cpp`, `src/Communication/CommandBus/LegacyResponseAdapter.cpp`