Skip to content

fix(agent): walk cause chain when extracting wrapped API error bodies (salvage of #14287 by @LeonSGP43) - #53582

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-7ce5d388
Jun 27, 2026
Merged

teknium1 merged 1 commit into
mainfrom
hermes/hermes-7ce5d388

Conversation

@teknium1

Copy link
Copy Markdown
Collaborator

Summary

Wrapped API errors now keep the nested body message, so transient 402 usage limits classify as rate_limit (retryable) instead of being misread as terminal billing failures.

Root cause: classify_api_error() extracted the status code via _extract_status_code() (which walks __cause__/__context__) but the body via _extract_error_body() (which only inspected the top-level exception). A wrapped 402 kept the nested status code but lost the nested "try again in 5 minutes" body, so _classify_402() saw no transient signal and defaulted to billing/non-retryable.

Changes

  • agent/error_classifier.py: _extract_error_body() now walks the __cause__/__context__ chain (max depth 5), mirroring _extract_status_code().
  • tests/agent/test_error_classifier.py: covers nested-body extraction and the full wrapped-402 → rate_limit classification path.

Validation

Case Before After
Wrapped 402, nested body "Usage limit, try again in 5 min" billing, retryable=False rate_limit, retryable=True
Wrapped 402, nested body "credit balance too low" billing billing (no regression)

Targeted suite: 164/164 pass. E2E verified with real imports against the live classification path.

Salvage of #14287 by @LeonSGP43 (cherry-picked onto current main, authorship preserved). Closes #14195. Duplicates: #14219 (@liuhao1024, first submitter, already closed), #14349 (@sgaofen), #14787 (@Tranquil-Flow).

Infographic

error-classifier-walk-the-cause-chain

@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-7ce5d388 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 11482 on HEAD, 11482 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 6032 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists labels Jun 27, 2026
@teknium1
teknium1 merged commit e7c0134 into main Jun 27, 2026
30 checks passed
@teknium1
teknium1 deleted the hermes/hermes-7ce5d388 branch June 27, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrapped API errors lose nested body details and misclassify transient 402s as billing failures

3 participants