Conversation
Auto-syncs main branch from upstream diegosouzapw/OmniRoute every 6 hours. Also triggerable manually via workflow_dispatch. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
…ent: prefix When all combo models fail via the quality-check path (200 response with invalid body), lastStatus was never set because result.ok is true. This caused the combo to return ALL_ACCOUNTS_INACTIVE instead of the proper error status. Additionally, validateResponseQuality only recognized SSE payloads starting with "data:" but not "event:" lines (Anthropic-style SSE), causing false quality-check failures for non-streaming requests routed through anthropic-compatible providers that return streaming responses. Fixes: - Set lastStatus=422 and lastError in quality-check failure path (both priority and round-robin code paths) - Accept SSE responses starting with "event:" or containing "\ndata:" in addition to "data:"
3397f90 to
06fcd3c
Compare
There was a problem hiding this comment.
Code Review
This pull request enhances SSE response validation by supporting 'event:' prefixes and ensures that quality check failures correctly set a 422 status code and error message. Feedback was provided to update the error handling logic so that the most recent failure reason is captured, maintaining consistency with existing patterns in the codebase.
| }); | ||
| recordedAttempts++; | ||
| if (!lastStatus) lastStatus = 422; | ||
| lastError = lastError || `quality check failed: ${quality.reason}`; |
There was a problem hiding this comment.
To maintain consistency with the error handling logic in the !result.ok branch (see line 1705), lastError should be updated with the latest failure reason rather than preserving the first one. The current use of the logical OR operator (||) deviates from the established pattern where lastStatus captures the first status code while lastError captures the most recent error message.
| lastError = lastError || `quality check failed: ${quality.reason}`; | |
| lastError = `quality check failed: ${quality.reason}`; |
| }); | ||
| recordedAttempts++; | ||
| if (!lastStatus) lastStatus = 422; | ||
| lastError = lastError || `quality check failed: ${quality.reason}`; |
There was a problem hiding this comment.
To maintain consistency with the error handling logic in the !result.ok branch (see line 2053), lastError should be updated with the latest failure reason rather than preserving the first one. The current use of the logical OR operator (||) deviates from the established pattern where lastStatus captures the first status code while lastError captures the most recent error message.
| lastError = lastError || `quality check failed: ${quality.reason}`; | |
| lastError = `quality check failed: ${quality.reason}`; |
|
Subsumed by #1444 and manually merged |
Problem
Two bugs in the combo routing engine caused false
ALL_ACCOUNTS_INACTIVEerrors:Bug 1: lastStatus tracking gap in quality-check failure path
When all combo models fail via the quality-check path (200 response that fails
validateResponseQuality),lastStatuswas never set becauseresult.okis true. The code only setslastStatusin the!result.okerror branch. This caused the final checkif (!lastStatus)to returnALL_ACCOUNTS_INACTIVEinstead of the proper error status.Bug 2: SSE event: prefix not recognized
validateResponseQualityonly recognized SSE payloads starting withdata:. Anthropic-style SSE starts withevent:lines beforedata:lines, so non-streaming requests routed throughanthropic-compatible-*providers that returned streaming responses were falsely rejected as "response is not valid JSON".Fix
combo.ts (2 changes):
lastStatus = 422andlastErrorin the quality-check failure path (both priority and round-robin code paths), so the combo returns proper 422 status with the quality-check failure reason instead ofALL_ACCOUNTS_INACTIVEevent:or containing\ndata:in addition todata:invalidateResponseQualityTests
3 new tests in
combo-routing-engine.test.ts:handleComboChat returns 422 (not ALL_ACCOUNTS_INACTIVE) when all models fail quality checkhandleComboChat accepts SSE responses starting with event: line as validhandleComboChat accepts SSE responses with event and data on separate linesAll 55 combo routing tests pass (52 existing + 3 new).