[Fix] Classify SessionServer endpoints and fail closed on trace errors - #2061
Open
matrix72c wants to merge 4 commits into
Open
[Fix] Classify SessionServer endpoints and fail closed on trace errors#2061matrix72c wants to merge 4 commits into
matrix72c wants to merge 4 commits into
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
matrix72c
force-pushed
the
fix/session-server-endpoint-classification
branch
from
September 2, 2026 03:36
dd8954e to
cd15002
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
SessionServeris a catch-all HTTP proxy, but only two requests represent model generations:POST /v1/messagesandPOST /v1/chat/completions.This change makes endpoint policy explicit before request/response processing and makes trace-enabled generations fail closed when the response cannot be recorded. Auxiliary API calls remain transparent, while the client-visible result stays consistent with the training trace stored by
SessionServer.The response-reliability changes previously proposed in #2059 are consolidated here so endpoint and trace policy are reviewed in one PR.
Problem
The proxy cannot safely infer the endpoint from the JSON body. For example,
POST /v1/messages/count_tokenscontainsmessagesbut is not a model generation. Treating it as one can invokeon_request, inject generation-only fields, filter tools, or invokeon_responseunexpectedly.For trace-enabled generations, malformed JSON, non-object response bodies, incomplete SSE streams, downstream disconnects, or a failing
on_responsehook can leave the trace store without a complete assistant turn. Returning a normal success response in that situation allows the caller to observe a turn that cannot be used for training.Implementation
_is_generation_endpoint(method, path)predicate. It uses the normalized method and path, ignores query strings, and recognizes onlyPOST /v1/messagesandPOST /v1/chat/completionsas generation endpoints./v1/messages/count_tokens,/v1/messages/batches, and future/v1/messages/...paths still receive the correct Anthropic headers._handle_request; noContextVar, wrapper handler, shared enum, or cross-project abstraction is introduced.session_id. Non-object bodies and objects withoutsession_idremain byte-for-byte unchanged whenever possible.2xxresponses never enter the cleaner or trace hooks, and explicit upstream error envelopes are passed through without being wrapped again.[DONE]until parsing andon_responsecomplete. If parsing or the response hook fails, return a native500error or SSE error event without[DONE].Successful generation behavior, the public
SessionServerAPI, and the existing/v1/responses501rejection remain unchanged. No LMDeploy code or management endpoint implementation is changed, andfix/chunk-loss-detached-head-memoryis untouched.Tests
Added focused
aiohttpfake-upstream coverage for:count_tokensand auxiliary endpoint forwarding with no generation hooks;on_response;2xxresponses remaining unchanged;2xxresponses failing closed;[DONE]; andValidation performed: