Repository navigation
fix(playground): classify Gemini errors from their message, not metadata - #133
Merged
Merged
Conversation
googleai_dart appends the request URL, a millisecond-timestamp request ID (req_1790…), and the latency to an exception's toString(). ErrorClassifier substring-matched that whole string against status-number patterns, so whenever the timestamp contained 401, 403, or 429 a safety block or a server error was reported as an invalid API key or an overloaded model. That also made generation_model_client_test fail intermittently in CI. Match SDK errors on their message, and match status numbers only as whole numbers.
|
Visit the preview URL for this PR (updated for commit 8e04574): https://superdeck-dev--pr133-fix-error-classifier-f3vnjquw.web.app (expires Fri, 23 Oct 2026 04:56:20 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: bd68fc230762285849207e7e120aaf87cd4ca2f9 |
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.
Intent
Fix a real misclassification of Gemini errors in the Wizard. It was also the cause of the intermittent
generation_model_client_testfailures in CI (#129 and #132 each failed once on it today).Root cause
googleai_dartstamps every request withgenerateRequestId()='req_${DateTime.now().millisecondsSinceEpoch}'.ApiException.toString()appends that ID, the request URL, and the latency (403ms). This is unchanged in 13.0.0.ErrorClassifierchecks 401/403/408/504/429 status codes structurally. For everything else, it substring-matched the wholetoString()against patterns that include bare numbers:'429'for rate limits, and'401'/'403'for auth.Fix (
error_classifier.dart)googleai_darterrors (the sealedGoogleAIException) are matched on theirmessage, nottoString(), so the URL, request ID and latency never reach the patterns.\b429\b). A standalone "Error 429:" or "(403)" still matches; digits inside an ID, a timestamp or a duration don't. Word patterns keep substring matching, so their behavior is unchanged.Tests
New deterministic regressions build an
ApiExceptionwith request IDreq_1790401403429and a 403 ms latency. They check that a 400 safety block stays a safety block, a 503 "unavailable" stays unknown, and "API key not valid" is still recognized as authentication from the message. A plain-string case (14290 ms,job 1403) covers whole-number matching.Impacted packages
playground.Commands run
fvm dart analyze --fatal-infosin playground, includingtest_live: no issues.fvm flutter testin playground: 375 passing.generation_model_client_test.dartrun 30 times in a row: 30/30 passing.