Repository navigation
feat(registry,api): harden warm-pool recovery, admission, and runtime shedding #525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d40e34a
feat(registry): bounded-busy warm-pool candidate gate with no-evict f…
Gajesh2007 4cd97bb
test(registry): MIN_WARM floor re-warms an idle-unloaded box (incl. l…
Gajesh2007 7460fef
feat(registry): combined box-wide admission cap behind EIGENINFERENCE…
Gajesh2007 e6a83de
fix(api): shed 429-vs-503 keys on provider existence, not DEDICATED m…
Gajesh2007 2a1d04c
feat(api): export warm-pool cold-disqualifier tallies as Datadog gauges
Gajesh2007 71ddf4c
feat(api): runtime reject-models admin endpoint (no-restart shed flips)
Gajesh2007 7fbf5a3
docs(operations): document COMBINED_ADMISSION_CAP, WARM_POOL_ALLOW_BU…
Gajesh2007 5b90697
fix(api): harden reject-models PUT input + typed response structs
Gajesh2007 aba4931
fix(api+registry): address 4 Codex review threads on warm-pool/shed PR
Gajesh2007 678cb63
Merge origin/master into fix/warmpool-openpool-ops
Gajesh2007 5176e66
fix: harden warm-pool and runtime shed readiness
Gajesh2007 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/http" | ||
| "strings" | ||
| "unicode" | ||
| "unicode/utf8" | ||
| ) | ||
|
|
||
| // Runtime shed-list ops. | ||
| // | ||
| // EIGENINFERENCE_REJECT_MODELS seeds the per-model reject set at startup | ||
| // (cmd/coordinator/main.go); before these endpoints existed, every shed flip | ||
| // (for example taking Gemma out of — or back into — rotation) required a | ||
| // coordinator restart, and each restart wipes the in-memory TTFT calibrator, | ||
| // TPS registries, breakers, and warm-pool state mid-recovery (1,589 provider | ||
| // sessions died to coordinator restarts in one 48h window). These endpoints | ||
| // mutate the set live: | ||
| // | ||
| // GET /v1/admin/reject-models -> {"models": ["..."]} (current set, sorted) | ||
| // PUT /v1/admin/reject-models <- {"models": ["..."]} (FULL replacement; | ||
| // empty list = shed nothing) | ||
| // | ||
| // Auth mirrors POST /v1/admin/drain (the other runtime-ops toggle): the routes | ||
| // are wrapped in requireAuth (which parses a Privy JWT into context and accepts | ||
| // the admin key as a pseudo-account — no credentials at all is a 401), and the | ||
| // handlers authorize via isAdminAuthorized (admin key OR Privy admin; anything | ||
| // else is a 403). | ||
|
|
||
| // rejectModelsResponse is the wire shape of GET /v1/admin/reject-models. | ||
| type rejectModelsResponse struct { | ||
| Models []string `json:"models"` | ||
| } | ||
|
|
||
| // rejectModelsReplaceResponse is the wire shape of PUT /v1/admin/reject-models: | ||
| // the installed set plus the set it replaced, both sorted. | ||
| type rejectModelsReplaceResponse struct { | ||
| Models []string `json:"models"` | ||
| Previous []string `json:"previous"` | ||
| } | ||
|
|
||
| // Bounds on a PUT /v1/admin/reject-models payload. The reject set only ever | ||
| // holds model IDs from a catalog of a few dozen entries, and real IDs (e.g. | ||
| // "mlx-community/Qwen3.5-0.8B-MLX-4bit") are well under 100 bytes, so these | ||
| // are generous. They exist so a fat-fingered or hostile admin-key holder | ||
| // can't install megabyte-long or control-character-laden strings that would | ||
| // then be echoed into logs and JSON responses. | ||
| const ( | ||
| maxRejectModelsCount = 128 | ||
| maxRejectModelNameLen = 256 | ||
| ) | ||
|
|
||
| // validateRejectModelName rejects entries that could garble logs or responses: | ||
| // over-long names, invalid UTF-8, and control characters. '/' stays legal — | ||
| // real model IDs contain it. The strings are only ever used as map keys, | ||
| // slog values, and JSON array elements (never filesystem paths or commands), | ||
| // so this is defense-in-depth for the admin surface, not an injection fix. | ||
| func validateRejectModelName(model string) error { | ||
| if len(model) > maxRejectModelNameLen { | ||
| return fmt.Errorf("model name exceeds %d bytes", maxRejectModelNameLen) | ||
| } | ||
| if !utf8.ValidString(model) { | ||
| return fmt.Errorf("model name is not valid UTF-8") | ||
| } | ||
| for _, r := range model { | ||
| if unicode.IsControl(r) { | ||
| return fmt.Errorf("model name contains a control character") | ||
| } | ||
| } | ||
| return nil | ||
|
Gajesh2007 marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| // handleAdminGetRejectModels serves GET /v1/admin/reject-models: the current | ||
| // reject set, sorted. Admin-gated and read-only. | ||
| func (s *Server) handleAdminGetRejectModels(w http.ResponseWriter, r *http.Request) { | ||
| if !s.isAdminAuthorized(w, r) { | ||
| return | ||
| } | ||
|
Gajesh2007 marked this conversation as resolved.
Resolved
|
||
| writeJSON(w, http.StatusOK, rejectModelsResponse{Models: s.RejectModels()}) | ||
| } | ||
|
|
||
| // handleAdminPutRejectModels serves PUT /v1/admin/reject-models: full | ||
| // replacement of the reject set. An empty list sheds nothing. Every change is | ||
| // logged loudly (old set -> new set) — this is the same class of operator | ||
| // action as flipping EIGENINFERENCE_REJECT_MODELS, minus the restart. | ||
| func (s *Server) handleAdminPutRejectModels(w http.ResponseWriter, r *http.Request) { | ||
| if !s.isAdminAuthorized(w, r) { | ||
| return | ||
| } | ||
| var req struct { | ||
| Models []string `json:"models"` | ||
| } | ||
| if !decodeCappedJSON(w, r, maxControlPlaneBodyBytes, &req) { | ||
| return | ||
| } | ||
| if len(req.Models) > maxRejectModelsCount { | ||
| writeJSON(w, http.StatusBadRequest, errorResponse("invalid_request_error", | ||
| fmt.Sprintf("too many models: %d (max %d)", len(req.Models), maxRejectModelsCount))) | ||
| return | ||
| } | ||
| // Validate everything before touching the live set: a bad entry must not | ||
| // leave a half-applied replacement. | ||
| set := make(map[string]bool, len(req.Models)) | ||
| for i, model := range req.Models { | ||
| model = strings.TrimSpace(model) | ||
| if model == "" { | ||
| continue // blank/whitespace-only entries are dropped, not errors | ||
| } | ||
| if err := validateRejectModelName(model); err != nil { | ||
| writeJSON(w, http.StatusBadRequest, errorResponse("invalid_request_error", | ||
| fmt.Sprintf("models[%d]: %v", i, err))) | ||
| return | ||
| } | ||
| set[model] = true | ||
|
Gajesh2007 marked this conversation as resolved.
Resolved
Gajesh2007 marked this conversation as resolved.
Resolved
Gajesh2007 marked this conversation as resolved.
Resolved
|
||
| } | ||
| previous, current := s.ReplaceRejectModels(set) | ||
|
Gajesh2007 marked this conversation as resolved.
Resolved
|
||
| s.logger.Warn("model shed set REPLACED via /v1/admin/reject-models (runtime, no restart)", | ||
| "old", previous, | ||
| "new", current, | ||
| "remote_addr", r.RemoteAddr, | ||
| ) | ||
| writeJSON(w, http.StatusOK, rejectModelsReplaceResponse{ | ||
| Models: current, | ||
| Previous: previous, | ||
| }) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.