Classify SessionServer endpoints before proxying - #2061
Open
matrix72c wants to merge 1 commit into
Open
Conversation
matrix72c
force-pushed
the
fix/session-server-endpoint-classification
branch
3 times, most recently
from
September 1, 2026 13:00
623f513 to
d80dd84
Compare
matrix72c
force-pushed
the
fix/session-server-endpoint-classification
branch
from
September 1, 2026 13:01
d80dd84 to
6165c7b
Compare
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
This PR makes
SessionServerclassify requests from the HTTP method and normalized endpoint before inspecting or mutating their JSON envelopes.It fixes Anthropic
/v1/messages/count_tokensrequests being mistaken for model generations because they contain prompt-shaped fields such asmessages, and it closes the catch-all proxy path that could otherwise forward unrelated requests to LMDeploy management endpoints.This endpoint-policy change was split out of #2059 so that proxy routing and trace-reliability behavior can be reviewed independently.
Endpoint behavior
POST /v1/messagesPOST /v1/chat/completionsPOST /v1/responses501responsePOST /v1/messages/count_tokenssession_idHEAD /api/hello204locally404locallyIn particular,
GET /v1/modelsand LMDeploy management routes such as/terminate,/update_weights,/sleep, and/wakeupnever reach the worker.Implementation
method + normalized path.on_request, response cleaning, stream parsing, andon_response.count_tokenspreservesmessages,system,tools, and other client fields. Only the compatibility-onlysession_idfield is removed.HEAD /api/hello, unsupported methods, and unsupported endpoints locally before opening an upstream connection.The classifier is intentionally private and local to
SessionServer; this PR does not add a shared enum, dataclass, or cross-project abstraction.Tests
Added focused classifier and local
aiohttpfake-upstream tests covering:Validation performed on this topic alone:
The topic also merges cleanly with #2059 in the local integration branch; the combined endpoint and trace suites pass all 12 tests.
Non-goals