Repository navigation
fix(brain): match status words, not bare 401/429 digits, in the error fallback - #862
Conversation
… fallback Signed-off-by: mateuscmtropical <[email protected]>
One table test covers the whole-word match on both sides of the phrase, the too many requests phrase, case folding and the bare-digit rule. Without it the boundary check and the RateLimit phrase could be removed with the brain suite still green. Signed-off-by: Vladimir Rotariu <[email protected]>
The four new status tests and the word-boundary table test move the count from 2177 to 2182. Signed-off-by: Vladimir Rotariu <[email protected]>
Keep 2182 as the workspace test count: main holds 2177 and this branch adds five tests. Signed-off-by: Vladimir Rotariu <[email protected]>
vladimirrott
left a comment
There was a problem hiding this comment.
Thanks for this one.
You built the failing errors in process, one per adapter, with the exact digits the issue named, and you left classify_status, sanitize_error_msg and the "401 unauthorized from grpc" test alone. Every offset in contains_words comes from the lowercased string it slices, so a non-ASCII message cannot misalign it.
I checked 5a25939 in a container with no network:
- Your four new tests pass. When I put the bare contains("401") or contains("429") back into one adapter, the matching new test goes red and no other test does. When I put them back into classify_status_words, both tests for that status go red.
- The whole sysknife-brain suite passes: 384 tests, your 301 + 83.
- I sent 38 inputs through classify_status_words: the phrase at the start and end of the string, "unauthorizedly", "reauthorized", "unauthorized_access", uppercase, "İ" before the phrase, double spaces. All 38 matched what I expected. None of 40,000 random strings made it panic.
One thing was missing: nothing tested the boundary check in contains_words. I deleted the check before the phrase, the check after it, and both together, and the suite stayed green each time, and "too many requests" could stop matching without a red test. I added the table test myself on your branch (a_status_phrase_inside_a_longer_word_is_not_a_status, in providers/mod.rs). It checks that "401 Unauthorized" gives Auth, "429 Too Many Requests" gives RateLimit, and that "unauthorizedly", "reauthorized" and bare digits give None. Each of the four mutants now turns exactly that test red.
I also took care of the two red checks, so neither is your debt. The test count moved to 2182 (main's 2177 plus your four tests plus the new one), and I pushed that to tests/evidence/workspace-tests.json. The branch had a conflict on that line with #861, which I resolved in a merge commit. The security-audit failure came from cookie 0.18.1 and url 2.5.8 in the lockfile your branch started from, and the merge brings in main's fix. All of it carries a sign-off.
Optional, here or in a later PR: three mutants still survive. They are the OpenAI Auth arm, the OpenAI RateLimit arm and the rig RateLimit arm. A JSONDeserialize body that says "429 Too Many Requests" and a rig ProviderError that says the same would catch the last two, and a body that says "401 Unauthorized" the first. The OpenAI test helper could also assert that the rendered message contains the digits, as your rig helper does for the column, so the test fails if async-openai stops echoing the body.
A note on the tradeoff, so you know I checked it. Once bare digits stop counting, a status that arrives without a reason phrase falls through to Request. I measured it. With OPENAI_BASE_URL pointed at an nginx basic-auth page ("401 Authorization Required") or an Azure API Management body ("statusCode": 401), the OpenAI adapter used to say Auth and now says Request, which the planner retries twice before it shows the body. I accept that for #858. The default OpenAI endpoint and every rig provider report the status as a structured value, and your "column 401" test cannot pass if a bare 401 still counts. The same change fixes a case the digits missed: vLLM's {"error":"Unauthorized"} now reads as Auth.
I will merge once the board is green. You have nothing to rebase or push.
|
Merged as bcad200. Thank you for tracing the error path through the adapters. |
Summary
When a provider error has no structured HTTP status, both adapters matched a bare
401or429anywhere in the message. A response body that fails to decode lands in the message whole, and itscreatedtimestamp can hold those digits. A serde position likecolumn 401does too. Both came back asAuth(not retryable, "check your API key") when the key was fine.classify_status_wordsinproviders/mod.rsnow reads the reason phrase as whole words (unauthorized,too many requests) and both adapters use it in place of the bare digits."401 unauthorized from grpc"still maps toAuththrough the word. The structuredclassify_statuspath andsanitize_error_msgare unchanged.Related Issue
Closes #858
Validation
git commit -s, see CONTRIBUTING.md)New tests, all red before the fix:
JSONDeserializewith a body whosecreatedis1764014012(contains401) and1764291234(contains429). Both map toRequest.JsonErrorfrom serde at column 401 and column 429. Both map toRequest.map_rig_error_falls_back_to_substring_when_no_structured_statusstays green.Ran in a
rust:1container:cargo fmt --all -- --checkandcargo clippy -p sysknife-brain --all-targets -- -D warnings: clean.cargo test -p sysknife-brain: 301 + 83 passed. WithoutUSERset in the container,state_client::tests::current_user_returns_non_empty_string_in_normal_envfails, which has nothing to do with this change.Notes for Reviewers
None.