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); }