Skip to content

Support runtime add/remove of robots for fleet autodiscovery#79

Merged
b-Tomas merged 11 commits into
mainfrom
feat/runtime-fleet-add-remove
Jun 5, 2026
Merged

Support runtime add/remove of robots for fleet autodiscovery#79
b-Tomas merged 11 commits into
mainfrom
feat/runtime-fleet-add-remove

Conversation

@b-Tomas
Copy link
Copy Markdown
Member

@b-Tomas b-Tomas commented Jun 4, 2026

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 after start()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.
  • Adds add_robot(RobotConfig) / remove_robot(robot_id) as convenience wrappers over update_fleet().
  • The fleet may shrink to zero robots at runtime; the loop idles safely.
  • Single-robot Connector blocks these methods (NotImplementedError) since it's bound to one robot.
  • Docs and the fleet-connector example updated to show the autodiscovery pattern.
  • This change is backwards compatible, even with connectors using update_fleet() at startup (for auto-discovery at startup, which was already supported).

b-Tomas and others added 3 commits June 3, 2026 22:12
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>
@b-Tomas b-Tomas self-assigned this Jun 4, 2026
b-Tomas and others added 4 commits June 3, 2026 22:22
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>
@b-Tomas b-Tomas requested a review from leandropineda June 4, 2026 01:28
Comment thread inorbit_connector/connector.py
Comment thread inorbit_connector/connector.py Outdated
@b-Tomas b-Tomas requested a review from leandropineda June 5, 2026 12:41
@b-Tomas b-Tomas merged commit e4abac3 into main Jun 5, 2026
13 checks passed
@b-Tomas b-Tomas deleted the feat/runtime-fleet-add-remove branch June 5, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants