fix(CommunicationRouter): republish status/playback on every MQTT (re)connect (F-066)

status/playback is retained but was only published on a Player transition.
After a power loss mid-melody the Player boots straight into STOPPED with no
transition, so the broker kept serving the old "playing" forever. The
MQTT on-connect callback now publishes Player::getPlaybackSnapshot() on
every CONNECT (not just the first after boot) — "idle" after a reboot, the
live state after a plain reconnect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-29 20:11:20 +03:00
co-authored by Claude Opus 5.5
parent fe5ab6223c
commit 92a0a8d5e8
4 changed files with 29 additions and 2 deletions
+21
View File
@@ -78,6 +78,7 @@ Check `git log -- src/Version.hpp` for the real bump history before tagging a ne
| F-063 | Fix: malformed `control/command` input (bad JSON, missing `cmd`) now gets an `ERROR` reply on `control/ack` instead of being silently dropped | v2.2.1 | Stable |
| F-064 | Richer `status/playback` — `pid`, `speed`, `duration`, `started_at`, `source`, `ts` (same fields on the WebSocket playback INFO event); command origin carried on `CommandEnvelope` | v2.3.0 | Stable |
| 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 |
---
@@ -1218,3 +1219,23 @@ Documented semantics (mqtt-events.md → States): entered only from `playing` wh
No firmware change. Subsystem: `docs/reference/mqtt-events.md`, `docs/reference/vesper_mqtt_topic_spec_v2.md`,
`docs/reference/api-reference.md`
---
### F-066 — Fix: stale retained `status/playback` after power loss
`status/playback` is retained, but was only ever published by `Player::setStatus()` on a *transition*.
If the board lost power (or its link) mid-melody, the last retained message was `playing` — and after
the reboot the Player starts in `STOPPED` without a transition, so nothing ever overwrote it. The
broker kept serving "playing" to every new subscriber indefinitely.
**Fix.** The `MQTTDriver` on-connect callback registered in `CommunicationRouter::begin()` (which already
ran `reportBootOnce()`) now also calls `publishPlayback(_player->getPlaybackSnapshot())`. It runs on
**every** CONNECT, not just the first after boot: after a reboot it publishes `idle`; after a plain
reconnect it publishes the live state (which also refreshes `ts`/`time_elapsed` for anyone who
subscribed while the board was offline). Same gates as any other playback publish: `playback` topic
switch, heap guard.
Verified: `pio run -e vesper-std-v1` builds clean.
Subsystem: `src/Communication/CommunicationRouter/CommunicationRouter.cpp`