fix(config): a task snapshot carries only the model limits its aliases resolve to
This commit is contained in:
2 files changed
+45
-1
No files matched your search
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user