fix(Communication): add LegacyResponseAdapter — v1 tablets saw device as unavailable while playing (F-061)

LegacyAdapter already translates incoming v1 requests to v2 internal
commands, but v2 handler replies used v2-only conventions (namespaced
type strings, data nested under "data", UPPERCASE status enum,
object-keyed strike_counters). A v1-only Flutter app polling
system.status never recognised the reply, hit its own 5s request
timeout, and its catch block explicitly set the UI to "unavailable" —
even though the device was playing correctly and had already replied
in time. Not a connectivity bug; a pure reply-schema mismatch.

Adds LegacyResponseAdapter, the reply-side mirror of LegacyAdapter: a
narrow, allowlisted translator that rewrites a CommandResult back into
v1 shape, but only for replies to requests whose original envelope
version was 1. Wired into WebSocket, MQTT, and HTTP's general command
path by capturing envelope.version before CommandBus::dispatch()
overwrites it to 2. v2 clients and all other reply types are
untouched, byte-for-byte.

This is deliberately temporary migration scaffolding for the v1→v2
tablet rollout window, not new permanent architecture — designed to be
deleted alongside LegacyAdapter in one PR once fleet telemetry shows
zero v1 requests. Full rationale and removal steps in
docs/architecture/legacy-response-adapter.md.

Verified: pio run across all four environments (vesper-std-v1,
agnus-v1, agnus-mini-v1, bespoke-rs485-v1).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-17 22:44:12 +03:00
co-authored by Claude Sonnet 5
parent 2707594f65
commit 230c1edfed
8 changed files with 323 additions and 27 deletions
+38
View File
@@ -70,6 +70,7 @@ Every feature — user-facing or significant internal mechanism — is listed he
| F-058 | Fix: NTP sync RTC corruption on flaky internet — de-dup guard, retry cooldown, large-jump consensus check | v2.1.7 | Stable |
| F-059 | Fix: partition table mismatch blocking safe OTA to pre-restructure field devices | v2.1.7 | Stable |
| F-060 | `system.set_identity` — sysadmin override of factory-set device identity (serial/hw_family/hw_revision) | v2.1.7 | Stable |
| F-061 | Fix: `LegacyResponseAdapter` — v1 tablets saw device as "unavailable" while playing, due to `system.status` reply schema mismatch | v2.1.7 | Stable (temporary migration scaffolding) |
---
@@ -995,3 +996,40 @@ This adds a narrow, deliberate exception: a new `system.set_identity` command le
Not gated behind an additional `confirm` field in the command body — the console UI is expected to require its own confirmation step before ever publishing this command, so no device-side friction was added on top of that.
Subsystem: `src/ConfigManager/ConfigManager.hpp`, `src/ConfigManager/ConfigManager.cpp`, `src/Communication/Handlers/SystemHandler/SystemHandler.hpp`, `src/Communication/Handlers/SystemHandler/SystemHandler.cpp`
---
### F-061 — Fix: `LegacyResponseAdapter` — v1 tablets saw device as "unavailable" while playing
`LegacyAdapter` already translates incoming v1 **requests** (tablets still on the old Flutter app,
which never sends a `"v"` field) into v2 internal commands. What was missing was the reverse: v2
handlers reply using v2 conventions — `system.status`'s reply used `type:"system.status"` with fields
under `data`, UPPERCASE status strings (`"PLAYING"`/`"STOPPED"`/...), `time_elapsed_ms`, and
`strike_counters` as an object keyed `"0".."15"` — none of which the v1 app recognises. It polls for
`type:"current_status"` with fields under `payload`, lowercase status strings, `time_elapsed`, and
`strike_counters` as an array.
Because the reply never matched, the v1 app's own 5-second request timeout fired every time, and its
`catch` block explicitly set `playbackStatus: PlaybackStatus.unavailable` — **while the device was
actually playing correctly and had already replied.** This was reported as "the board shows
unavailable sometimes while it's playing" and traced to this schema mismatch, not a real
connectivity/timeout issue. The async `playback` INFO push (`Player::setStatus()`) was checked too and
was already v1-compatible — no changes needed there.
**Fix.** Added `LegacyResponseAdapter` (`src/Communication/CommandBus/LegacyResponseAdapter.{hpp,cpp}`)
— a narrow, allowlisted translator that rewrites a `CommandResult` back into v1 shape, but only for
replies to requests whose *original* envelope version was 1 (v2 clients and all other reply types are
untouched, byte-for-byte). Each transport's reply lambda now captures `isLegacyRequest` (from
`envelope.version` before `CommandBus::dispatch()` overwrites it to 2) and routes through the adapter
when true. Wired into WebSocket, MQTT, and HTTP's general command path; not touched: HTTP's
`system.status` shortcut route (hardcodes v2) and UART (board-to-board only, no known v1 peers).
This is deliberately temporary migration scaffolding, not new permanent architecture — the plan is to
update all devices (firmware + tablets) to v2 and retire both `LegacyAdapter` and
`LegacyResponseAdapter` together once fleet telemetry shows zero v1 requests. Full rationale, the
before/after schema table, and the exact removal steps are in
[architecture/legacy-response-adapter.md](../architecture/legacy-response-adapter.md).
Verified: `pio run -e vesper-std-v1` builds clean (all four environments share the touched files).
Subsystem: `src/Communication/CommandBus/LegacyResponseAdapter.hpp` (new), `src/Communication/CommandBus/LegacyResponseAdapter.cpp` (new), `src/Communication/Transport/WebSocketTransport/WebSocketTransport.cpp`, `src/Communication/Transport/MQTTTransport/MQTTTransport.cpp`, `src/Communication/Transport/HTTPTransport/HTTPTransport.cpp`