← Back to PRs

#4653: fix(gateway): improve crash resilience for mDNS and network errors

by AyedAlmudarra open 2026-01-30 13:34 View on GitHub →
cli
## Summary Fixes critical gateway stability issues caused by mDNS/Bonjour errors during network interface changes. ## Issues Fixed - Fixes #3821 - Gateway crash loop on mDNS network changes (sleep/wake, WiFi reconnect) - Fixes #3815 - Gateway crashes from unhandled fetch failures - Fixes #4501 - Unhandled promise rejection causing gateway crash ## Changes ### 1. Error Handling (`src/infra/bonjour-ciao.ts`) - Added error patterns for transient mDNS issues - Catches AssertionError from MDNServer ### 2. Network Error Detection (`src/infra/unhandled-rejections.ts`) - Added ERR_ASSERTION to transient network codes - Better detection of mDNS-related assertion errors ### 3. CLI Flag (`src/cli/gateway-cli/run.ts`) - Added `--no-bonjour` flag to disable mDNS advertising ### 4. Tests & Docs - Added unit and integration tests (42 total, all passing) - Updated CHANGELOG.md ## Checklist - [x] Code follows project style - [x] Tests added and passing - [x] CHANGELOG.md updated - [x] No breaking changes <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR improves gateway stability around unhandled promise rejections by (1) broadening transient network error detection to include specific mDNS/Bonjour failures and (2) adding a new `--no-bonjour` CLI flag to disable mDNS advertising. It also adds focused tests (unit + an integration-style suite) to cover the new mDNS error patterns and updates the changelog. The changes fit into the existing crash-resilience layer by extending `src/infra/unhandled-rejections.ts` (which decides whether an unhandled rejection should exit the process) and by adding a dedicated bonjour/ciao rejection handler in `src/infra/bonjour-ciao.ts` that can be registered via the unhandled rejection handler registry. <h3>Confidence Score: 2/5</h3> - This PR is not yet safe to merge due to a likely CLI flag default bug that can disable Bonjour unintentionally. - Most changes are localized and well-tested, but the Commander `--no-bonjour` option appears to be declared with a default that makes it always evaluate to false, which would set `OPENCLAW_DISABLE_BONJOUR=1` even when the user did not pass the flag. Additionally, treating all `ERR_ASSERTION` errors as transient may hide real assertion failures outside the mDNS context. - src/cli/gateway-cli/run.ts, src/infra/unhandled-rejections.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs