docs(req_id): confirm req_id survives playback.play/stop incl. the download path

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 <noreply@anthropic.com>
This commit is contained in:
2026-09-29 20:26:32 +03:00
co-authored by Claude Opus 5.5
parent b01e755c92
commit 83b2b2547f
2 changed files with 6 additions and 0 deletions
@@ -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. - **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. - **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. - **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 ## Malformed Input
@@ -53,6 +53,10 @@ void CommandBus::dispatch(CommandEnvelope& envelope) {
LOG_DEBUG(TAG, "Dispatching: %s", envelope.command.c_str()); LOG_DEBUG(TAG, "Dispatching: %s", envelope.command.c_str());
CommandResult result = it->second->execute(envelope); 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; result.reqId = envelope.reqId;
envelope.reply(result); envelope.reply(result);
} }