#4653: fix(gateway): improve crash resilience for mDNS and network errors
cli
Cluster:
Gateway Resilience and Configuration
## 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
#3831: fix: ignore mDNS socket errors to prevent gateway crashes
by cici1029 · 2026-01-29
88.7%
#12234: gateway: incident tracking, recover command, and ciao ERR_SERVER_CL...
by levineam · 2026-02-09
82.5%
#8260: fix(macOS): gateway readiness detection + reversible Configure later
by xksteven · 2026-02-03
82.1%
#10034: Don't crash gateway on transient unhandled fetch failures
by gigq · 2026-02-06
82.1%
#11455: fix(gateway): default gateway.mode to local when unset
by AnonO6 · 2026-02-07
81.2%
#17257: fix(bonjour): stop mDNS flood on multi-NIC same-LAN setups (#17222)
by yinghaosang · 2026-02-15
80.1%
#19088: fix(gateway): allow startup with unset mode and fix pairing for local…
by mdanassaif · 2026-02-17
80.0%
#11101: fix: handle AbortError and WebSocket 1006 in unhandled rejection ha...
by Nipurn123 · 2026-02-07
79.8%
#14564: fix(gateway): crashes on startup when tailscale meets non-loopback ...
by yinghaosang · 2026-02-12
79.6%
#6466: fix(gateway): add handshake timeout and connection error handling
by jarvis-raven · 2026-02-01
79.1%