diff --git a/internal/config/config.go b/internal/config/config.go index 638982c4b..29935c7c6 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -463,7 +463,7 @@ func (c Config) ForTask() TaskConfig { BotUser: c.BotUser, BotEmail: c.BotEmail, Models: cloneStringMap(c.Models), - ModelLimits: maps.Clone(c.ModelLimits), + ModelLimits: c.aliasedModelLimits(), Budgets: c.Budgets, MaxRetries: c.MaxRetries, Dispatch: Dispatch{Trigger: c.Dispatch.Trigger, AckReaction: c.Dispatch.AckReaction}, @@ -474,6 +474,22 @@ func (c Config) ForTask() TaskConfig { } } +// aliasedModelLimits keeps the limits of the models an alias can resolve to. +// Workflows reach a model only through Models, so the rest of the provider +// catalog would only bloat every attempt's captured configuration. +func (c Config) aliasedModelLimits() map[string]ModelLimits { + var out map[string]ModelLimits + for _, ref := range c.Models { + if l, ok := c.ModelLimits[ref]; ok { + if out == nil { + out = make(map[string]ModelLimits) + } + out[ref] = l + } + } + return out +} + // ToConfig expands a TaskConfig back into a Config with only the carried // fields populated -- everything else (Repos, NATS, Containers, Providers, // secrets) is zero. Used by archie-agent to reconstruct the Config value diff --git a/internal/config/fortask_test.go b/internal/config/fortask_test.go new file mode 100644 index 000000000..cdfb41304 --- /dev/null +++ b/internal/config/fortask_test.go @@ -0,0 +1,28 @@ +package config + +import ( + "maps" + "slices" + "testing" +) + +func TestForTaskCarriesOnlyAliasedModelLimits(t *testing.T) { + cases := []struct { + name string + models map[string]string + limits map[string]ModelLimits + want []string + }{ + {"catalog beyond the aliases is dropped", map[string]string{"default": "a/x", "fast": "a/y"}, map[string]ModelLimits{"a/x": {}, "a/y": {}, "a/z": {}, "b/q": {}}, []string{"a/x", "a/y"}}, + {"alias without catalog entry carries nothing", map[string]string{"default": "a/x"}, map[string]ModelLimits{"b/q": {}}, nil}, + {"no aliases carries nothing", nil, map[string]ModelLimits{"b/q": {}}, nil}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + got := slices.Sorted(maps.Keys(Config{Models: tc.models, ModelLimits: tc.limits}.ForTask().ModelLimits)) + if !slices.Equal(got, tc.want) { + t.Fatalf("limits = %v, want %v", got, tc.want) + } + }) + } +}