fix: reasoning duplication, quota reported as 502, network blip aborting retries - #5
Open
maxff77 wants to merge 1 commit into
Open
fix: reasoning duplication, quota reported as 502, network blip aborting retries#5maxff77 wants to merge 1 commit into
maxff77 wants to merge 1 commit into
Conversation
Independent of each other; each one is small and reproducible. 1. Reasoning content was duplicated quadratically. Upstream `thinking_summary` events each carry the full summary so far, not an increment. `parseQwenSsePayload` concatenated them, so a 263-character summary reached the client as roughly 1.5 KB of repeated text. Merge cumulative fragments by replacement. 2. Quota exhaustion was reported as HTTP 502. Qwen returns `You've reached the upper limit for today's usage.` as HTTP 200 with an error body, which became a blanket 502. Clients read that as a gateway fault and retry blindly instead of backing off. Map the rate-limit signatures to 429 with `type: "rate_limit_error"`; everything else stays on 502. 3. A network blip aborted the whole request instead of retrying. `createChatSession` called `getBaxiaTokens` outside its try block, so a network failure while refreshing tokens on retry escaped the function: the remaining retries never ran and Express answered with an empty 500. The completion fetch was unguarded in all three call sites too, with the same result. Route them through `fetchUpstream`, which turns a network exception into a synthetic failed response so the existing `!ok` branch reports it properly. Adds `scripts/test-core.js` (6 assert-based checks, no framework, no new dependencies) and a CI workflow, since the repo had no job running tests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Someone is attempting to deploy a commit to the smanx's projects Team on Vercel. A member of the Team first needs to authorize it. |
❌ Deploy Preview for qwen2api failed. Why did it fail? →
|
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.
Three independent failure modes found while exercising the live Qwen endpoint. Each is small and reproducible; none of them depend on each other.
1. Reasoning content was duplicated quadratically
Upstream
thinking_summaryevents each carry the full summary so far, not an increment.parseQwenSsePayloadconcatenated them, so a 263-character summary reached the client as roughly 1.5 KB of repeated text.Merged by replacement when a fragment starts with what we already have; genuinely incremental fragments still concatenate.
2. Quota exhaustion was reported as HTTP 502
Qwen returns
You've reached the upper limit for today's usage.as HTTP 200 with an error body, which became a blanket 502. Clients read that as a gateway fault and retry blindly instead of backing off.Rate-limit signatures now map to
429withtype: "rate_limit_error". Every other upstream failure stays on 502.3. A network blip aborted the request instead of retrying
createChatSessioncalledgetBaxiaTokensoutside its try block, so a network failure while refreshing tokens on retry escaped the function entirely: the remaining retries never ran and Express answered with an empty 500. The signature in the logs is a singleexception (attempt 1)line followed by nothing.The completion
fetchwas unguarded in all three call sites too, with the same result. Both now go throughfetchUpstream, which turns a network exception into a synthetic failed response so the existing!okbranch reports it properly.Testing
Adds
scripts/test-core.js— 6 assert-based checks, no framework, no new dependencies — and a CI workflow, since the repo had no job running tests.Happy to split this into three separate PRs if you would rather review them one at a time.