feat: respnoses api error cache handler#599
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the relay’s handling of OpenAI “Responses API” (and related adapters) by (1) rewriting outbound model fields back to the client-requested/origin model, and (2) strengthening streaming error handling—especially around lifecycle events and late-arriving error events.
Changes:
- Generalize stream scanner sizing to consider multiple model names (origin + actual), ensuring image-model streams get the larger buffer even when models are mapped.
- Add
keepalivestream event support and parse/propagateerrorobjects on Responses API SSE events; implement buffering logic to avoid emitting lifecycle events too early when an error is imminent. - Rewrite top-level and nested
modelfields in Responses + Video outputs to return origin model names consistently; update adapter conversions and tests accordingly.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| core/relay/utils/utils.go | NewStreamScanner now accepts multiple model names; uses image buffer if any matches image models. |
| core/relay/utils/utils_test.go | Adds coverage to ensure mapped image models get the larger scanner buffer. |
| core/relay/utils/reasoning.go | Refactors FirstMatchingModelName to accept variadic model names and updates internal callers. |
| core/relay/model/response.go | Adds keepalive event constant and error field to stream event model. |
| core/relay/adaptor/vertexai/adaptor.go | Updates FirstMatchingModelName call signature usage. |
| core/relay/adaptor/qianfan/adaptor.go | Updates FirstMatchingModelName call signature usage. |
| core/relay/adaptor/openai/video.go | Rewrites top-level model in video JSON responses back to origin model. |
| core/relay/adaptor/openai/response.go | Adds Responses API model rewriting + new streaming scan/buffer/error handling logic. |
| core/relay/adaptor/openai/response_test.go | Adds/updates tests for stream buffering/error behavior and model rewriting. |
| core/relay/adaptor/openai/reasoning.go | Updates FirstMatchingModelName call signature usage. |
| core/relay/adaptor/openai/image.go | Ensures scanner sizing considers origin + actual model names. |
| core/relay/adaptor/openai/gemini.go | Uses origin model name in Gemini responses; strengthens stream error handling. |
| core/relay/adaptor/openai/gemini_to_responses_test.go | Updates expected Gemini model version to origin model. |
| core/relay/adaptor/openai/gemini_test.go | Adds coverage for error handling before downstream writes. |
| core/relay/adaptor/openai/claude.go | Uses origin model name in Claude responses; strengthens stream error handling. |
| core/relay/adaptor/openai/claude_test.go | Updates expected Claude model and adds stream error test. |
| core/relay/adaptor/openai/chat.go | Introduces responseModelName helper; improves stream error handling and output filtering. |
| core/relay/adaptor/openai/chat_test.go | Updates/extends tests for stream done/error behavior and origin model propagation. |
| core/relay/adaptor/gemini/openai.go | Updates FirstMatchingModelName call signature usage. |
| core/relay/adaptor/gemini/adaptor.go | Updates FirstMatchingModelName call signature usage. |
| core/relay/adaptor/doubao/main.go | Updates FirstMatchingModelName call signature usage. |
| core/relay/adaptor/doubao/chat.go | Updates FirstMatchingModelName call signature usage. |
| core/relay/adaptor/baidu/adaptor.go | Updates FirstMatchingModelName call signature usage. |
| core/relay/adaptor/anthropic/utils.go | Updates FirstMatchingModelName call signature usage. |
| core/relay/adaptor/anthropic/openai.go | Updates FirstMatchingModelName call signature usage. |
| core/relay/adaptor/ali/chat.go | Updates FirstMatchingModelName call signature usage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
No description provided.