Skip to content

wire hive_discover: route prompts to workers discovered across the mesh #63

Description

@adiled

Discovery is half-built and unwired. hive_advertise fires on every peer hello, but hive_discover has zero production call sites — so humd can announce its bees to the mesh and then never hears about anyone else's.

Current state (verified on f968e39)

Piece State
Ensemble::hive_advertise called on peer hello — humd/src/lib.rs:882
Ensemble::hive_discover never called outside ensemble/tests/hives_integration.rs
manifests: RwLock<HashMap<client_id, HiveManifest>> keyed by local thrum client_id
every worker dispatch thrum.thrum_to(&client_id, ..) → local socket only
inbound client_id == "ensemble" forwards replies by sid only — humd/src/lib.rs:745
pick_overflow_peer already selects cross-machine by caps + free_slots — humd/src/lib.rs:1345

So explicit addressing works today (to: <hid> routes at humd/src/lib.rs:733, proven by sim/tests/eggs_on_the_hum.rs). What's missing is automatic discovery and selection.

Why hive_discover alone won't close this

  1. Remote manifests have nowhere to live. manifests is keyed by local thrum client_id. A remote bee has no client_id — it exists only as a Hid. Needs a parallel HashMap<Hid, HiveManifest>.
  2. Dispatch has to branch. Local hit → thrum_to(client_id). Remote hit → ensemble.route() with to: <hid>. One lookup, two transports.
  3. The receiver can't answer a request. Inbound ensemble tones only forward replies by sid (:745). Worse, a prompt arriving with client_id == "ensemble" currently falls through to local session handling at :895 as though a local bee sent it. Needs an explicit decision: reject, or resolve Hid → local worker via the hid field already in HiveManifest.
  4. Two selection mechanisms already exist — manifest-by-discovery and caps-by-pick_overflow_peer. Pick one source of truth instead of letting them drift.

Requirements

  • remote: RwLock<HashMap<Hid, HiveManifest>> fed by hive_discover, keyed by hive name
  • worker selection consults local manifests and remote, preferring local
  • dispatch branches to thrum_to or ensemble.route on locality
  • inbound remote prompt resolved to a local worker, or explicitly refused — never silently treated as local
  • staleness: a hive that dies must leave remote (reuse the lease/evict_expired machinery from ensemble: bound every send, order the opening frame, prune dead routes #62), otherwise we dispatch into a black hole forever
  • capability/free_slots preference where the manifest carries it

Acceptance

Two humds in sim: B's worker discovered over gossip by A, A prompts it without knowing B in advance, reply returns to A's session by sid. Follows the existing integration-test shape (eggs_on_the_hum.rs), runs in CI.

Local-only dispatch must be observably unchanged — no regression in the current 209-test suite.

Non-goals

DHT bootstrap for workers (Kademlia already routes peers), NAT traversal (iroh already handles it), any central registry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions