Skip to content

Add discovery.watch() for services that need to hear the network change - #22

Merged
mullinmax merged 2 commits into
mainfrom
claude/vector-network-discovery-windows-2xeoja
Sep 5, 2026
Merged

mullinmax merged 2 commits into
mainfrom
claude/vector-network-discovery-windows-2xeoja

Conversation

@mullinmax

Copy link
Copy Markdown
Contributor

What

discover() asks the network once and returns — the right shape for a CLI, the wrong one for a long-running service. A board broadcasts HELLO about ten seconds after it boots, but a poller only finds out when its interval next comes round, so a machine that rebooted is invisible until then.

discovery.watch() keeps the socket open and yields as things happen:

for event in discovery.watch():
    if event.kind == "roster":     # a FULL frame
        print("live boards:", [(m.ip, m.name) for m in event.machines])
    elif event.kind == "joined":   # a HELLO
        print("came up:", event.machines[0].name)

Why FULL gets its own event kind

A FULL frame is the registry board's complete list of live boards, and every board on the network checks it against what it knows and corrects it if it's wrong. That makes it the closest thing this protocol has to ground truth about who is on the network right now — worth handing to callers as an authoritative roster rather than folding into a stream of individual sightings.

HELLO is the complementary signal: one specific board saying "I just came up". Together they answer both questions a service has — what's out there, and what just changed.

Notes

  • Reuses discover()'s probing (PING + OFFLINE, every interface, limited and directed broadcast) so quiet networks still answer — a lone board only announces itself every 15 s unprovoked.
  • watch() owns the discovery port while it runs. The docstring says so plainly: a concurrent discover() in the same process would be pushed to an ephemeral port by the _open_socket() fallback and go deaf to the FULL frames and unicast PONGs it's waiting for. That's a quiet failure worth warning about at the call site.
  • Closes its sockets when the caller stops iterating, not just at timeout.
  • PONGs are deliberately ignored: they carry no name, and a board that PONGs will appear in the next FULL anyway.

Testing

  • python -m pytest — 322 passed
  • ruff check . — clean
  • New tests cover roster and joined events, that a FULL frame does not end the watch (the behavioral difference from discover()), self-probe loopback filtering, garbage and PONG frames, probing, and socket cleanup on early exit.

Version 0.4.0 → 0.5.0. Consumed by the Origin change that makes the discovery relay listen continuously instead of polling.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VmtVSp58rDkDBRPzL9hJkt


Generated by Claude Code

discover() asks the network once and returns, which is the right shape for a
CLI and the wrong one for a service. A board broadcasts HELLO about ten
seconds after it boots; a poller only finds out when its interval next comes
round, so a machine that rebooted is invisible for up to that long.

watch() keeps the socket open and yields as things happen: "joined" when a
board announces itself, "roster" for a FULL frame. FULL is worth surfacing
separately because it is the registry board's complete list and every board on
the network checks it against what it knows and corrects it -- the closest
thing to ground truth about who is live.

It reuses discover()'s probing so quiet networks still answer (a lone board
only announces itself every 15 s unprovoked), and it owns the discovery port
while running, which the docstring says plainly since a concurrent discover()
would be pushed to an ephemeral port and go deaf.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VmtVSp58rDkDBRPzL9hJkt
@github-actions

github-actions Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Coverage report

✅

Total coverage: 100.00% (0.00% vs base 100.00%)

The coverage gate was right to complain: watch() had four unexercised
branches, and each is a real behaviour rather than defensive padding.

- An interface with no broadcast route makes sendto fail, and that must not
  stop the watch -- probing is best effort across every interface.
- Windows reports an earlier datagram's ICMP port-unreachable on the next
  receive. It looks like a socket error and is not one.
- A socket that genuinely dies ends the watch by returning, so the caller can
  start a fresh one, rather than raising into it.
- The per-interface probe sockets get closed alongside the listening one.

warpedpinball/discovery.py is back to 100%.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VmtVSp58rDkDBRPzL9hJkt
@mullinmax
mullinmax marked this pull request as ready for review September 5, 2026 03:13
@mullinmax
mullinmax merged commit e791064 into main Sep 5, 2026
12 checks passed
@mullinmax
mullinmax deleted the claude/vector-network-discovery-windows-2xeoja branch September 5, 2026 03:15
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