Say when a replica is running an edited profile, and check a source from the web too
CI / test (push) Successful in 1m43s
CI / test (push) Successful in 1m43s
Two defects, both of the same kind: something the CLI knew and the rest of the system did not. A profile can be edited while a replica is running against the old one. The reconciler deliberately leaves it alone — churning a replica that is serving costs more than the imperfection — but there was no way to see it, so the cluster could disagree with its own configuration indefinitely and read as healthy. Profile now carries a fingerprint, a replica records the one it was placed with, and both the API and `ctl replicas` say "stale profile" when they differ. An empty fingerprint is not stale: it means a replica adopted from an older agent, which is unknown rather than wrong. Adding a model from the admin page skipped the source check `ctl model add` has done all along, so a typo or a mirror that is down became a replica failing on a node minutes later, with an error naming the node. The check moves out of the CLI into a package both use. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
832d0a652c
commit
40f5c930c4
14 files changed
+281
-49
No files matched your search
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/hf"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/mirror"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/sourcecheck"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
|
||||
)
|
||||
|
||||
@@ -189,6 +190,15 @@ func (p *AccountPages) RegisterAdminMirror(mux *http.ServeMux, d MirrorDeps) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// The same check `llmgw ctl model add` makes. This page builds
|
||||
// the source out of a row the mirror reported, so it is right
|
||||
// far more often than something typed — but a file removed
|
||||
// between the listing and the click, or a mirror that has gone
|
||||
// down since, both end as a replica failing on a node minutes
|
||||
// later with an error naming the node. Asking costs one HEAD.
|
||||
if _, err := sourcecheck.Check(ctx, model.Source); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := d.Catalog.Add(ctx, model, admin.Email); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -60,6 +61,17 @@ func servePage(t *testing.T, models []mirror.Status, cat CatalogAdmin, gpus int,
|
||||
}, true)
|
||||
}
|
||||
|
||||
// reachableSource stands in for a mirror holding the file. The serve handler
|
||||
// checks the source before the catalog sees it, the same as the CLI does, so a
|
||||
// test that means to exercise the form has to offer something that answers.
|
||||
func reachableSource(t *testing.T) string {
|
||||
t.Helper()
|
||||
srv := httptest.NewServer(http.HandlerFunc(
|
||||
func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) }))
|
||||
t.Cleanup(srv.Close)
|
||||
return srv.URL + "/coder/v1/m.gguf"
|
||||
}
|
||||
|
||||
func TestAGGUFCanBeServedStraightFromTheList(t *testing.T) {
|
||||
cat := &fakeCatalog{}
|
||||
body := mirrorGet(t, servePage(t, []mirror.Status{
|
||||
@@ -160,9 +172,10 @@ func TestAModelDeclaredInConfigurationIsNotOfferedTwice(t *testing.T) {
|
||||
|
||||
func TestServingBuildsTheEntryFromTheForm(t *testing.T) {
|
||||
cat := &fakeCatalog{}
|
||||
source := reachableSource(t)
|
||||
mirrorPost(t, servePage(t, nil, cat, 0), "/admin/mirror/serve", url.Values{
|
||||
"csrf": {"tok"}, "name": {"coder"}, "aliases": {"c7b, coder-7b"},
|
||||
"source": {"http://mirror:8081/coder/v1/m.gguf"}, "engine": {"llamacpp"},
|
||||
"source": {source}, "engine": {"llamacpp"},
|
||||
"replicas": {"3"}, "context_length": {"4096"}, "max_output": {"1024"},
|
||||
"ctx_size": {"16384"}, "profile": {"cpu-large"},
|
||||
"min_memory_gb": {"8"}, "selector_key": {"role"}, "selector_value": {"cpu-large"},
|
||||
@@ -207,8 +220,9 @@ func TestRubbishInTheFormIsRefusedBeforeTheCatalog(t *testing.T) {
|
||||
|
||||
func TestTheCatalogsOwnRefusalReachesTheOperator(t *testing.T) {
|
||||
cat := &fakeCatalog{err: errors.New("that name collides with an alias")}
|
||||
source := reachableSource(t)
|
||||
body := mirrorPost(t, servePage(t, nil, cat, 0), "/admin/mirror/serve", url.Values{
|
||||
"csrf": {"tok"}, "name": {"coder"}, "source": {"http://x/m.gguf"},
|
||||
"csrf": {"tok"}, "name": {"coder"}, "source": {source},
|
||||
"engine": {"llamacpp"}, "replicas": {"1"}, "context_length": {"4096"},
|
||||
}).Body.String()
|
||||
|
||||
@@ -316,8 +330,9 @@ func TestAnEstimateIsNotMadeWhenTheSizeIsUnknown(t *testing.T) {
|
||||
|
||||
func TestADescriptionReachesTheCatalog(t *testing.T) {
|
||||
cat := &fakeCatalog{}
|
||||
source := reachableSource(t)
|
||||
mirrorPost(t, servePage(t, nil, cat, 0), "/admin/mirror/serve", url.Values{
|
||||
"csrf": {"tok"}, "name": {"coder"}, "source": {"http://x/m.gguf"},
|
||||
"csrf": {"tok"}, "name": {"coder"}, "source": {source},
|
||||
"engine": {"llamacpp"}, "replicas": {"1"}, "context_length": {"4096"},
|
||||
"description": {"code completion and review; 7B, fits the large node"},
|
||||
})
|
||||
@@ -334,11 +349,55 @@ func TestADescriptionReachesTheCatalog(t *testing.T) {
|
||||
|
||||
func TestAModelWithNoDescriptionIsStillAccepted(t *testing.T) {
|
||||
cat := &fakeCatalog{}
|
||||
source := reachableSource(t)
|
||||
mirrorPost(t, servePage(t, nil, cat, 0), "/admin/mirror/serve", url.Values{
|
||||
"csrf": {"tok"}, "name": {"coder"}, "source": {"http://x/m.gguf"},
|
||||
"csrf": {"tok"}, "name": {"coder"}, "source": {source},
|
||||
"engine": {"llamacpp"}, "replicas": {"1"}, "context_length": {"4096"},
|
||||
})
|
||||
if len(cat.added) != 1 || cat.added[0].Description != "" {
|
||||
t.Errorf("a description is optional: %+v", cat.added)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnUnreachableSourceIsRefusedBeforeTheCatalog(t *testing.T) {
|
||||
// A port nothing is listening on: refused at once rather than after a
|
||||
// timeout, and the same shape of failure as a mirror that is down.
|
||||
srv := httptest.NewServer(http.HandlerFunc(
|
||||
func(http.ResponseWriter, *http.Request) {}))
|
||||
dead := srv.URL
|
||||
srv.Close()
|
||||
|
||||
cat := &fakeCatalog{}
|
||||
body := mirrorPost(t, servePage(t, nil, cat, 0), "/admin/mirror/serve", url.Values{
|
||||
"csrf": {"tok"}, "name": {"coder"}, "source": {dead + "/m.gguf"},
|
||||
"engine": {"llamacpp"}, "replicas": {"1"}, "context_length": {"4096"},
|
||||
}).Body.String()
|
||||
|
||||
if len(cat.added) != 0 {
|
||||
t.Error("a model whose weights are not there should not reach the catalog")
|
||||
}
|
||||
// The address, so the operator can see which one it could not reach; the
|
||||
// page used to accept this and leave the failure to a node, minutes later.
|
||||
if !strings.Contains(body, "cannot reach") {
|
||||
t.Errorf("the reason should name the source; got %s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestASourceTheMirrorNoLongerHoldsIsRefused(t *testing.T) {
|
||||
gone := httptest.NewServer(http.HandlerFunc(
|
||||
func(w http.ResponseWriter, _ *http.Request) { http.Error(w, "gone", http.StatusNotFound) }))
|
||||
t.Cleanup(gone.Close)
|
||||
|
||||
cat := &fakeCatalog{}
|
||||
body := mirrorPost(t, servePage(t, nil, cat, 0), "/admin/mirror/serve", url.Values{
|
||||
"csrf": {"tok"}, "name": {"coder"}, "source": {gone.URL + "/m.gguf"},
|
||||
"engine": {"llamacpp"}, "replicas": {"1"}, "context_length": {"4096"},
|
||||
}).Body.String()
|
||||
|
||||
if len(cat.added) != 0 {
|
||||
t.Error("a file removed between the listing and the click should be caught")
|
||||
}
|
||||
if !strings.Contains(body, "404") {
|
||||
t.Errorf("the server's answer should be shown; got %s", body)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user