fix(MQTTTransport): reply with error instead of silently dropping malformed input (F-063)

Invalid JSON or a missing 'cmd' field on control/command previously logged
a WARNING on serial and returned with no reply at all — a client waiting
on control/ack had no way to tell "malformed request" apart from "message
never arrived" or "device offline," all three looking identical until its
own timeout fired.

Both onMessage() drop paths now publish an ERROR to control/ack before
returning: { "status": "ERROR", "type": "parse_error", "message": "..." }.
Unparseable JSON necessarily has no req_id (nothing to read it from); a
valid-but-cmd-less message echoes req_id if one was present. The heap-guard
drop above these two (hasHeapForPublish() check) is untouched — that one's
silence is deliberate, protecting against allocation under critical heap
pressure (see F-055), not something this fix should touch.

Bumped to v2.2.1. Verified: pio run -e vesper-std-v1 -e agnus-v1 both build clean.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-21 18:06:26 +03:00
co-authored by Claude Sonnet 5
parent 391ecb63fc
commit 4ea581af5b
6 changed files with 75 additions and 5 deletions
+27
View File
@@ -75,6 +75,7 @@ Check `git log -- src/Version.hpp` for the real bump history before tagging a ne
| F-060 | `system.set_identity` — sysadmin override of factory-set device identity (serial/hw_family/hw_revision) | v2.1.0 | Stable |
| F-061 | Fix: `LegacyResponseAdapter` — v1 tablets saw device as "unavailable" while playing, due to `system.status` reply schema mismatch | v2.1.1 | Stable (temporary migration scaffolding) |
| F-062 | MQTT topic spec v2 — restructured topics (`control/command`/`control/ack`/`control/reports`/`status/playback`/`system/*`), LWT, `req_id` correlation, per-topic ON/OFF switches (`mqtt.set_topics`) | v2.2.0 | Stable |
| 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 |
---
@@ -1120,3 +1121,29 @@ Verified: `pio run -e vesper-std-v1` and `pio run -e agnus-v1` both build clean
paths both touched).
Subsystem: `src/Communication/Drivers/MQTTDriver/MQTTDriver.hpp`, `src/Communication/Drivers/MQTTDriver/MQTTDriver.cpp`, `src/Communication/Transport/MQTTTransport/MQTTTransport.hpp`, `src/Communication/Transport/MQTTTransport/MQTTTransport.cpp`, `src/Communication/Handlers/MQTTHandler/MQTTHandler.hpp`, `src/Communication/Handlers/MQTTHandler/MQTTHandler.cpp`, `src/Communication/CommandBus/CommandEnvelope.hpp`, `src/Communication/CommandBus/CommandResult.hpp`, `src/Communication/CommandBus/CommandBus.cpp`, `src/Communication/CommunicationRouter/CommunicationRouter.hpp`, `src/Communication/CommunicationRouter/CommunicationRouter.cpp`, `src/ConfigManager/ConfigManager.hpp`, `src/ConfigManager/ConfigManager.cpp`, `src/Player/Player.cpp`
---
### F-063 — Fix: malformed `control/command` input silently dropped
Found during manual QA of F-062: sending invalid JSON (e.g. a missing comma or bracket) to
`control/command` logged `[WARN][MQTTTransport] JSON parse error: IncompleteInput — dropping message`
on serial, but published nothing to `control/ack`. A caller had no way to distinguish "malformed
request" from "message never arrived" or "device offline" — all three looked identical from the
client's side: silence until its own timeout fired.
**Fix.** Both silent-drop paths in `MQTTTransport::onMessage()` now reply with an `ERROR` on
`control/ack` before returning, instead of just logging and returning:
- Unparseable JSON → `{ "status": "ERROR", "type": "parse_error", "message": "Invalid JSON: <reason>" }`.
No `req_id` on this reply — one can't be read out of input that failed to parse.
- Valid JSON but missing `cmd` → same shape, `"message": "Missing required field: cmd"`. Echoes
`req_id` if the JSON was otherwise valid and included one.
The pre-existing heap-guard drop (`MQTTDriver::hasHeapForPublish()` check, top of `onMessage()`) is
deliberately **not** changed — that guard exists specifically to avoid allocating under critical heap
pressure (see F-055), and a parse-error reply is cheap enough not to need the same protection, but the
guard itself must stay silent by design.
Verified: `pio run -e vesper-std-v1` builds clean.
Subsystem: `src/Communication/Transport/MQTTTransport/MQTTTransport.cpp`