← Back to PRs

#3396: Config: gateway.unhandledRejections (warn|exit)

by diegoaledesma open 2026-01-28 15:05 View on GitHub →
cli size: S
## 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