From 83b2b2547ff96acd7395931863fabb5568ef4553 Mon Sep 17 00:00:00 2001 From: bonamin Date: Tue, 29 Sep 2026 20:26:32 +0300 Subject: [PATCH] docs(req_id): confirm req_id survives playback.play/stop incl. the download path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Verified: MQTTTransport reads req_id into the envelope, CommandBus::dispatch() runs the handler and calls reply() synchronously on the same task, and Player::command() returns immediately in every case — the download path only signals MelodyDL and never defers the ACK. So req_id is echoed on every playback.play/stop ACK, including v1 "playback" translated by LegacyAdapter. Documents the invariant in CommandBus::dispatch() and the topic spec, plus the cases where no reply is sent at all (heap guard, command switch off, broker down). No behaviour change. Co-Authored-By: Claude Opus 5.5 --- docs/reference/vesper_mqtt_topic_spec_v2.md | 2 ++ src/Communication/CommandBus/CommandBus.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/docs/reference/vesper_mqtt_topic_spec_v2.md b/docs/reference/vesper_mqtt_topic_spec_v2.md index d642b4b..1c989ca 100644 --- a/docs/reference/vesper_mqtt_topic_spec_v2.md +++ b/docs/reference/vesper_mqtt_topic_spec_v2.md @@ -48,6 +48,8 @@ This lets a device "breathe" — a fleet-monitoring-only install with no phone a - **Always optional.** A request without `req_id` gets a reply without `req_id` — this is deliberate so v1 clients and any caller not fanning requests out over a shared channel keep working unchanged. - **Bus-wide plumbing, MQTT-only today.** `req_id` lives on `CommandEnvelope`/`CommandResult` in the shared `CommandBus` core (see [CommandBus](../../src/Communication/CommandBus/README.md)), not bolted onto MQTT alone — the intent is that any transport where multiple logical senders share one channel (multiple devices on one broker; a future multiplexed transport) can use the same mechanism to route replies. Only `MQTTTransport` currently reads it from the request; WebSocket, HTTP and UART ignore it and their replies never carry it. +- **Replies are never deferred.** `CommandBus::dispatch()` sends the reply synchronously, on the transport's own task, right after the handler returns — no command replies from another task/context, so `req_id` can't be lost. This includes `playback.play` when a download is needed: the ACK (`Melody download started — …`, with `req_id`) goes out immediately, and the later outcome is reported on `status/playback` (`loading` → `playing`/`idle`) and, on failure, `control/reports` `playback_failed` — neither of which carries `req_id` (match by `pid`). +- **When no reply arrives at all:** the MQTT heap guard drops incoming commands silently under critical heap pressure, and a reply is dropped if the `command` switch is off or the broker link is down at reply time. A client should still time out. - **No access control yet.** Any caller can set any `req_id` today. If needed later, safeguards (e.g. restricting who may set one, or validating format) can be added without a wire-format change. ## Malformed Input diff --git a/src/Communication/CommandBus/CommandBus.cpp b/src/Communication/CommandBus/CommandBus.cpp index 5cef2a4..0a5a97f 100644 --- a/src/Communication/CommandBus/CommandBus.cpp +++ b/src/Communication/CommandBus/CommandBus.cpp @@ -53,6 +53,10 @@ void CommandBus::dispatch(CommandEnvelope& envelope) { LOG_DEBUG(TAG, "Dispatching: %s", envelope.command.c_str()); CommandResult result = it->second->execute(envelope); + // The reply always goes out here, synchronously, on the transport's own task — + // which is what guarantees req_id is echoed. Work that finishes later (e.g. a + // playback.play that must download first, F-068) must NOT defer the reply; + // its outcome is published on its own topic (status/playback, control/reports). result.reqId = envelope.reqId; envelope.reply(result); }