diff --git a/CHANGELOG.md b/CHANGELOG.md index 6945941..5ec6c47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,18 @@ is only released once its **exit criterion** is met, not when its code lands. Until v1.0.0 the minor version is the breaking one: configuration formats and Go APIs change between minors without a deprecation period. +## Unreleased + +### The mirror page is one line per model + +What the mirror holds used to take two table rows per file — seven columns and +the address under them — so a sharded model filled the screen. Now each version +is one line: model and version, the file (or "4 files" for a set), total size, +and which catalog models use it. The address moved into a "copy address" button; +the checksum is in the file's tooltip. A version already in use is not offered +for serving again, and removing one warns that the catalog uses it. The header +counts versions rather than files. + ## v0.9.0 — 2026-09-28 ### Managing people and the tenancy tree diff --git a/internal/control/modelsvc/modelsvc.go b/internal/control/modelsvc/modelsvc.go index 37b9a1b..b3c94dc 100644 --- a/internal/control/modelsvc/modelsvc.go +++ b/internal/control/modelsvc/modelsvc.go @@ -70,6 +70,22 @@ func (s *Service) Declared(name string) bool { return false } +// Sources maps each weights source in the catalog to the models that name it, +// so a page listing files can say which of them are in use. +func (s *Service) Sources(ctx context.Context) (map[string][]string, error) { + c, err := s.Load(ctx) + if err != nil { + return nil, err + } + out := map[string][]string{} + for _, m := range c.Models() { + if m.Source != "" { + out[m.Source] = append(out[m.Source], m.Name) + } + } + return out, nil +} + // Add puts a model in the catalog and keeps it across restarts. // // Validated by building the whole catalog before anything is written. A model diff --git a/internal/web/admin_mirror.go b/internal/web/admin_mirror.go index e72f51f..6467a11 100644 --- a/internal/web/admin_mirror.go +++ b/internal/web/admin_mirror.go @@ -70,6 +70,14 @@ type mirrorRow struct { // then not drawn at all: a progress bar that has to invent its own total is // worse than a byte count that only goes up. HasPercent bool + + // Files is how many files a held version has. A version of several is one + // row — a fifteen-shard model is one thing to serve or remove, and fifteen + // rows of it pushed everything else off the page. + Files int + // UsedBy names the catalog models whose source is this row's address, so + // a file that is in use does not look like one waiting to be served. + UsedBy []string } type adminMirrorData struct { @@ -276,25 +284,46 @@ func (p *AccountPages) renderMirror(w http.ResponseWriter, r *http.Request, } d.Base = got.Base + var sources map[string][]string + if p.catalog != nil { + if sources, err = p.catalog.Sources(r.Context()); err != nil { + p.log.Warn("could not read which models use the mirror", "err", err) + } + } + held := map[string]int{} // model/version -> index of its row for _, st := range got.Models { - row := mirrorRow{ - Status: st, - URL: mirror.Entry{Model: st.Model, Version: st.Version, File: st.File}. - URL(got.Base), - } - if pc, ok := st.Percent(); ok { - row.Percent, row.HasPercent = pc, true - } switch st.State { case mirror.Fetching: d.Fetching++ case mirror.Failed: d.Failed++ default: - d.Present++ + key := st.Model + "/" + st.Version + if i, ok := held[key]; ok { + // Another file of a version already shown: counted into it. + d.Rows[i].Files++ + d.Rows[i].BytesDone += st.BytesDone + d.Rows[i].URL = strings.TrimSuffix( + mirror.Entry{Model: st.Model, Version: st.Version}.URL(got.Base), "/") + "/" + continue + } + held[key] = len(d.Rows) + d.Present++ // versions, not files: what the rows below count + } + row := mirrorRow{ + Status: st, + Files: 1, + URL: mirror.Entry{Model: st.Model, Version: st.Version, File: st.File}. + URL(got.Base), + } + if pc, ok := st.Percent(); ok { + row.Percent, row.HasPercent = pc, true } d.Rows = append(d.Rows, row) } + for i := range d.Rows { + d.Rows[i].UsedBy = sources[d.Rows[i].URL] + } // The one row whose serve form is open, and only when the catalog can be // changed at all. diff --git a/internal/web/admin_mirror_test.go b/internal/web/admin_mirror_test.go index 664e608..c5dc6ad 100644 --- a/internal/web/admin_mirror_test.go +++ b/internal/web/admin_mirror_test.go @@ -331,7 +331,7 @@ func TestAFailedRowOffersRetryRatherThanRemove(t *testing.T) { if strings.Contains(body, "/admin/mirror/m/v/remove") { t.Error("a failed row should not offer a remove that can only 404") } - if !strings.Contains(body, "Retry") { + if !strings.Contains(body, ">retry<") { t.Error("a failed row should offer to start the download again") } if !strings.Contains(body, `value="http://upstream/model.gguf"`) { @@ -535,3 +535,35 @@ func TestAlternativeQuantisationsStaySeparateRows(t *testing.T) { t.Errorf("expected a form each plus the manual one, found %d", n) } } + +func TestAHeldVersionIsOneLineAndSaysWhoUsesIt(t *testing.T) { + m := &fakeMirror{models: []mirror.Status{ + {Model: "big", Version: "v1", File: "a-00001-of-00002.gguf", State: mirror.Present, BytesDone: 1 << 30}, + {Model: "big", Version: "v1", File: "a-00002-of-00002.gguf", State: mirror.Present, BytesDone: 1 << 30}, + {Model: "small", Version: "v1", File: "s.gguf", State: mirror.Present, BytesDone: 1 << 20}, + }} + cat := &fakeCatalog{sources: map[string][]string{"http://mirror:8081/small/v1/s.gguf": {"small-chat"}}} + body := mirrorGet(t, mirrorPageDeps(t, MirrorDeps{Mirror: m, Catalog: cat}, true), + "/admin/mirror").Body.String() + + if n := strings.Count(body, "/admin/mirror/big/v1/remove"); n != 1 { + t.Errorf("a two-file version should be one row, found %d", n) + } + if !strings.Contains(body, "2 files") || !strings.Contains(body, "2.0 GiB") { + t.Error("the row should count its files and add up their size") + } + if !strings.Contains(body, `data-url="http://mirror:8081/big/v1/"`) { + t.Error("a set's address is its directory, trailing slash included") + } + if !strings.Contains(body, ">small-chat<") { + t.Error("the model serving a file should be named on its row") + } + // Already served: offering to serve it again invites a second catalog + // entry for the same weights. + if strings.Contains(body, "serve=small:v1") { + t.Error("a file in use should not be offered for serving") + } + if !strings.Contains(body, "serve=big:v1") { + t.Error("a file nobody uses should be offered for serving") + } +} diff --git a/internal/web/admin_serve.go b/internal/web/admin_serve.go index 0a91076..aadb34e 100644 --- a/internal/web/admin_serve.go +++ b/internal/web/admin_serve.go @@ -15,6 +15,8 @@ import ( type CatalogAdmin interface { Add(ctx context.Context, m catalog.Model, by string) error Declared(name string) bool + // Sources maps a weights source to the catalog models that use it. + Sources(ctx context.Context) (map[string][]string, error) } // serveForm is the offer to put one mirrored version into service. diff --git a/internal/web/admin_serve_test.go b/internal/web/admin_serve_test.go index 7758b97..2c12501 100644 --- a/internal/web/admin_serve_test.go +++ b/internal/web/admin_serve_test.go @@ -17,6 +17,7 @@ import ( type fakeCatalog struct { added []catalog.Model declared string + sources map[string][]string err error } @@ -28,6 +29,9 @@ func (f *fakeCatalog) Add(_ context.Context, m catalog.Model, _ string) error { return nil } func (f *fakeCatalog) Declared(name string) bool { return name == f.declared } +func (f *fakeCatalog) Sources(context.Context) (map[string][]string, error) { + return f.sources, nil +} // fleet reports a cluster with a given number of cards and engines. type fakeFleet struct { diff --git a/internal/web/static/base.css b/internal/web/static/base.css index 9ed6deb..b6aa2cd 100644 --- a/internal/web/static/base.css +++ b/internal/web/static/base.css @@ -357,3 +357,8 @@ input.search { width: 100%; max-width: 26rem; margin: 0 0 .7rem; padding: .45rem font: inherit; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--fg); } tr[hidden] { display: none; } + +/* The mirror's list of what it holds: one line per version. */ +table.held td.file { max-width: 22rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +table.held td.actions > * + * { margin-left: .7rem; } +table.held .tag { margin: 0 .3rem 0 0; text-transform: none; letter-spacing: 0; } diff --git a/internal/web/templates/admin_mirror.html b/internal/web/templates/admin_mirror.html index f6cac44..4d90d9d 100644 --- a/internal/web/templates/admin_mirror.html +++ b/internal/web/templates/admin_mirror.html @@ -12,7 +12,7 @@ {{if .Unreachable}}{{.Addr}} did not answer{{else}}{{.Present}} held · {{.Fetching}} downloading · {{.Failed}} failed · {{.Addr}}{{end}}
-