#3396: Config: gateway.unhandledRejections (warn|exit)
cli
size: S
Cluster:
Gateway Error Handling Improvements
## Summary
Add a JSON config knob to control unhandled promise rejection behavior in the Gateway/CLI.
## Motivation
Transient network errors (e.g., undici `fetch failed`) can currently terminate the gateway when they surface as unhandled promise rejections. Some operators prefer warn-only behavior to avoid missed replies and restarts.
## Changes
- Add `gateway.unhandledRejections: "warn"|"exit"` to config types + zod schema.
- Wire config into `installUnhandledRejectionHandler({ mode })` in `src/index.ts` and `src/cli/run-main.ts`.
- Extend handler to accept `mode` and skip `process.exit(1)` when `mode="warn"`.
## Default behavior
Unchanged (defaults to `"exit"`).
## Acceptance criteria
- With `gateway.unhandledRejections="warn"`, unhandled rejections are logged but do not terminate the gateway.
- With default config, behavior remains unchanged.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds a new config option `gateway.unhandledRejections` (`"exit" | "warn"`) to control whether the process exits on unhandled promise rejections, wiring it into the CLI and main entrypoint and updating the unhandled-rejection handler to accept a `mode`.
The change lives in the config layer (`src/config/types.gateway.ts`, `src/config/zod-schema.ts`) and is consumed at process startup (`src/index.ts`, `src/cli/run-main.ts`) by passing the configured mode into `src/infra/unhandled-rejections.ts`.
Key issue spotted: `src/index.ts` now imports `loadConfig` twice, which should break compilation. There are also a couple of consistency/cleanup opportunities around reusing `loadConfig()` results and applying the knob to the macOS relay entrypoint if intended.
<h3>Confidence Score: 2/5</h3>
- Not safe to merge as-is due to a compile-time error in the main entrypoint.
- `src/index.ts` introduces a duplicate import of `loadConfig`, which should cause a TypeScript/ESM duplicate-identifier error at build time. The functional change itself is small and localized, but the entrypoint break is critical. Minor follow-ups include avoiding repeated `loadConfig()` calls in CLI startup and deciding whether the macOS relay should honor the new config knob for consistency.
- src/index.ts; src/cli/run-main.ts; src/macos/relay.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
#10034: Don't crash gateway on transient unhandled fetch failures
by gigq · 2026-02-06
84.6%
#5823: fix(config): exit cleanly on invalid config instead of high CPU loop
by gavinbmoore · 2026-02-01
79.1%
#11101: fix: handle AbortError and WebSocket 1006 in unhandled rejection ha...
by Nipurn123 · 2026-02-07
77.4%
#4653: fix(gateway): improve crash resilience for mDNS and network errors
by AyedAlmudarra · 2026-01-30
76.6%
#12656: fix: install unhandled rejection handler before async boot operations
by kiranirabatti · 2026-02-09
76.4%
#11455: fix(gateway): default gateway.mode to local when unset
by AnonO6 · 2026-02-07
75.9%
#14395: feat: add gateway.nodes.execEvents config to control exec completio...
by dan3093 · 2026-02-12
75.7%
#12234: gateway: incident tracking, recover command, and ciao ERR_SERVER_CL...
by levineam · 2026-02-09
75.3%
#8260: fix(macOS): gateway readiness detection + reversible Configure later
by xksteven · 2026-02-03
75.3%
#19020: bugfix(gateway): Handle invalid model provider API config gracefully\…
by funkyjonx · 2026-02-17
74.9%