Skip to content

fix(gateway): classify wrapped "fetch failed" messages as transient network errors#38530

Merged
Takhoffman merged 4 commits intoopenclaw:mainfrom
xinhuagu:fix/transient-wrapped-fetch-failed
Mar 7, 2026
Merged

fix(gateway): classify wrapped "fetch failed" messages as transient network errors#38530
Takhoffman merged 4 commits intoopenclaw:mainfrom
xinhuagu:fix/transient-wrapped-fetch-failed

Conversation

@xinhuagu
Copy link
Copy Markdown
Contributor

@xinhuagu xinhuagu commented Mar 7, 2026

Problem

When Discord's ProxyGatewayPlugin wraps a fetch failure into a higher-level error like:

Failed to get gateway information from Discord: fetch failed

the previous exact-match check (message === "fetch failed") missed it. The error was not classified as transient, so the unhandled rejection handler called process.exit(1), crashing the entire gateway instead of just the Discord provider.

Closes #38510

Fix

  • Add "fetch failed" to TRANSIENT_NETWORK_MESSAGE_SNIPPETS so the existing substring matching catches both bare and wrapped forms
  • Remove the now-redundant exact-match checks (TypeError instance check and message === "fetch failed")

This is a strict superset of the previous behavior — all previously matched errors still match, plus wrapped variants like the Discord gateway error.

Testing

  • All 39 existing tests pass
  • Added a test case for the wrapped Discord gateway error in the fatal-detection test suite

@Takhoffman Takhoffman self-assigned this Mar 7, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 11fa4e98c7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/infra/unhandled-rejections.ts Outdated
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 7, 2026

Greptile Summary

This PR fixes a gateway crash caused by ProxyGatewayPlugin wrapping the bare "fetch failed" Fetch API error into a higher-level message (e.g. "Failed to get gateway information from Discord: fetch failed"), which the old exact-match check missed, leading to process.exit(1). The fix adds "fetch failed" to TRANSIENT_NETWORK_MESSAGE_SNIPPETS so the existing case-insensitive substring logic catches both bare and wrapped forms, and removes the now-redundant exact-match checks.

Key changes:

  • "fetch failed" added to TRANSIENT_NETWORK_MESSAGE_SNIPPETS; the two prior exact-match checks (instanceof TypeError && message === "fetch failed" and standalone message === "fetch failed") are removed as they are now strictly subsumed
  • SSL/TLS error codes (EPROTO, ERR_SSL_WRONG_VERSION_NUMBER, ERR_SSL_PROTOCOL_RETURNED_AN_ERROR) and message snippets (tlsv1 alert, ssl routines, packet length too long, write eproto) are bundled in the same change
  • A test case for the wrapped Discord error is added to the transient-cases suite

The solution is straightforward: substring matching with "fetch failed" is a strict superset of the old exact-match logic. All 39 existing tests pass, and a new test for the reported scenario is included.

Confidence Score: 5/5

  • Safe to merge. The fix is logically sound, all 39 existing tests pass, and the reported scenario is now covered by a new test.
  • The change is a straightforward fix that strictly extends the previous behavior to catch wrapped error messages. The substring matching correctly handles both bare "fetch failed" errors and wrapped variants like "Failed to get gateway information from Discord: fetch failed". The implementation removes redundant exact-match checks that are now subsumed by the broader snippet matching. Test coverage is comprehensive with both existing test suites passing and new tests added for the reported scenario. No functional issues or regressions identified.
  • No files require special attention.

Last reviewed commit: 11fa4e9

xinhuagu and others added 4 commits March 6, 2026 21:39
…etwork errors

When Discord wraps a fetch failure into a higher-level error like
"Failed to get gateway information from Discord: fetch failed",
the previous exact-match check (message === "fetch failed") missed it,
causing the gateway to crash instead of continuing.

Move "fetch failed" into TRANSIENT_NETWORK_MESSAGE_SNIPPETS so substring
matching catches both bare and wrapped forms. Remove the now-redundant
exact-match checks for TypeError("fetch failed") and message === "fetch failed".

Closes openclaw#38510
@Takhoffman Takhoffman force-pushed the fix/transient-wrapped-fetch-failed branch from 11fa4e9 to 91ffeae Compare March 7, 2026 03:46
@Takhoffman Takhoffman merged commit 1a022a3 into openclaw:main Mar 7, 2026
27 of 28 checks passed
@Takhoffman
Copy link
Copy Markdown
Contributor

PR #38530 - fix(gateway): classify wrapped "fetch failed" messages as transient network errors (#38530)

Merged after verification.

  • Merge commit: 1a022a3
  • Verified: pnpm build, pnpm check, pnpm test:macmini
  • Autoland updates:
    M CHANGELOG.md
    M src/infra/unhandled-rejections.ts
    M src/infra/unhandled-rejections.test.ts
    M src/infra/unhandled-rejections.fatal-detection.test.ts
  • Rationale:
    Addressed open review thread by narrowing fetch-failed matching to transport-oriented wrapped suffixes, added positive/negative regressions, and fixed TS typing in fatal-detection transient test cases.
  • Changelog: CHANGELOG.md updated=true required=true opt_out=false

joshavant pushed a commit that referenced this pull request Mar 7, 2026
…etwork errors (#38530)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: xinhuagu <562450+xinhuagu@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
vincentkoc pushed a commit to BryanTegomoh/openclaw-upstream that referenced this pull request Mar 8, 2026
…etwork errors (openclaw#38530)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: xinhuagu <562450+xinhuagu@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
jenawant pushed a commit to jenawant/openclaw that referenced this pull request Mar 10, 2026
…etwork errors (openclaw#38530)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: xinhuagu <562450+xinhuagu@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
V-Gutierrez pushed a commit to V-Gutierrez/openclaw-vendor that referenced this pull request Mar 17, 2026
…etwork errors (openclaw#38530)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: xinhuagu <562450+xinhuagu@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 20, 2026
…etwork errors (openclaw#38530)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: xinhuagu <562450+xinhuagu@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
(cherry picked from commit 1a022a3)
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 20, 2026
…etwork errors (openclaw#38530)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: xinhuagu <562450+xinhuagu@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
(cherry picked from commit 1a022a3)
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…etwork errors (openclaw#38530)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: xinhuagu <562450+xinhuagu@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…etwork errors (openclaw#38530)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: xinhuagu <562450+xinhuagu@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
…etwork errors (openclaw#38530)

Verified:
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: xinhuagu <562450+xinhuagu@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Gateway crashes on Discord client re-init after wrapped fetch/TLS error

2 participants