Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(hermes): validate efforts confirmed by partial discovery (#10991)
Danila Katalshov2f02b5005241
diff --git a/server/internal/daemon/daemon.go b/server/internal/daemon/daemon.goindex 93d78d5fac..6a592104ac 100644--- a/server/internal/daemon/daemon.go+++ b/server/internal/daemon/daemon.go@@ -5016,7 +5016,8 @@ func (d *Daemon) handleModelList(ctx context.Context, rt Runtime, requestID stri// Additive field: the models are still worth rendering, but the server// must not persist them as this runtime's real catalog (MUL-5549).// Older servers ignore it and keep the previous behaviour.- "fallback": catalog.Fallback,+ "fallback": catalog.Fallback,+ "effort_discovery_incomplete": catalog.EffortDiscoveryIncomplete,})}diff --git a/server/internal/handler/agent.go b/server/internal/handler/agent.goindex da0850cb76..eae9f8f900 100644--- a/server/internal/handler/agent.go+++ b/server/internal/handler/agent.go@@ -1596,7 +1596,7 @@ func (h *Handler) CreateAgent(w http.ResponseWriter, r *http.Request) {// — this runtime's own discovered catalog is. Keeps a Hermes Agent user's// clear 400 instead of accepting a level the daemon would later drop.if req.ThinkingLevel != "" {- switch h.acpThinkingDecision(r.Context(), runtime.Provider, runtime.ID) {+ switch h.acpThinkingDecision(r.Context(), runtime.Provider, runtime.ID, req.Model, req.ThinkingLevel) {case acpEffortAbsent:writeError(w, http.StatusBadRequest, thinkingCapabilityRejection(runtime.Provider))return@@ -2321,7 +2321,7 @@ func (h *Handler) UpdateAgent(w http.ResponseWriter, r *http.Request) {writeError(w, http.StatusBadRequest, thinkingLevelRejection(provider, value))return}- switch h.acpThinkingDecision(r.Context(), provider, targetRuntimeID) {+ switch h.acpThinkingDecision(r.Context(), provider, targetRuntimeID, effectiveModelValue(params, existing), value) {case acpEffortAbsent:writeError(w, http.StatusBadRequest, thinkingCapabilityRejection(provider))return@@ -2352,7 +2352,7 @@ func (h *Handler) UpdateAgent(w http.ResponseWriter, r *http.Request) {writeError(w, http.StatusBadRequest, existingThinkingLevelRejection(provider, existing.ThinkingLevel.String))return}- switch h.acpThinkingDecision(r.Context(), provider, targetRuntimeID) {+ switch h.acpThinkingDecision(r.Context(), provider, targetRuntimeID, effectiveModelValue(params, existing), existing.ThinkingLevel.String) {case acpEffortAbsent:writeError(w, http.StatusBadRequest, existingThinkingCapabilityRejection(provider, existing.ThinkingLevel.String))return@@ -2831,11 +2831,31 @@ var ambiguousACPEffortProviders = map[string]bool{// turns an undiscovered catalog into a refusal, because for those the name// genuinely does not answer the question and guessing "yes" is what let a Hermes// Agent user persist a level the daemon would later drop.-func (h *Handler) acpThinkingDecision(ctx context.Context, provider string, runtimeID pgtype.UUID) acpEffortEvidence {+func partialEffortCatalogKey(runtimeID string) string {+ return "partial-effort:" + runtimeID+}++func (h *Handler) acpThinkingDecision(ctx context.Context, provider string, runtimeID pgtype.UUID, model, level string) acpEffortEvidence {if !agent.UsesACPCatalogThinking(provider) {return acpEffortPresent}- snapshot := h.cachedModelCatalog(ctx, uuidToString(runtimeID))+ snapshot, partial := h.currentModelCatalog(ctx, uuidToString(runtimeID), provider)+ if partial {+ for _, entry := range snapshot.Models {+ if model == "" && !entry.Default || model != "" && entry.ID != model {+ continue+ }+ if entry.Thinking != nil {+ for _, option := range entry.Thinking.SupportedLevels {+ if option.Value == level {+ return acpEffortPresent+ }+ }+ }+ break+ }+ return acpEffortUnknown+ }if snapshot == nil || len(snapshot.Models) == 0 {if ambiguousACPEffortProviders[provider] {return acpEffortUnknowndiff --git a/server/internal/handler/agent_thinking_test.go b/server/internal/handler/agent_thinking_test.goindex b4aa0c665a..872af033b4 100644--- a/server/internal/handler/agent_thinking_test.go+++ b/server/internal/handler/agent_thinking_test.go@@ -7,6 +7,8 @@ import ("net/http/httptest""strings""testing"++ "github.com/multica-ai/multica/server/internal/testutil")// TestCreateAgent_ThinkingLevel_ValidationConsistency exercises the@@ -772,13 +774,13 @@ func TestAcpThinkingDecision(t *testing.T) {withoutEffort := []ModelEntry{{ID: "hermes-4"}}t.Run("jcode-shaped catalog keeps the level accepted", func(t *testing.T) {- if got := withCatalog(t, withEffort).acpThinkingDecision(ctx, "hermes", runtimeID); got != acpEffortPresent {+ if got := withCatalog(t, withEffort).acpThinkingDecision(ctx, "hermes", runtimeID, "", ""); got != acpEffortPresent {t.Errorf("decision = %v, want acpEffortPresent", got)}})t.Run("Hermes-Agent-shaped catalog restores the capability answer", func(t *testing.T) {- if got := withCatalog(t, withoutEffort).acpThinkingDecision(ctx, "hermes", runtimeID); got != acpEffortAbsent {+ if got := withCatalog(t, withoutEffort).acpThinkingDecision(ctx, "hermes", runtimeID, "", ""); got != acpEffortAbsent {t.Errorf("decision = %v, want acpEffortAbsent", got)}})@@ -787,13 +789,13 @@ func TestAcpThinkingDecision(t *testing.T) {// The catalog is only written once a client asks for a model list, so this// state persists indefinitely for CLI-only callers.t.Run("no cache is unknown for hermes", func(t *testing.T) {- if got := (&Handler{}).acpThinkingDecision(ctx, "hermes", runtimeID); got != acpEffortUnknown {+ if got := (&Handler{}).acpThinkingDecision(ctx, "hermes", runtimeID, "", ""); got != acpEffortUnknown {t.Errorf("decision = %v, want acpEffortUnknown", got)}})t.Run("empty catalog is unknown for hermes", func(t *testing.T) {- if got := withCatalog(t, nil).acpThinkingDecision(ctx, "hermes", runtimeID); got != acpEffortUnknown {+ if got := withCatalog(t, nil).acpThinkingDecision(ctx, "hermes", runtimeID, "", ""); got != acpEffortUnknown {t.Errorf("decision = %v, want acpEffortUnknown", got)}})@@ -802,7 +804,7 @@ func TestAcpThinkingDecision(t *testing.T) {// an undiscovered reasonix runtime is allowed rather than blocked before its// first discovery. Tightening hermes must not tighten this.t.Run("no cache still allows reasonix", func(t *testing.T) {- if got := (&Handler{}).acpThinkingDecision(ctx, "reasonix", runtimeID); got != acpEffortPresent {+ if got := (&Handler{}).acpThinkingDecision(ctx, "reasonix", runtimeID, "", ""); got != acpEffortPresent {t.Errorf("decision = %v, want acpEffortPresent — reasonix is unambiguous", got)}})@@ -810,7 +812,7 @@ func TestAcpThinkingDecision(t *testing.T) {// Providers outside the ACP-catalog set are answered by name alone; this// check must not start second-guessing them from a catalog.t.Run("non-ACP provider is not consulted", func(t *testing.T) {- if got := withCatalog(t, withoutEffort).acpThinkingDecision(ctx, "claude", runtimeID); got != acpEffortPresent {+ if got := withCatalog(t, withoutEffort).acpThinkingDecision(ctx, "claude", runtimeID, "", ""); got != acpEffortPresent {t.Errorf("decision = %v, want acpEffortPresent — claude is decided by provider", got)}})@@ -1140,3 +1142,88 @@ func TestAgent_OmpThinkingLevelRequiresExplicitModel(t *testing.T) {}})}++func TestAgentSaveWithPartialHermesEffortCatalog(t *testing.T) {+ ctx := context.Background()+ cache := withModelListStores(t)+ runtimeID := dbfx.Runtime(t, "Hermes with partial effort discovery", testutil.Cols{"provider": "hermes"})+ if err := cache.Put(ctx, runtimeID, []ModelEntry{+ {ID: "confirmed", Thinking: &ModelThinking{SupportedLevels: []ThinkingLevel{{Value: "low"}}}},+ {ID: "previously-confirmed", Thinking: &ModelThinking{SupportedLevels: []ThinkingLevel{{Value: "high"}}}},+ {ID: "older"},+ }, nil, true); err != nil {+ t.Fatal(err)+ }++ modelsPath := "/api/runtimes/" + runtimeID + "/models"+ request := testutil.Decode[ModelListRequest](t, testHandler.InitiateListModels, withURLParam(+ newRequest(http.MethodPost, modelsPath+"?force=true", nil), "runtimeId", runtimeID,+ ), http.StatusOK)+ report := newOwnerDaemonRequest(http.MethodPost, "/api/daemon/runtimes/"+runtimeID+"/models/"+request.ID+"/result", map[string]any{+ "status": "completed",+ "supported": true,+ "fallback": true,+ "effort_discovery_incomplete": true,+ "models": []ModelEntry{+ {ID: "confirmed", Default: true, Thinking: &ModelThinking{+ SupportedLevels: []ThinkingLevel{{Value: "high"}, {Value: "medium"}},+ }},+ {ID: "previously-confirmed"},+ {ID: "unprobed"},+ },+ })+ testutil.Call(t, testHandler.ReportModelListResult, testutil.WithURLParams(+ report, "runtimeId", runtimeID, "requestId", request.ID,+ )).Want(http.StatusOK)++ created := httptest.NewRecorder()+ testHandler.CreateAgent(created, newRequest(http.MethodPost, "/api/agents", map[string]any{+ "name": "partial-hermes-thinking", "runtime_id": runtimeID, "visibility": "private",+ "max_concurrent_tasks": 1, "model": "confirmed", "thinking_level": "high",+ }))+ if created.Code != http.StatusCreated {+ t.Fatalf("create with advertised level: got %d: %s", created.Code, created.Body.String())+ }+ var result struct {+ ID string `json:"id"`+ }+ if err := json.NewDecoder(created.Body).Decode(&result); err != nil {+ t.Fatal(err)+ }+ t.Cleanup(func() { testPool.Exec(ctx, "DELETE FROM agent WHERE id = $1", result.ID) })++ for _, tc := range []struct {+ model, level string+ status int+ }{+ {"unprobed", "medium", http.StatusBadRequest},+ {"confirmed", "low", http.StatusBadRequest},+ {"confirmed", "medium", http.StatusOK},+ {"previously-confirmed", "high", http.StatusOK},+ } {+ w := httptest.NewRecorder()+ req := newRequest(http.MethodPatch, "/api/agents/"+result.ID, map[string]any{+ "model": tc.model, "thinking_level": tc.level,+ })+ testHandler.UpdateAgent(w, withURLParam(req, "id", result.ID))+ if w.Code != tc.status {+ t.Fatalf("%s/%s: got %d, want %d: %s", tc.model, tc.level, w.Code, tc.status, w.Body.String())+ }+ }++ refreshed := testutil.Decode[ModelListRequest](t, testHandler.GetModelListRequest, testutil.WithURLParams(+ newRequest(http.MethodGet, modelsPath+"/"+request.ID, nil), "runtimeId", runtimeID, "requestId", request.ID,+ ), http.StatusOK)+ cached := testutil.Decode[ModelListRequest](t, testHandler.InitiateListModels, withURLParam(+ newRequest(http.MethodPost, modelsPath, nil), "runtimeId", runtimeID,+ ), http.StatusOK)+ for _, result := range []ModelListRequest{refreshed, cached} {+ if len(result.Models) != 3 || result.Models[0].ID != "confirmed" || result.Models[1].ID != "previously-confirmed" || result.Models[2].ID != "unprobed" {+ t.Fatalf("picker must preserve the latest model list, got %+v", result.Models)+ }+ thinking := result.Models[1].Thinking+ if thinking == nil || len(thinking.SupportedLevels) != 1 || thinking.SupportedLevels[0].Value != "high" {+ t.Fatalf("picker must retain previously confirmed effort, got %+v", thinking)+ }+ }+}diff --git a/server/internal/handler/runtime_model_catalog_fallback_test.go b/server/internal/handler/runtime_model_catalog_fallback_test.goindex a62e0c3ff0..173763687d 100644--- a/server/internal/handler/runtime_model_catalog_fallback_test.go+++ b/server/internal/handler/runtime_model_catalog_fallback_test.go@@ -248,3 +248,45 @@ func TestModelCatalogCacheDecision(t *testing.T) {})}}++func TestReportModelListResult_PartialHermesReportProvidesConfirmedEffort(t *testing.T) {+ ctx := context.Background()+ cache := withModelListStores(t)+ request, err := testHandler.ModelListStore.Create(ctx, testRuntimeID)+ if err != nil {+ t.Fatal(err)+ }+ w := reportModelList(t, request.ID, map[string]any{+ "status": "completed",+ "supported": true,+ "fallback": true,+ "effort_discovery_incomplete": true,+ "models": []ModelEntry{+ {+ ID: "confirmed", Label: "Confirmed", Default: true,+ Thinking: &ModelThinking{SupportedLevels: []ThinkingLevel{{Value: "high", Label: "High"}}},+ },+ {ID: "unprobed", Label: "Unprobed"},+ },+ })+ if w.Code != http.StatusOK {+ t.Fatalf("report partial catalog: expected 200, got %d: %s", w.Code, w.Body.String())+ }+ report, err := testHandler.ModelListStore.Get(ctx, request.ID)+ if err != nil || report == nil || len(report.Models) != 2 || report.Models[0].Thinking == nil {+ t.Fatalf("the picker must receive confirmed effort metadata: report=%+v err=%v", report, err)+ }+ if got := testHandler.acpThinkingDecision(ctx, "hermes", parseUUID(testRuntimeID), "confirmed", "high"); got != acpEffortPresent {+ t.Fatalf("save validation lost confirmed effort evidence: got %v, want %v", got, acpEffortPresent)+ }+ if got := testHandler.acpThinkingDecision(ctx, "hermes", parseUUID(testRuntimeID), "unprobed", "high"); got != acpEffortUnknown {+ t.Fatalf("unprobed model got decision %v, want unknown", got)+ }+ if got := testHandler.acpThinkingDecision(ctx, "hermes", parseUUID(testRuntimeID), "confirmed", "low"); got != acpEffortUnknown {+ t.Fatalf("unadvertised level got decision %v, want unknown", got)+ }+ if snapshot, err := cache.Get(ctx, testRuntimeID); err != nil || snapshot != nil {+ t.Fatalf("partial report must not populate the complete picker cache: got %v, err %v", snapshot, err)+ }++}diff --git a/server/internal/handler/runtime_models.go b/server/internal/handler/runtime_models.goindex d0edda49a4..f7b018d550 100644--- a/server/internal/handler/runtime_models.go+++ b/server/internal/handler/runtime_models.go@@ -5,6 +5,7 @@ import ("encoding/json""log/slog""net/http"+ "slices""sync""time"@@ -353,7 +354,7 @@ func (h *Handler) InitiateListModels(w http.ResponseWriter, r *http.Request) {resolvedRuntimeID := uuidToString(rt.ID)if r.URL.Query().Get("force") != "true" {- if cached := h.cachedModelCatalog(r.Context(), resolvedRuntimeID); cached != nil {+ if cached, _ := h.currentModelCatalog(r.Context(), resolvedRuntimeID, rt.Provider); cached != nil {age := cached.Age(time.Now())if age >= modelCatalogRevalidateAfter {h.revalidateModelCatalog(r.Context(), resolvedRuntimeID)@@ -388,6 +389,36 @@ func (h *Handler) InitiateListModels(w http.ResponseWriter, r *http.Request) {writeJSON(w, http.StatusOK, req)}+func (h *Handler) currentModelCatalog(ctx context.Context, runtimeID, provider string) (*ModelCatalogSnapshot, bool) {+ complete := h.cachedModelCatalog(ctx, runtimeID)+ if provider == "hermes" {+ partial := h.cachedModelCatalog(ctx, partialEffortCatalogKey(runtimeID))+ if partial != nil && (complete == nil || partial.StoredAt.After(complete.StoredAt)) {+ if complete != nil {+ partial.Models = fillMissingModelThinking(partial.Models, complete.Models)+ }+ return partial, true+ }+ }+ return complete, false+}++// fillMissingModelThinking preserves the live model list and fills in effort+// metadata that a partial discovery could not confirm again.+func fillMissingModelThinking(models, complete []ModelEntry) []ModelEntry {+ thinkingByID := make(map[string]*ModelThinking, len(complete))+ for _, model := range complete {+ thinkingByID[model.ID] = model.Thinking+ }+ merged := slices.Clone(models)+ for i := range merged {+ if merged[i].Thinking == nil {+ merged[i].Thinking = thinkingByID[merged[i].ID]+ }+ }+ return merged+}+// cachedModelCatalog returns a usable cached catalog, or nil when the cache is// absent, cold, or unreadable. Cache problems must never fail the request — the// caller just falls back to the daemon round trip.@@ -481,7 +512,8 @@ func (h *Handler) GetModelListRequest(w http.ResponseWriter, r *http.Request) {func (h *Handler) ReportModelListResult(w http.ResponseWriter, r *http.Request) {runtimeID := chi.URLParam(r, "runtimeId")- if _, ok := h.requireDaemonRuntimeAccess(w, r, runtimeID); !ok {+ rt, ok := h.requireDaemonRuntimeAccess(w, r, runtimeID)+ if !ok {return}@@ -518,7 +550,8 @@ func (h *Handler) ReportModelListResult(w http.ResponseWriter, r *http.Request)// stand-in the provider substituted after discovery failed, not the// runtime's real catalog. Older daemons omit it; absent means "this// daemon cannot tell us", which stays the pre-MUL-5549 behaviour.- Fallback bool `json:"fallback"`+ Fallback bool `json:"fallback"`+ EffortDiscoveryIncomplete bool `json:"effort_discovery_incomplete"`}if err := json.NewDecoder(r.Body).Decode(&body); err != nil {writeError(w, http.StatusBadRequest, "invalid request body")@@ -532,7 +565,14 @@ func (h *Handler) ReportModelListResult(w http.ResponseWriter, r *http.Request)if body.Supported != nil {supported = *body.Supported}- if err := h.ModelListStore.Complete(r.Context(), requestID, body.Models, body.UnavailableModels, supported); err != nil {+ partialEffort := body.Fallback && body.EffortDiscoveryIncomplete && supported && len(body.Models) > 0+ models := body.Models+ if partialEffort && rt.Provider == "hermes" {+ if complete := h.cachedModelCatalog(r.Context(), runtimeID); complete != nil {+ models = fillMissingModelThinking(models, complete.Models)+ }+ }+ if err := h.ModelListStore.Complete(r.Context(), requestID, models, body.UnavailableModels, supported); err != nil {// Surface the store failure as 5xx so the daemon can retry instead// of swallowing the report (leaves the request stuck in running// until the server-side timeout, which is exactly the "looks OK@@ -557,6 +597,17 @@ func (h *Handler) ReportModelListResult(w http.ResponseWriter, r *http.Request)// store nor grounds to discard a real catalog we already hold. Treat it// like a failure and leave the cache untouched (MUL-5549).if h.ModelCatalogCache != nil {+ if partialEffort {+ // Store only this report's evidence so a refresh cannot extend+ // the lifetime of effort metadata from the complete snapshot.+ if err := h.ModelCatalogCache.Put(r.Context(), partialEffortCatalogKey(runtimeID), body.Models, body.UnavailableModels, true); err != nil {+ slog.Warn("partial effort catalog cache write failed", "error", err, "runtime_id", runtimeID)+ }+ } else if !body.Fallback {+ if err := h.ModelCatalogCache.Invalidate(r.Context(), partialEffortCatalogKey(runtimeID)); err != nil {+ slog.Warn("partial effort catalog cache invalidate failed", "error", err, "runtime_id", runtimeID)+ }+ }switch modelCatalogCacheDecision(body.Models, supported, body.Fallback) {case modelCatalogCacheStore:if err := h.ModelCatalogCache.Put(r.Context(), runtimeID, body.Models, body.UnavailableModels, supported); err != nil {diff --git a/server/pkg/agent/models.go b/server/pkg/agent/models.goindex 3bdfe42680..a72e12bcc0 100644--- a/server/pkg/agent/models.go+++ b/server/pkg/agent/models.go@@ -127,6 +127,9 @@ type Catalog struct {// enter the server's day-scale model-catalog cache, which would pin one// transient failure as the answer for 24h (MUL-5549).Fallback bool+ // EffortDiscoveryIncomplete distinguishes live ACP models with partial+ // effort metadata from a static fallback. Fallback remains true for older servers.+ EffortDiscoveryIncomplete bool// CLIThinkingLevels is the effort vocabulary the installed binary itself// accepts, read from the binary (claude's `--help`) rather than from any// model list. nil means it is unknown; a non-nil empty slice means the@@ -161,7 +164,7 @@ func discovered(models []Model, err error) (Catalog, error) {if errors.Is(err, errACPEffortDiscoveryIncomplete) {// The model IDs are real, but missing effort metadata must not be used// to reject saved settings or cached as a complete discovery.- return Catalog{Models: models, Fallback: true}, nil+ return Catalog{Models: models, Fallback: true, EffortDiscoveryIncomplete: true}, nil}return Catalog{Models: models}, err}