Skip to content

fix(hosts): unsubscribe connection topics and keep the old socket until commit #88

Closed

Description

@wstein

Two control-plane defects in apps/control_plane/lib/workharbor/host_connections.ex:

  1. The worker subscribes to PubSub topics (around line 103) and never unsubscribes. Each reconnect of a host adds a duplicate Registry entry, so :identity_changed arrives N times and triggers N sweeps. It grows over uptime.
  2. The old connection is closed as :replaced (around lines 83-86) before the new slot transaction commits (around lines 92-101). If the transaction fails or the peer check turns false, the healthy socket is dropped and no new one is admitted.

Acceptance criteria

  • Each host topic is subscribed at most once, or unsubscribed when the host has no remaining entry, with a test that reconnects repeatedly.
  • The old connection closes only after the replacement commits, with a test for a failed replacement.
  • make check is green.

Depends on #87 (same file).

Found by the independent pilot review on 2026-10-16. Builds on the pilot branch pilot/installable-pilot-pr (split from #83); start from its current head.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions