fix(api-server): persist response snapshot on client disconnect AND server cancellation (salvages #15171)#15392
Merged
Merged
Conversation
…r too Extends PR #15171 to also cover the server-side cancellation path (aiohttp shutdown, request-level timeout) — previously only ConnectionResetError triggered the incomplete-snapshot write, so cancellations left the store stuck at the in_progress snapshot written on response.created. Factors the incomplete-snapshot build into a _persist_incomplete_if_needed() helper called from both the ConnectionResetError and CancelledError branches; the CancelledError handler re-raises so cooperative cancellation semantics are preserved. Adds two regression tests that drive _write_sse_responses directly (the TestClient disconnect path races the server handler, which makes the end-to-end assertion flaky).
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.
Salvages @UgwujaGeorge's PR #15171 with a follow-up for the asyncio.CancelledError path.
Summary
Streamed
/v1/responsescalls withstore=truenow leave a retrievable snapshot inResponseStorewhether the stream ends cleanly, on client disconnect, OR on server-side cancellation (shutdown, request-level timeout). Previously only the clean path wrote to the store, soGET /v1/responses/{id}andprevious_response_idchaining 404'd after any abrupt termination.Changes
in_progresssnapshot immediately afterresponse.created, updates it tocompleted/failedon terminal events, writes anincompletesnapshot onConnectionResetError/BrokenPipeError/OSError.incompleteonasyncio.CancelledError(server shutdown, request timeout). Factors the incomplete-snapshot build into_persist_incomplete_if_needed()so both branches share one implementation; the cancellation handler re-raises to preserve cooperative-cancel semantics. Adds two direct_write_sse_responsestests (TestClient-level disconnect races the server handler, flaky for an end-to-end assertion).AUTHOR_MAPentry for @UgwujaGeorge so release notes attribute correctly.Validation
Closes #15171.