Files
hermes-agent/agent/errors.py
kshitijk4poor 3425329bc7 fix(classifier): carry the auxiliary-only error phrasings and shape facts
The auxiliary client decides retry/fallback with private substring
predicates while the main loop uses classify_api_error. Before the aux
decisions can move onto the shared classifier, the classifier has to know
what the aux predicates know. This commit adds those phrasings to the
classifier's pattern tables and records the shape facts the aux recovery
paths branch on. Aux decisions still use their predicates here; the
switch follows in the next commit.

Phrasings (only those the aux predicates already matched; the bare
"billing" substring is not carried):
- an account wall (credits, budget/spending/key limits, subscription and
  upgrade walls, quota windows, RESOURCE_EXHAUSTED) on a 403 or 404, and
  "insufficient funds" / "can only afford" -> billing; a 404 "isn't
  available on the free tier" -> billing
- a 429 or status-less body naming a daily/weekly window with no reset
  signal -> billing; a bare RESOURCE_EXHAUSTED or per-minute quota stays
  a rate limit, and a 429 that says rate limit outranks a billing phrase
- xAI "unauthenticated:bad-credentials", a status-less "Error code: 401"
  and a status-less *AuthenticationError class -> auth that rotates
- "OpenRouter catalog" -> model_not_found
- account gating of the model itself ("model X is not supported for/when
  using this account") -> model_entitlement; a feature or parameter
  named first, and wall wording, are excluded
- "response ended prematurely", protocol-error text and a status-less
  SDK transport class by name (Connection/Timeout/DNS/SSL) -> transport
- botocore ClientError and httpx.HTTPStatusError statuses are read from
  their response objects
- InvalidProviderResponseError (new, agent/errors.py), an HTTP-200
  answer with no usable choices -> incomplete_response

Shape facts in error_context: transport ("timeout" | "connection"; a
connection or disconnect phrase sets it behind an HTTP status too, e.g.
a relay's 502 "connection reset by peer") and statusless_structured on
every verdict (keyed on the exception carrying no HTTP status, so an SSE
error body whose numeric code reads as a status still counts); quota_exhausted and route_rejects_model on built-in
verdicts only (a plugin or profile verdict is authoritative), which set
hook_declines_fallback instead when they say should_fallback=False. The
main loop reads none of them.

Tests: tests/agent/test_error_classifier_aux_phrasings.py, one table row
per phrasing and shape fact.

Part of the Code Health plan.
2026-11-08 13:18:54 +05:30

12 lines
485 B
Python

class EmptyStreamError(RuntimeError):
"""Raised when a provider closes a stream without yielding a response."""
class MoAPresetNotFoundError(ValueError):
"""Raised when a persisted MoA preset no longer exists in config."""
class InvalidProviderResponseError(RuntimeError):
"""An HTTP-200 answer with no usable ``choices[0].message``: the route cannot answer this request.
The provider's own ``error`` object, when the body carried one, rides ``provider_error``."""