← Back to PRs

#19088: fix(gateway): allow startup with unset mode and fix pairing for local…

by mdanassaif open 2026-02-17 10:46 View on GitHub →
cli size: XS
Two fixes for the gateway crash-loop and "pairing required" disconnection: 1. Gateway startup no longer blocks when gateway.mode is unset (undefined). Previously only "local" was accepted, causing a restart loop on fresh installs or when the mode config was missing. Unset mode now defaults to local behavior, matching the documented default. 2. requestDevicePairing now upgrades the silent flag on an existing pending request when a local client reconnects. Previously, if a non-local connection created a pending request, subsequent localhost connections would inherit silent=false and fail auto-approval, causing repeated "pairing required" (1008) disconnections until the 5-min TTL expired. ## Summary Describe the problem and fix in 2–5 bullets: - Problem: - Why it matters: - What changed: - What did NOT change (scope boundary): ## Change Type (select all) - [ ] Bug fix - [ ] Feature - [ ] Refactor - [ ] Docs - [ ] Security hardening - [ ] Chore/infra ## Scope (select all touched areas) - [ ] Gateway / orchestration - [ ] Skills / tool execution - [ ] Auth / tokens - [ ] Memory / storage - [ ] Integrations - [ ] API / contracts - [ ] UI / DX - [ ] CI/CD / infra <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR fixes two gateway issues: (1) startup crash-loop when `gateway.mode` is unset, and (2) pairing failures for local reconnections. **Changes:** - `src/cli/gateway-cli/run.ts:167`: Modified the startup check to allow `mode === undefined` in addition to `mode === "local"`, preventing startup blocks on fresh installs - `src/infra/device-pairing.ts:233-236`: Added logic to upgrade `silent` flag from `false` to `true` when a local client reconnects to an existing pending pairing request, enabling auto-approval **How it works:** The first fix changes the condition from `mode !== "local"` to `mode !== "local" && mode !== undefined`, allowing the gateway to start when mode is unset (which defaults to local behavior). The second fix addresses a race condition where a non-local connection creates a pending request with `silent=false`, then a local reconnection inherits that flag and fails auto-approval. Now, when `req.silent === true` and `existing.silent !== true`, the existing request is upgraded to `silent=true` and persisted. <h3>Confidence Score: 4/5</h3> - This PR is safe to merge with minimal risk - the changes are focused bug fixes with clear logic - Both fixes are surgical and address specific edge cases. The first fix simply relaxes a validation check to match documented default behavior. The second fix properly handles state updates in a race condition. The changes are well-scoped and unlikely to introduce regressions. However, the lack of test coverage for these specific scenarios (unset mode startup and silent flag upgrading) reduces confidence slightly from a perfect score. - No files require special attention <sub>Last reviewed commit: 1ad8de9</sub> <!-- 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