feat(combo): validate empty 200 responses with retry-before-fallback#2689
Open
berthojoris wants to merge 2 commits into
Open
feat(combo): validate empty 200 responses with retry-before-fallback#2689berthojoris wants to merge 2 commits into
berthojoris wants to merge 2 commits into
Conversation
- Add isBodyEmpty() helper to detect 12 empty body patterns (empty string, empty object/array, empty choices/content/text) - On 200 + empty body: retry same model once before falling back - Streaming/opaque responses are trusted (skip body validation) - Does not pollute lastError on empty responses — final error message stays accurate to the most recent genuine failure
- Tests cover: valid body, empty object, empty array, empty string, empty choices, empty message content, empty message object - Retry behavior: recovery on second attempt, fallback to next model - lastError not polluted by empty responses - Streaming responses treated as valid (no retry triggered) - All 11 tests passing
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
Adds empty response body validation to combo fallback. When a provider returns HTTP 200 but the body is empty/null/empty-array/empty-object, the combo now retries the same model once before falling back to the next model. This catches transient empty responses from overloaded providers without prematurely burning combo slots or polluting
lastError.Changes
open-sse/services/combo.js— +57/-2 linesisBodyEmpty()helper detects 12 empty body patterns (empty string,{},[],{"choices":[]},{"choices":""},{"choices":[{}]},{"choices":[{"delta":{},"finish_reason":null}]},{"choices":[{"message":{"content":""}}]},{"choices":[{"message":{}}]},{"content":""},{"content":[]},{"text":""})continueto next modellastError— final "all models failed" message stays accurateTest coverage
tests/unit/combo-empty-200-fallback.test.js(11 tests) — all passing ✅{}→ retry → succeed on second attempt[]→ retry → succeed on second attempt{"content":""}→ fallback{"message":{}}→ fallback[]→ fallbacklastErrornot polluted (generic "All combo models unavailable")Edge cases handled
{}(empty object) — caught, retried, fallback{"choices":[]}— caught, retried, fallback""— caught, retried, fallbacktext/event-stream) —.text()throws, caught silently, response trustedlastError— ensures accurate error reportingAuthoring disclosure
Generated with Hermes Agent (Claude Opus 4); verified locally.