fix(ai): crash-proof SSE parsing + drop dead AiResult.RateLimited#8
Closed
Azyrn wants to merge 2 commits into
Closed
fix(ai): crash-proof SSE parsing + drop dead AiResult.RateLimited#8Azyrn wants to merge 2 commits into
Azyrn wants to merge 2 commits into
Conversation
OpenAI-compatible providers may send the error `code` as a string
("rate_limit_exceeded") instead of an int, and a mid-stream chunk can
be schema-mismatched or truncated. Either case threw a
SerializationException from decodeFromString in parseStreamPiece that
ProviderExecutor.run does not catch, so it escaped the retry/fallback
loop and failed the whole flow with a raw exception.
Loosen ApiError.code to JsonElement and read it via a codeInt helper,
and wrap the streaming decode in decodeChunk so a parse failure is
re-thrown as TransientAiException. ProviderExecutor already treats
TransientAiException as retryable, so a bad chunk now degrades to a
normal retry / provider fallback instead of a crash.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
AiResult.RateLimited was never constructed anywhere in the pipeline — rate limits already surface as AiResult.Error strings via exhaustedMessage / httpErrorMessage. The three UI branches handling it (ResultsScreen, AiScanViewModel extraction + translation) were dead, and its remainingMs had no source. Remove the variant and its dead consumers; the sealed when-expressions stay exhaustive over Success/Error, and a rate-limited translation now falls through to the existing Error branch. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Two fixes from the
core/aiaudit, worst-severity first. Scoped to findings #1–#2 only; #3–#10 deferred.#1 — Malformed SSE chunk crashes the scan pipeline (critical)
ProviderClient.parseStreamPiecedecoded every SSE line withdecodeFromString; a schema/type mismatch (OpenAI-compatible providers send errorcodeas a string like"rate_limit_exceeded", or a truncated mid-stream chunk) threw aSerializationExceptionthatProviderExecutor.rundoes not catch — it escaped the retry/fallback loop and failed the whole flow with a raw exception.ApiError.codeInt?→JsonElement?, read via newcodeInthelper (numeric only).decodeChunk<T>()wraps the streaming decode for all 3 kinds; parse failure →TransientAiException.err.code == 429→err.codeInt == 429.ProviderExecutoralready treatsTransientAiExceptionas retryable, so a bad chunk now degrades to a normal retry / provider fallback instead of a crash.#2 — Remove never-produced
AiResult.RateLimited(moderate)The variant was never constructed anywhere; rate limits already surface as
AiResult.Errorstrings. Three UI branches handling it were dead andremainingMshad no source.ResultsScreenandAiScanViewModel(extraction + translation).Errorbranch → shows "Translation failed" instead of failing silently (intended, kept per review).Testing
:app:compileDebugKotlinclean after each commit.grep RateLimitedacrossapp/src/main/java→ none remain;whenexpressions stay exhaustive overSuccess/Error.decodeChunkthrow →consumeSsebody.use{}closes body →stream()→withTimeout→ProviderExecutorcatch (TransientAiException)→ backoff retry →Exhausted→ next provider in chain.Not in scope
Findings #3–#10 (duplicate endpoint/auth knowledge, repeated 429 parse blocks, Anthropic once() 429 gap, presentation copy in core, dead
ICON_TRANSLATE/OcrEngine.displayName, HF verify false-positive, text-mime error message).🤖 Generated with Claude Code