tractor/ai/prompt-io/claude/20260414T163300Z_befedc49_p...

1.8 KiB
Raw Blame History

tractor/discovery/_api.py

git diff befedc49~1..befedc49 -- tractor/discovery/_api.py

Add _is_local_addr() and prefer_addr() transport preference helpers.

_is_local_addr(addr: Address) -> bool

Determines whether an Address is reachable on the local host:

  • UDSAddress: always returns True (filesystem-bound, inherently local)
  • TCPAddress: checks if ._host is a loopback IP via ipaddress.ip_address().is_loopback, then falls back to comparing against the machines own interface IPs via socket.getaddrinfo(socket.gethostname(), None)

prefer_addr(addrs: list[UnwrappedAddress]) -> UnwrappedAddress

Selects the “best” transport address from a multihomed actors address list. Wraps each candidate via wrap_address() to get typed Address objects, then classifies into three tiers:

  1. UDS (same-host guaranteed, lowest overhead)
  2. TCP loopback / same-host IP (local network)
  3. TCP remote (only option for distributed)

Within each tier, the last-registered (latest) entry is preferred. Falls back to addrs[-1] if no heuristic matches.

tractor/discovery/_registry.py

git diff befedc49~1..befedc49 -- tractor/discovery/_registry.py

Registrar.find_actor() return type broadened from single addr to list[UnwrappedAddress]|None — full addr list lets callers apply transport preference.

Integration

query_actor() and wait_for_actor() now call prefer_addr(addrs) instead of addrs[-1].

Verification

All discovery tests pass (13/13 non-daemon). test_local.py and test_multi_program.py also pass (daemon fixture teardown failures are pre-existing and unrelated).