Skip to content

feat(cluster): Add peer server support with invite+accept handshake#85

Merged
nfebe merged 2 commits intomainfrom
feat/cluster-peering
Mar 18, 2026
Merged

feat(cluster): Add peer server support with invite+accept handshake#85
nfebe merged 2 commits intomainfrom
feat/cluster-peering

Conversation

@nfebe
Copy link
Contributor

@nfebe nfebe commented Mar 18, 2026

Implement hub-and-spoke cluster architecture allowing multiple Flatrun agents to cooperate as peers. Peering requires mutual agreement via a one-time invite token exchange. API keys are auto-generated and encrypted at rest using AES-GCM derived from the JWT secret.

New cluster package provides SQLite storage for peers/invites, an HTTP client for peer communication, a manager with health check goroutines, and fan-out aggregation for cross-server queries.

Adds 9 API endpoints for cluster management including invite creation, key exchange, peer listing/removal, transparent proxy, and aggregated deployments/stats. Includes 48 tests covering unit, integration, and a full two-server peering E2E flow.

@sourceant
Copy link

sourceant bot commented Mar 18, 2026

Code Review Summary

This PR introduces a hub-and-spoke clustering system. It handles peer invitation, key exchange, and health monitoring effectively. The code is well-structured and highly tested.

🚀 Key Improvements

  • Added secure peer-to-peer communication using auto-generated, encrypted API keys.
  • Implemented aggregated endpoints for deployments and stats across the cluster.
  • Provided comprehensive E2E tests for the peering handshake.

💡 Minor Suggestions

  • Explicitly enable foreign keys in SQLite.
  • Improve error logging in the API key generation path.

Copy link

@sourceant sourceant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review complete. See the overview comment for a summary.

Copy link

@sourceant sourceant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review complete. See the overview comment for a summary.

nfebe added 2 commits March 18, 2026 13:45
Implement hub-and-spoke cluster architecture allowing multiple Flatrun
agents to cooperate as peers. Peering requires mutual agreement via a
one-time invite token with 1-hour expiry.

New cluster package with SQLite storage, encrypted API key management,
health check loop, fan-out aggregation, and transparent proxy. Includes
API routes for invite/accept/exchange flow, peer management, and
cross-server deployment/stats aggregation.

Signed-off-by: nfebe <fenn25.fn@gmail.com>
Test was flaky due to non-deterministic map iteration order when
extracting bind mounts from Docker service configs.

Signed-off-by: nfebe <fenn25.fn@gmail.com>
@nfebe nfebe force-pushed the feat/cluster-peering branch from 5de99bf to 4a6f83a Compare March 18, 2026 12:45
Copy link

@sourceant sourceant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review complete. See the overview comment for a summary.

@nfebe nfebe merged commit cc79789 into main Mar 18, 2026
5 checks passed
@nfebe nfebe deleted the feat/cluster-peering branch March 18, 2026 12:53
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