Skip to content

fix(agent): make buildHttpClient failures actionable (#823) - #919

Open
Sagethepeak wants to merge 1 commit into
Stellar-Ecosystem:mainfrom
Sagethepeak:fix/823-buildHttpClient-actionable
Open

fix(agent): make buildHttpClient failures actionable (#823)#919
Sagethepeak wants to merge 1 commit into
Stellar-Ecosystem:mainfrom
Sagethepeak:fix/823-buildHttpClient-actionable

Conversation

@Sagethepeak

Copy link
Copy Markdown

Fixes #823

Problem

buildHttpClient at agent/agent.js:248 failed without distinguishing transient (retryable network) vs permanent (config) causes, leaving operator unable to tell whether to retry or fix config in unattended runs.

Solution

  • Classify via HttpClientError (kind: transient|permanent) + classifyHttpClientError() (AbortError/timeout/ETIMEDOUT/ECONNREFUSED/ENOTFOUND/EAI_AGAIN/fetch failed/5xx/429 → transient; default permanent to avoid retry storms)
  • Wrap each step (loadSecretcreateSignercreateSchemecreateClient) so error carries operation (buildHttpClient.loadSecret etc.) and safeInputs (rpcUrl, network, secretSource/filePath — never secret)
  • Log actionable http_client_init_failed at warn (transient) vs error (permanent) with operation, kind, code (HTTP_CLIENT_TRANSIENT|PERMANENT), safeInputs, cause
  • Exit codes differ 75 EX_TEMPFAIL (transient, supervisor should restart) vs 78 EX_CONFIG (permanent, fix config) — distinct from generic 1 crash; wired in main() via lazy getHttpClient() and in entry guard main().catch
  • Preserve backwards compat: lazy singleton + eager proxy fallback so imports don't crash before main()

Acceptance

  • Transient vs permanent distinguished
  • Log lines name failing operation + inputs (safe)
  • Exit codes differ by class (75 vs 78), tested: agent:test 50/50

Verification

cd agent && npm test → 50 passed
Manual: classifyHttpClientError(new DOMException(..., 'AbortError')) === 'transient', permanent default for config errors

Where

agent/agent.js — new EXIT_CODE, HttpClientError, classifyHttpClientError, logHttpClientFailure, refactored buildHttpClient, getHttpClient lazy init, main() handling

…em#823)

- Classify errors as transient vs permanent (HttpClientError + classifyHttpClientError)
- Wrap each sub-operation (loadSecret/createSigner/createScheme/createClient) so logs name the failing operation and safe inputs (rpcUrl, network, secretSource) without leaking secret
- Log with event http_client_init_failed at warn (transient) / error (permanent) with operation, kind, code, safeInputs and cause
- Exit with distinct codes 75 (EX_TEMPFAIL, retryable) vs 78 (EX_CONFIG, fix config) so supervisor can decide to restart; main() now defers construction via getHttpClient() and handles top-level crash in entry guard
- Lazy singleton preserves backwards compat; eager fallback proxied to avoid import-time crash in tests
@drips-wave

drips-wave Bot commented Aug 30, 2026

Copy link
Copy Markdown

@Sagethepeak Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 122ef002-8437-4ef2-a14c-32f4d685bb0a


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Agent: make failures in buildHttpClient actionable

1 participant