-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
fix(sse): track lastStatus on quality-check failure and detect SSE event: prefix #1440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| name: Sync Fork | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: "0 */6 * * *" | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| sync: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: main | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Sync upstream | ||
| run: | | ||
| git remote add upstream https://github.com/diegosouzapw/OmniRoute.git | ||
| git fetch upstream main | ||
| git merge upstream/main --no-edit | ||
| git push origin main |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -65,7 +65,11 @@ const COMBO_BAD_REQUEST_FALLBACK_PATTERNS = [ | |||||
| // Used to detect 503 responses from handleNoCredentials so combo can fallback. | ||||||
| const ALL_ACCOUNTS_RATE_LIMITED_PATTERNS = [/unavailable/i, /service temporarily unavailable/i]; | ||||||
|
|
||||||
| function isAllAccountsRateLimitedResponse(status: number, contentType: string | null, errorText: string): boolean { | ||||||
| function isAllAccountsRateLimitedResponse( | ||||||
| status: number, | ||||||
| contentType: string | null, | ||||||
| errorText: string | ||||||
| ): boolean { | ||||||
| if (status !== 503) return false; | ||||||
| if (!contentType?.includes("application/json")) return false; | ||||||
| return ALL_ACCOUNTS_RATE_LIMITED_PATTERNS.some((p) => p.test(errorText)); | ||||||
|
|
@@ -168,7 +172,9 @@ async function validateResponseQuality( | |||||
| try { | ||||||
| json = JSON.parse(text); | ||||||
| } catch { | ||||||
| if (text.startsWith("data:")) return { valid: true }; | ||||||
| if (text.startsWith("data:") || text.startsWith("event:") || text.includes("\ndata:")) { | ||||||
| return { valid: true }; | ||||||
| } | ||||||
| return { valid: false, reason: "response is not valid JSON" }; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -1522,6 +1528,8 @@ export async function handleComboChat({ | |||||
| target: toRecordedTarget(target), | ||||||
| }); | ||||||
| recordedAttempts++; | ||||||
| if (!lastStatus) lastStatus = 422; | ||||||
| lastError = lastError || `quality check failed: ${quality.reason}`; | ||||||
| if (i > 0) fallbackCount++; | ||||||
| break; // move to next model | ||||||
| } | ||||||
|
|
@@ -1900,6 +1908,8 @@ async function handleRoundRobinCombo({ | |||||
| target: toRecordedTarget(target), | ||||||
| }); | ||||||
| recordedAttempts++; | ||||||
| if (!lastStatus) lastStatus = 422; | ||||||
| lastError = lastError || `quality check failed: ${quality.reason}`; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To maintain consistency with the error handling logic in the
Suggested change
|
||||||
| if (offset > 0) fallbackCount++; | ||||||
| break; // move to next model | ||||||
| } | ||||||
|
|
@@ -2001,7 +2011,10 @@ async function handleRoundRobinCombo({ | |||||
| } | ||||||
|
|
||||||
| if (isAllAccountsRateLimited) { | ||||||
| log.info("COMBO", `All accounts rate-limited for ${modelStr}, falling back to next model`); | ||||||
| log.info( | ||||||
| "COMBO", | ||||||
| `All accounts rate-limited for ${modelStr}, falling back to next model` | ||||||
| ); | ||||||
| } else if (!shouldFallback && !comboBadRequestFallback) { | ||||||
| log.warn("COMBO-RR", `${modelStr} failed (no fallback)`, { status: result.status }); | ||||||
| recordComboRequest(combo.name, modelStr, { | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To maintain consistency with the error handling logic in the
!result.okbranch (see line 1705),lastErrorshould 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 wherelastStatuscaptures the first status code whilelastErrorcaptures the most recent error message.