The control plane uses whichever mirror answers

mirror.peers names the mirrors kept in step with mirror.api. The
mirror's management calls go to the first that can be reached, and
each mirror is asked every fifteen seconds whether it answers: a shard
is sent its model's and adapters' address on one that does while the
mirror the catalog names is down.

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-29 13:43:27 +01:00
1 parent 5bc71b3d0a
commit 8a76a53afb
11 files changed
+276 -21

No files matched your search

+25
View File
@@ -5,6 +5,8 @@ import (
"fmt"
"maps"
"runtime"
"slices"
"sync/atomic"
"time"
llmgwv1 "gitea.mynodes.xyz/ilker/llmgw/api/gen/llmgw/v1"
@@ -189,8 +191,31 @@ func AdoptedFromRegister(nodeID string, shards []*llmgwv1.RunningShard) []reconc
}
// StartShardFromCommand converts a reconciler command into a wire message.
// sourceRewrite is where a model is fetched while its mirror is down: set
// when mirrors are kept in step, else nil and the catalog's address as it is.
var sourceRewrite atomic.Pointer[func(string) string]
// SetSourceRewrite has every shard started from now on fetch its model, and
// adapters, from the address f gives: one on a mirror that answers.
func SetSourceRewrite(f func(string) string) { sourceRewrite.Store(&f) }
func rewriteSource(src string) string {
if f := sourceRewrite.Load(); f != nil && src != "" {
return (*f)(src)
}
return src
}
func StartShardFromCommand(cmd reconciler.ShardCommand) *llmgwv1.StartShard {
p := cmd.Spec.Profile
p.ModelPath = rewriteSource(p.ModelPath)
if len(p.Adapters) > 0 {
ads := slices.Clone(p.Adapters)
for i := range ads {
ads[i].Path = rewriteSource(ads[i].Path)
}
p.Adapters = ads
}
return &llmgwv1.StartShard{
ReplicaId: cmd.ReplicaID,
ShardId: cmd.ShardID,
+18
View File
@@ -1,6 +1,7 @@
package agentsvc
import (
"strings"
"testing"
"gitea.mynodes.xyz/ilker/llmgw/internal/agent/engines"
@@ -18,3 +19,20 @@ func TestAdaptersTravelToTheAgentInOrder(t *testing.T) {
t.Errorf("adapters %+v", got)
}
}
// While its mirror is down, a shard is sent its model and adapters on the
// mirror the rewrite names, and the command it was made from is left as it is.
func TestAShardIsSentItsModelOnAMirrorThatAnswers(t *testing.T) {
SetSourceRewrite(func(s string) string { return strings.Replace(s, "http://mirror-a", "http://mirror-b", 1) })
t.Cleanup(func() { SetSourceRewrite(func(s string) string { return s }) })
ads := []engines.Adapter{{Name: "sql", Path: "http://mirror-a/sql.gguf"}}
cmd := reconciler.ShardCommand{ReplicaID: "r", ShardID: "s", Spec: engines.ShardSpec{
Profile: engines.Profile{Name: "cpu", Engine: "llamacpp", ModelPath: "http://mirror-a/qwen/v1/", Adapters: ads}}}
spec, _ := ShardSpecFromStart(StartShardFromCommand(cmd))
if spec.Profile.ModelPath != "http://mirror-b/qwen/v1/" || spec.Profile.Adapters[0].Path != "http://mirror-b/sql.gguf" {
t.Errorf("sent %+v", spec.Profile)
}
if ads[0].Path != "http://mirror-a/sql.gguf" {
t.Error("the catalog's adapter was changed in place")
}
}