Skip to content

Controller: Connect stream, worker sessions and the worker client - #2

Merged
KristiforMilchev merged 1 commit into
mainfrom
controller-connect
Nov 3, 2026
Merged

KristiforMilchev merged 1 commit into
mainfrom
controller-connect

Conversation

@KristiforMilchev

Copy link
Copy Markdown
Contributor

Second part of milestone M1: workers stay connected to the controller.

Controller

  • Connect requires the worker's client certificate, and it must be the worker's current one. The worker is identified by its certificate, never by what it sends in Hello.
  • Each connection is a session with heartbeats and a silence timeout. A registry lets the scheduler send messages to a worker. If the same worker connects again, its old session is replaced.
  • controller worker revoke <id> disconnects a worker immediately, and it can't reconnect. A worker revoked through another controller is dropped at the next periodic check, which runs every 30s.
  • controller worker list shows workers, pools and when each was last seen.

Worker kit (pkg/worker)

  • Join generates the private key locally, joins, and saves the identity to disk.
  • Client connects, sends heartbeats, delivers controller messages in order and reconnects with jittered backoff. It stops for good if the controller rejects it as revoked or unknown.

Tests: integration tests run a real controller with PostgreSQL and the real worker client over TLS. They cover:

  • connect and status reporting;
  • a controller → worker message;
  • reconnecting after a drop;
  • a silent worker being dropped;
  • revocation, both direct and through the database;
  • a hello for the wrong worker;
  • a superseded certificate;
  • a certificate from a different CA;
  • 10 workers at once.

They passed 10 times in a row under the race detector.

Next: runs, jobs and the scheduler.

🤖 Generated with Claude Code

- Connect requires the worker's current client certificate; the worker is
  identified by the certificate, never by what it says in Hello
- Sessions with heartbeats, a silence timeout, a registry the scheduler can
  send through, and replacement when the same worker reconnects
- Revocation: controller worker revoke disconnects at once; workers revoked
  elsewhere are dropped at the next periodic check
- pkg/worker: Join saves the identity to disk; Client connects, sends
  heartbeats and reconnects with jittered backoff, stopping for good when
  the controller rejects the worker permanently
- internal/controller/api: handler and TLS config shared by the binary and
  tests
- Integration tests: real controller, PostgreSQL and worker client over TLS
- controller worker list and controller worker revoke

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KristiforMilchev
KristiforMilchev merged commit 7b5e3bc into main Nov 3, 2026
1 check passed
@KristiforMilchev
KristiforMilchev deleted the controller-connect branch November 3, 2026 12:44
KristiforMilchev added a commit that referenced this pull request Nov 3, 2026
…ains #2)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant