#16193·thingsboard

Server-side RPC never reaches a device assigned to an Edge while it is connected to the server directly: DeviceActorMessageProcessor routes by edge assignment, not by session

Author: luka-medicCreated Sep 24, 2026Updated Sep 25, 2026

Describe the bug

A device that is assigned to an Edge but is currently connected directly to the server (its own MQTT session on the cloud, for example because it cannot reach its Edge and falls back to the server) never receives server-side RPC. Every RPC is written to the Edge's event queue, which cannot reach the device at that moment. If the Edge is inactive, the RPC is dropped with an error log instead. The device's RPC subscription on the server is ignored, even though the device actor is holding it.

Uplink keeps working over the direct session, and shared-attribute notifications are not affected either (processAttributesUpdate sends to attributeSubscriptions with no edge check). Only RPC is silently lost, so it is easy to miss. Commands such as reboot, firmware-update approval or credential rotation never reach a device that is on its fallback path, which is exactly when an operator most often needs them.

Cause (application/src/main/java/org/thingsboard/server/actors/device/DeviceActorMessageProcessor.java, processRpcRequest. Identical on v4.3.1.5, lts-4.3, release-4.4 and master):

java
if (systemContext.isEdgesEnabled() && edgeId != null) {
    // device is related to an edge -> save RPC to the edge queue
    if (edgeService.isEdgeActiveAsync(...).get()) {
        saveRpcRequestToEdgeQueue(request, requestId);
    } else {
        log.error("... The Edge is currently offline or unreachable", ...);
    }
} else if (isSendNewRpcAvailable()) {
    sent = !rpcSubscriptions.isEmpty();
    rpcSubscriptions.forEach((sessionId, sessionInfo) -> sendToTransport(rpcRequest, sessionId, sessionInfo.getNodeId()));
    ...
}

The decision uses only the edge-assignment relation (edgeId), never whether the device has a transport session on this server. An Edge-connected device has no such session: its uplink arrives over the Edge gRPC stream, and its RPC responses come back as FromDeviceRpcResponseActorMsg through DeviceEdgeProcessor. So rpcSubscriptions is non-empty only when the device really is connected to the server itself.

To Reproduce

  1. Create an Edge and assign a device to it.
  2. Connect the device directly to the server over MQTT (not to the Edge) and subscribe to v1/devices/me/rpc/request/+.
  3. Send a two-way or one-way RPC to the device from the server (REST /api/rpc/twoway/{deviceId} or the rule engine).
  4. Nothing reaches the device. With the Edge connected, the RPC appears in the Edge's event queue. With the Edge offline, the server logs Failed to save RPC request to edge queue ... The Edge is currently offline or unreachable. The two-way call times out.
  5. Unassign the device from the Edge, repeat step 3: it is delivered at once.

Expected behavior If the device holds an RPC-subscribed session on the server, the server delivers the RPC over that session, as it does for any other device. The Edge queue is used when it does not.

Proposed fix (one condition, no new state):

java
if (systemContext.isEdgesEnabled() && edgeId != null && rpcSubscriptions.isEmpty()) {

Otherwise it falls through to the existing session branch, so persistent and lightweight RPC, status bookkeeping, expiry, actors.rpc.submit_strategy and the one-way fast path behave exactly as for a device without an Edge. The edge branch is taken again as soon as the direct session is closed, unsubscribed, times out or is evicted. An RPC sent over the session is never also written to the Edge queue, so no new double-delivery path is added.

One trade-off to note: if the direct session is dead but not yet reported closed, the RPC goes to it and times out, as it would for a device without an Edge, instead of going to the Edge. That window is bounded by transport keep-alive detection (and at worst the session inactivity timeout).

We carry this as a patch on v4.3.1.5 with a focused unit test (DeviceActorEdgeRpcRoutingTest). Happy to open a PR against lts-4.3 and master.

Your Server Environment

  • own setup: monolith, deb, Community Edition
  • ThingsBoard CE v4.3.1.5 (server), ThingsBoard Edge 4.3.1.4EDGE
  • Debian 13 (aarch64)

Your Device

  • Connectivity: MQTT over TLS, to the Edge normally, directly to the server as a fallback
  • Device vendor and model: ESP32-S3 based device