You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
authored
Stop publishing system stats for offline robots (#91)
* Stop publishing system stats for offline robots
The framework publishes system stats for every robot on every execution
loop iteration, including robots the connector reports as offline. InOrbit
answers those stats with a get_state request, the online status callback
replies "offline", and the retained status message refreshes the robot's
offline timestamp -- so an offline robot's offline_ts keeps moving forward
for as long as the connector runs.
Gate the publish on _is_fleet_robot_online(robot_id) inside
__publish_pending_system_stats, where the stored-stats and default-values
paths converge, so stats explicitly stored via publish_robot_system_stats()
are dropped too rather than only the framework defaults. Nothing is lost by
skipping: the forced state request only helps when the robot is online but
InOrbit believes otherwise.
The online check is subclass code and now runs once per robot per loop
iteration instead of only on get_state, so it falls back to publishing if it
raises (matching the edge-sdk's own get_state fallback) and the docstrings
now require it to be cheap and non-blocking.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Update inorbit_connector/connector.py
Co-authored-by: Leandro <leandropineda.lp@gmail.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Leandro <leandropineda.lp@gmail.com>
Stores system stats (CPU, RAM, disk usage) to be published at the end of the execution loop. If no stats are stored for a robot during the loop iteration, default values are published automatically.
126
+
Stores system stats (CPU, RAM, disk usage) to be published at the end of the execution loop. If no stats are stored for a robot during the loop iteration, default values are published automatically. Nothing is published for a robot whose online check reports it offline (see below).
127
127
128
128
All percentage values should be floats between 0.0 and 1.0 (e.g., 0.45 for 45%).
129
129
130
-
This ensures that system stats are always published for all robots in the fleet, even if the connector does not explicitly provide values. This is to ensure stability of the online status of the robot in the UI, as it forces state requests if the robot was to appear offline.
130
+
This ensures that system stats are published for every online robot in the fleet, even if the connector does not explicitly provide values. This is to ensure stability of the online status of the robot in the UI, as it forces state requests if the robot was to appear offline.
131
+
132
+
Robots reported offline by `_is_robot_online()` (single-robot) / `_is_fleet_robot_online(robot_id)` (fleet) are skipped, as otherwise their state would be interpreted as online.
131
133
132
134
By default, zeroed values are used. To use the connector host's actual system stats as defaults, set `publish_connector_system_stats=True` when initializing the connector. See [FleetConnector constructor](specification/connector#spec-connector-fleetconnector-constructor) for details.
Copy file name to clipboardExpand all lines: docs/contents/specification/connector.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,6 +97,8 @@ Return `None` if the map can’t be fetched.
97
97
98
98
The Edge SDK uses this callback to determine if a robot should be considered online. It is invoked when InOrbit sends a `get_state` request, which happens automatically when the robot is marked as offline but system stats are still being received. Default implementation returns `True`.
99
99
100
+
The framework also calls it once per robot on every execution loop iteration, to decide whether to publish system stats at all: while it returns `False`, no system stats are published for that robot, keeping the robot offline in InOrbit. Keep the implementation cheap and non-blocking (read cached state; no network or other blocking I/O), or the connector's event loop will stall. If it raises, the framework logs a warning and publishes anyway.
@@ -148,6 +150,8 @@ Publishes pose for one robot. If the `frame_id` differs from the last published
148
150
149
151
If no stats are stored for a robot during the loop iteration, default values are published automatically. By default, zeroed values are used. To use the connector host's actual system stats as defaults, set `publish_connector_system_stats=True` in the [constructor](#spec-connector-fleetconnector-constructor).
150
152
153
+
Stats stored for a robot whose [`_is_fleet_robot_online()`](#spec-connector-fleetconnector-is-online) returns `False` are dropped rather than published.
154
+
151
155
If immediate publishing is required, use `_get_robot_session(robot_id)` to access the underlying `RobotSession` and call `publish_system_stats()` directly.
@@ -189,7 +193,7 @@ Single-robot convenience for map fetching. The framework uses it by delegating `
189
193
190
194
**Optional override.**
191
195
192
-
Single-robot convenience for online status. The fleet-level online check delegates to this method. Called when InOrbit requests state due to a discrepancy between the robot's offline status and incoming system stats.
196
+
Single-robot convenience for online status. The fleet-level online check delegates to this method. Called when InOrbit requests state due to a discrepancy between the robot's offline status and incoming system stats, and once per execution loop iteration to decide whether to publish system stats at all. See [`_is_fleet_robot_online()`](#spec-connector-fleetconnector-is-online) for the constraints that puts on the implementation.
193
197
194
198
<aid="spec-connector-connector-publishing"></a>
195
199
### Publishing wrappers
@@ -207,5 +211,3 @@ Single-robot convenience for online status. The fleet-level online check delegat
207
211
**Callable (advanced).**
208
212
209
213
Returns the underlying Edge SDK session for the current robot.
Copy file name to clipboardExpand all lines: docs/contents/usage/fleet.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -111,7 +111,7 @@ All publishing methods require a `robot_id` parameter. See the [Publishing Guide
111
111
-`publish_robot_pose(robot_id, x, y, yaw, frame_id)`: Publish pose for a specific robot
112
112
-`publish_robot_odometry(robot_id, **kwargs)`: Publish odometry for a specific robot
113
113
-`publish_robot_key_values(robot_id, **kwargs)`: Publish key-values for a specific robot
114
-
-`publish_robot_system_stats(robot_id, **kwargs)`: Defer publishing of system stats for a specific robot; defaults are published if not called
114
+
-`publish_robot_system_stats(robot_id, **kwargs)`: Defer publishing of system stats for a specific robot; defaults are published if not called, and nothing is published while the robot is offline
115
115
-`publish_robot_map(robot_id, frame_id, is_update=False)`: Publish map for a specific robot
This callback is invoked when InOrbit sends a `get_state` request, which happens automatically when the robot is marked as offline but system stats are still being received. The connector framework always publishes system stats for all robots (even zeroed defaults), ensuring that any online/offline discrepancy is detected and corrected.
181
+
This callback is invoked when InOrbit sends a `get_state` request, which happens automatically when the robot is marked as offline but system stats are still being received. The connector framework publishes system stats for every online robot, ensuring that any online/offline discrepancy is detected and corrected.
182
+
183
+
It is also called once per robot on every execution loop iteration, to decide whether to publish system stats at all. While it returns `False`, no system stats are published for that robot, keeping the robot offline in InOrbit. Keep it cheap and non-blocking (read cached state; no API call in the hot path), or the connector's event loop will stall.
Override this method to provide custom robot health checks. The default implementation assumes the robot is online if the connector is running. This callback is invoked when InOrbit sends a `get_state` request, which happens automatically when the robot is marked as offline but system stats are still being received.
182
182
183
+
It is also called on every execution loop iteration, to decide whether to publish system stats at all. While it returns `False`, no system stats are published, keeping the robot offline in InOrbit. Keep it cheap and non-blocking (read cached state; no API call in the hot path), or the connector's event loop will stall.
184
+
183
185
```python
184
186
def _is_robot_online(self) ->bool:
185
187
"""Check if the robot is online.
@@ -216,4 +218,3 @@ Scripts are automatically registered and can be executed from InOrbit.
0 commit comments