Skip to content

fix(brain): match status words, not bare 401/429 digits, in the error fallback - #862

Merged
vladimirrott merged 4 commits into
lacs-project:mainfrom
mateuscmtropical:fix/status-digits-fallback
Nov 26, 2026
Merged

vladimirrott merged 4 commits into
lacs-project:mainfrom
mateuscmtropical:fix/status-digits-fallback

Conversation

@mateuscmtropical

Copy link
Copy Markdown
Contributor

Summary

When a provider error has no structured HTTP status, both adapters matched a bare 401 or 429 anywhere in the message. A response body that fails to decode lands in the message whole, and its created timestamp can hold those digits. A serde position like column 401 does too. Both came back as Auth (not retryable, "check your API key") when the key was fine.

classify_status_words in providers/mod.rs now 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 to Auth through the word. The structured classify_status path and sanitize_error_msg are unchanged.

Related Issue

Closes #858

Validation

  • Tests added or updated
  • Documentation updated if behavior changed
  • Security impact considered
  • Trust boundary preserved (daemon remains the only privileged executor)
  • CI passes
  • Every commit is signed off (git commit -s, see CONTRIBUTING.md)

New tests, all red before the fix:

  • OpenAI: JSONDeserialize with a body whose created is 1764014012 (contains 401) and 1764291234 (contains 429). Both map to Request.
  • rig: JsonError from serde at column 401 and column 429. Both map to Request.
  • map_rig_error_falls_back_to_substring_when_no_structured_status stays green.

Ran in a rust:1 container:

  • cargo fmt --all -- --check and cargo clippy -p sysknife-brain --all-targets -- -D warnings: clean.
  • cargo test -p sysknife-brain: 301 + 83 passed. Without USER set in the container, state_client::tests::current_user_returns_non_empty_string_in_normal_env fails, which has nothing to do with this change.

Notes for Reviewers

None.

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 vladimirrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@vladimirrott
vladimirrott merged commit bcad200 into lacs-project:main Nov 26, 2026
15 checks passed
@vladimirrott

vladimirrott commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Merged as bcad200. Thank you for tracing the error path through the adapters.

@vladimirrott vladimirrott mentioned this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A provider error that merely contains 401 or 429 is reported as a bad API key or a rate limit

2 participants