[Fix] Preserve SessionServer traces across response failures - #2059
Closed
matrix72c wants to merge 1 commit into
Closed
[Fix] Preserve SessionServer traces across response failures#2059matrix72c wants to merge 1 commit into
matrix72c wants to merge 1 commit into
Conversation
matrix72c
force-pushed
the
fix/session-server-untraceable-response
branch
from
September 1, 2026 09:06
ee51a92 to
4104f70
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 prevents trace-enabled
SessionServergenerations from being silently lost when the downstream client disconnects before response headers are prepared or when an upstream successful response cannot be recorded.It also keeps upstream error responses out of generation trace processing and returns those errors unchanged to the client.
The endpoint-classification and proxy allowlist changes originally included in this PR have been split into #2061. This PR now contains only trace-response reliability behavior and is independently based on
upstream/main.Problem
Disconnect before response preparation
The streaming path already stopped writing after a downstream disconnect while continuing to drain the upstream response for trace completion. However,
response.prepare(request)ran before that protected state was established. If the client disconnected before headers were prepared, the exception escaped and the upstream response was no longer drained, leaving the training trace incomplete.Successful but untraceable response
For a trace-enabled non-streaming request, a JSON array or non-JSON 2xx response previously left
response_dataunset and returned the successful upstream response without callingon_response. The client could observe or record a successful turn while the trace store had no corresponding node.Upstream error payloads
Non-2xx responses are capability or request errors, not successful generations. They should remain visible to the caller in their original form and must not enter response cleaning or trace hooks.
Implementation
trace_responsefrom both the request trace flag and the upstream HTTP status.on_response.500error instead of silently omitting the trace.on_response, whose existing fail-closed error handling remains authoritative.No endpoint allowlist,
count_tokens, hello, or management-route policy is introduced here; those changes are isolated in #2061.Tests
Added focused local
aiohttpfake-upstream tests covering:on_response.Validation performed on this topic alone:
This topic merges cleanly with #2061 in the local integration branch; the combined endpoint and trace suites pass all 12 tests.
Scope