mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-10-15 05:29:28 +00:00
fix(registry): recover refresh goroutine, per-provider warm-fill budget, exact-glob model authorization
1. refreshProvider (the plugin's only background goroutine) had no recover(): a panicking adapter's listModels would crash the whole Traefik process. Restructured around deferred recover + finishRefresh, so a panic is turned into a logged error, inFlight always releases, and the next interval retries. Documented as a scoped exception to limits.go's no-background-goroutine rule. 2. newGateway wrapped ctx in an outer 5s WithTimeout before warmFill, but warmFill already derives a fresh 5s budget per provider from whatever ctx it receives. The outer wrap made that a single budget shared across every discovery-enabled provider instead of a per-provider one - providers after the first could get a near-expired context and fail instantly. Dropped the outer wrapper; construction's worst case is now N * 5s, accepted. 3. group.allowsModel stripped at any first slash, so a glob like 'deepseek-*' could spuriously match a bare model id that merely contains a slash (e.g. an upstream's own 'uni/deepseek-v4-flash-0731' naming) even though the leading segment names no configured provider. allowsModel is now an exact glob with no internal splitting; resolveAgainst and listFor generate the provider-prefixed and bare-suffix candidates themselves, only when a prefix legitimately names a configured provider. Updated the Task-3 TestIdentify assertion to match. 4. Annotated the discarded json.Encode error in handleModels. Gate: go test ./... -count=1, -race, gofmt, vet, fieldalignment, golangci-lint (incl gosec) all clean.
This commit is contained in:
+8
-2
@@ -30,8 +30,14 @@ func TestIdentify(t *testing.T) {
|
||||
if !grp.allowsModel("gpt-5-mini") {
|
||||
t.Error("glob should match")
|
||||
}
|
||||
if !grp.allowsModel("openai/gpt-5-mini") {
|
||||
t.Error("prefixed form should match")
|
||||
// allowsModel is an exact glob against the given string only — it no
|
||||
// longer strips a "provider/" prefix itself (fix(registry) ruling 3): a
|
||||
// pattern like "gpt-5*" reaching a provider-prefixed request like
|
||||
// "openai/gpt-5-mini" is now the caller's job (modelRegistry.
|
||||
// resolveAgainst / listFor build the bare-suffix candidate themselves),
|
||||
// covered at the registry level in registry_test.go, not here.
|
||||
if grp.allowsModel("openai/gpt-5-mini") {
|
||||
t.Error("allowsModel must not match a provider-prefixed id on its own; prefix-stripping now lives in the caller")
|
||||
}
|
||||
if grp.allowsModel("claude-4") {
|
||||
t.Error("should not match")
|
||||
|
||||
Reference in New Issue
Block a user