Support runtime add/remove of robots for fleet autodiscovery#79
Merged
Conversation
Make `FleetConnector.update_fleet()` the single, idempotent reconciler of the live robot fleet, and add `add_robot()`/`remove_robot()` as thin convenience wrappers over it. This lets fleet connectors add and remove robots while running, enabling robot autodiscovery (e.g. polling a fleet manager and reacting to robots joining/leaving). Previously the fleet was static after `start()`: `update_fleet()` only swapped the cached config and `__robot_ids`, with sessions bulk-created once at connect time and never reconciled afterwards. Changes: - `update_fleet(fleet)` now reconciles the live sessions to exactly the given list: creates+connects sessions for added robots (registering cameras, command handler and online-status callback) and disconnects + frees sessions for removed robots, clearing their per-robot state. The whole reconcile runs under a re-entrant fleet lock so a fleet change is atomic w.r.t. concurrent callers. - `add_robot()`/`remove_robot()` read the current fleet and delegate to `update_fleet()` under the same lock. - Reconcile logic lives in a private `__apply_fleet()`; `update_fleet()` wraps it and `__connect()` calls it directly to create the initial sessions (replacing `__initialize_sessions()`). - Camera registration moved from `__run_connector` into `__initialize_session` so runtime-added robots get their cameras too. - `__disconnect()` disconnects under the lock and clears the session dict (so a later `start()` reconnects, and a concurrent add can't leak a session mid-teardown). - `__publish_pending_system_stats` reads `__robot_sessions` instead of the pool, so a removed robot is skipped rather than resurrected on a cache miss. - Single-robot `Connector` overrides the public mutation API to raise `NotImplementedError` (its startup still works via the private `__apply_fleet`). - Fleet may shrink to zero robots at runtime; the loop idles safely. Docs and the fleet-connector example updated to show autodiscovery. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Make ConnectorRootConfig.fleet optional (default []) and drop the must_contain_at_least_one_robot validator, so a connector can start knowing no robots and discover them at runtime via add_robot()/ update_fleet(). robot_ids_must_be_unique still applies (and is a no-op for an empty list). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
leandropineda
approved these changes
Jun 4, 2026
leandropineda
approved these changes
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds runtime add/remove of robots to
FleetConnector, enabling robot autodiscovery (e.g. polling a fleet manager and reacting to robots joining/leaving). Previously the fleet was static afterstart()—update_fleet()only swapped the cached config without reconciling sessions, and there was no way to change the fleet while running.update_fleet(fleet)now reconciles the live sessions to match the given list: connects added robots, disconnects + cleans up removed ones. Idempotent.add_robot(RobotConfig)/remove_robot(robot_id)as convenience wrappers overupdate_fleet().Connectorblocks these methods (NotImplementedError) since it's bound to one robot.update_fleet()at startup (for auto-discovery at startup, which was already supported).