fix(server): validate sampling params and rebuild timeout at the API layer - #223
Open
Artemowka22 wants to merge 1 commit into
Open
fix(server): validate sampling params and rebuild timeout at the API layer#223Artemowka22 wants to merge 1 commit into
Artemowka22 wants to merge 1 commit into
Conversation
resolve_sampling forwarded arbitrary client floats into SamplingParams: negative, NaN and inf temperature, top_p outside (0, 1], top_k 0 -- all reached the engine and died (or misbehaved) deep in the sampler instead of failing the request. Validate the RESOLVED values (checkpoint defaults included) and raise ValueError in the style of the existing max_tokens check; every adapter already maps that to a clean 400. CacheRebuildRequest.timeout gets the matching pydantic bound (0 < t <= 3600) so a NaN/inf/negative timeout cannot reach asyncio.wait_for. Found via the freetoken-mlx downstream audit (docs/AUDIT.md, defects 3-4); the rebuild TOCTOU race from that audit is already structurally fixed upstream, so only the timeout bound is ported.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Invalid sampling silently reaches the engine.
resolve_samplingforwards arbitrary client floats:temperature=-3,NaN,inf,top_p=0,top_p=7,top_k=0all become aSamplingParamsand die (or misbehave) deep in the sampler instead of failing the request. Fix: after checkpoint defaults are filled, validatetemperature(finite, ≥ 0),top_p((0, 1]),top_k(−1 or ≥ 1) and raiseValueErrorin the same style as the existingmax_tokenscheck — every adapter already maps that to a clean HTTP 400.CacheRebuildRequest.timeoutis unbounded. A negative/NaN/huge timeout reachesasyncio.wait_foron the rebuild future;infparks the handler forever. Fix: pydantic bound0 < timeout ≤ 3600.The audit that surfaced these (agisota/freetoken-mlx, docs/AUDIT.md, defects 3–4) also reported a TOCTOU race on concurrent
/v1/cache/rebuild; current upstream has already restructured that path (single synchronous section from the pre-flight checks tomaintenance_state = "rebuilding"), so only the timeout bound is ported.Test plan
/v1/chat/completionsintests/server/test_openai_api.py— 400 with the offending parameter named; boundary valuestemperature=0,top_p=1,top_k=-1,top_k=1acceptedtests/server/test_rebuild_maintenance.pytests/server/suite passes