Merge ha: replicated store, second control plane, join codes, setup and console screens
Release / build (push) Successful in 4m26s
Release / notes (push) Successful in 3s
CI / test (push) Successful in 5m14s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-03 22:59:49 +02:00
commit 36cdbce125
67 files changed
+8574 -490

No files matched your search

+14 -1
View File
@@ -123,6 +123,19 @@ func (r *Router) Handler() http.Handler {
w.WriteHeader(http.StatusOK)
})
// Leadership: 200 on the control plane that places work, 503 on a
// standby. What a floating address follows (llmgw server add --vip):
// unlike /ready it does not wait for a replica, so a cluster with no
// node yet still has its address on one machine. A process that is not
// a control plane, or one with no rival, is always the leader.
mux.HandleFunc("GET /leader", func(w http.ResponseWriter, _ *http.Request) {
if f := r.isLeader.Load(); f != nil && !(*f)() {
http.Error(w, "this control plane is a standby", http.StatusServiceUnavailable)
return
}
w.WriteHeader(http.StatusOK)
})
// The landing page says how to connect and nothing about what is here, so
// it is safe to serve without a key — and it has to be, because the person
// reading it is the one who does not have one yet.
@@ -227,7 +240,7 @@ func (r *Router) Handler() http.Handler {
// route must not be able to add an unauthenticated one by omission. Health
// stays open because a load balancer has no key.
return auth.Middleware(r.auth, r.log,
"/health", "/ready", "/", "/about", "/_static/", "/claim/",
"/health", "/ready", "/leader", "/", "/about", "/_static/", "/claim/",
"/signup", "/login", "/logout", "/profile", "/profile/",
"/admin", "/admin/", "/chat", "/chat/", "/org", "/org/", "/setup/")(mux)
}
+43
View File
@@ -0,0 +1,43 @@
package router
import (
"net/http"
"net/http/httptest"
"path/filepath"
"testing"
)
func TestTheLeaderEndpointFollowsLeadership(t *testing.T) {
rt := newTestRouter(t, baseConfig())
get := func() int {
rec := httptest.NewRecorder()
rt.Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/leader", nil))
return rec.Code
}
// No rival, nothing to follow: the one process leads.
if c := get(); c != http.StatusOK {
t.Errorf("with no leadership: %d", c)
}
leading := false
rt.SetLeader(func() bool { return leading })
if c := get(); c != http.StatusServiceUnavailable {
t.Errorf("a standby: %d", c)
}
leading = true
if c := get(); c != http.StatusOK {
t.Errorf("the leader: %d", c)
}
}
func TestTheLeaderEndpointNeedsNoKey(t *testing.T) {
// keepalived and load balancers ask it, and they have no key.
cfg := baseConfig()
cfg.Auth.Enabled = true
cfg.Auth.Store = filepath.Join(t.TempDir(), "store.db")
rt := newTestRouter(t, cfg)
rec := httptest.NewRecorder()
rt.Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/leader", nil))
if rec.Code != http.StatusOK {
t.Errorf("/leader without a key: %d", rec.Code)
}
}
+6 -1
View File
@@ -85,7 +85,9 @@ type Router struct {
store *storepkg.DB
// usageRetention is how long request records are kept; zero is for ever.
usageRetention time.Duration
acct *accounting.Accountant
// isLeader says whether this process leads; nil is always.
isLeader atomic.Pointer[func() bool]
acct *accounting.Accountant
// threads holds conversations and memory notes. It is store when auth is on,
// its own file when only the threads block is configured, and nil when
@@ -532,6 +534,9 @@ func (r *Router) Stop() {
}
}
// SetLeader tells /leader how to know whether this process leads.
func (r *Router) SetLeader(f func() bool) { r.isLeader.Store(&f) }
// Registry exposes the endpoint registry, for tests and admin endpoints.
func (r *Router) Registry() *endpoint.Registry { return r.reg }