Canary on the console's model menu; docs

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-04 20:33:59 +02:00
1 parent a1dfd4df1d
commit 889be70b8f
8 files changed
+209 -1

No files matched your search

+62
View File
@@ -680,6 +680,67 @@ func (m *consoleModel) doEntry() tea.Cmd {
return nil
}
// canaryItems try a model's newer weights on a share of its requests: start
// one, change its share, promote it, or take it out.
func (m consoleModel) canaryItems(md adminapi.ModelView) []menuItem {
path := "/api/v1/models/" + url.PathEscape(md.Name)
result := func(raw json.RawMessage) string {
var out map[string]string
_ = json.Unmarshal(raw, &out)
return out["result"] + "."
}
if cn := md.Canary; cn != nil {
return []menuItem{
{fmt.Sprintf("Canary's share (%d%%)…", cn.Percent), func(m *consoleModel) tea.Cmd {
m.openForm(&formDialog{title: "Share of " + md.Name + " for " + cn.Model,
fields: []formField{textF("percent", strconv.Itoa(cn.Percent), "0 to 100; 0 keeps it running and gives it none")},
submit: func(m *consoleModel, v []string) (tea.Cmd, error) {
n, err := strconv.Atoi(v[0])
if err != nil || n < 0 || n > 100 {
return nil, fmt.Errorf("a whole number from 0 to 100")
}
return m.call("Canary of "+md.Name, http.MethodPut, path+"/canary", map[string]int{"percent": n}, result), nil
}})
return nil
}},
{"Promote the canary…", func(m *consoleModel) tea.Cmd {
m.confirmD = &confirmDialog{title: "Promote " + cn.Model,
text: md.Name + " moves to the canary's weights: its replicas are replaced one at a time,\n" +
"and the canary is removed. Going back is \"Go back to\" on this menu.",
yes: func(m *consoleModel) tea.Cmd {
return m.call("Promote "+cn.Model, http.MethodPost, path+"/promote", map[string]string{}, startedSays)
}}
return nil
}},
{"Take the canary out…", func(m *consoleModel) tea.Cmd {
m.confirmD = &confirmDialog{title: "Take " + cn.Model + " out",
text: md.Name + " serves all of its requests again, and the canary is removed.",
yes: func(m *consoleModel) tea.Cmd {
return m.call("Canary of "+md.Name, http.MethodDelete, path+"/canary", nil, result)
}}
return nil
}},
}
}
if u := md.Update; u == nil || !u.Available || md.CanaryOf != "" {
return nil
}
return []menuItem{{"Try the new weights as a canary…", func(m *consoleModel) tea.Cmd {
m.openForm(&formDialog{title: "Canary of " + md.Name,
note: "The new weights run beside it, one replica, given this share of its requests.\n" +
"Taken out by itself if it errs or answers more slowly than " + md.Name + ".",
fields: []formField{textF("percent", "10", "share of its requests, 0 to 100")},
submit: func(m *consoleModel, v []string) (tea.Cmd, error) {
n, err := strconv.Atoi(v[0])
if err != nil || n < 0 || n > 100 {
return nil, fmt.Errorf("a whole number from 0 to 100")
}
return m.call("Canary of "+md.Name, http.MethodPost, path+"/canary", catalog.Canary{Percent: n}, startedSays), nil
}})
return nil
}}}
}
// updateItems are what can be done about a model's repository publishing new
// weights: move to them, ask now, or go back.
func (m consoleModel) updateItems(md adminapi.ModelView) []menuItem {
@@ -728,6 +789,7 @@ func (m consoleModel) updateItems(md adminapi.ModelView) []menuItem {
return nil
}})
}
items = append(items, m.canaryItems(md)...)
items = append(items, menuItem{"Ask the registry for new weights now", func(m *consoleModel) tea.Cmd {
return m.call("New weights for "+md.Name, http.MethodPost, "/api/v1/updates/check", map[string]string{"model": md.Name},
func(raw json.RawMessage) string {
+27
View File
@@ -17,6 +17,7 @@ import (
"gitea.mynodes.xyz/ilker/llmgw/internal/config"
"gitea.mynodes.xyz/ilker/llmgw/internal/control/adminapi"
"gitea.mynodes.xyz/ilker/llmgw/internal/control/catalog"
"gitea.mynodes.xyz/ilker/llmgw/internal/control/modelserve"
"gitea.mynodes.xyz/ilker/llmgw/internal/guard"
"gitea.mynodes.xyz/ilker/llmgw/internal/modelplan"
@@ -669,3 +670,29 @@ func TestTheAuditViewListsChangesAndOpensOne(t *testing.T) {
t.Errorf("not opened:\n%s", v)
}
}
func TestAModelsMenuOffersACanaryAndThenRunsIt(t *testing.T) {
m, _ := consoleWith(t, cModels)
labels := func(md adminapi.ModelView) []string {
var out []string
for _, it := range m.canaryItems(md) {
out = append(out, it.label)
}
return out
}
md := adminapi.ModelView{Name: "qwen", Update: &modelserve.UpdateInfo{Available: true, Latest: "def98765"}}
if got := labels(md); len(got) != 1 || !strings.Contains(got[0], "canary") {
t.Errorf("with new weights: %v", got)
}
md.Canary = &catalog.Canary{Model: "qwen-canary", Percent: 10}
got := strings.Join(labels(md), " | ")
for _, want := range []string{"share (10%)", "Promote", "Take the canary out"} {
if !strings.Contains(got, want) {
t.Errorf("with a canary, %q lacks %q", got, want)
}
}
if got := labels(adminapi.ModelView{Name: "qwen-canary", CanaryOf: "qwen",
Update: &modelserve.UpdateInfo{Available: true}}); len(got) != 0 {
t.Errorf("a canary offered a canary of its own: %v", got)
}
}