#19088: fix(gateway): allow startup with unset mode and fix pairing for local…
cli
size: XS
Cluster:
Device Pairing and Gateway Fixes
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
#22280: fix(gateway): silently auto-approve local paired-device scope upgrades
by abhishekp76 · 2026-02-21
85.4%
#22712: fix(gateway): auto-approve all device pairing for localhost connect...
by NewdlDewdl · 2026-02-21
83.9%
#3744: Gateway: fix device pairing when local connection retries with exis...
by photon3710 · 2026-01-29
83.5%
#11455: fix(gateway): default gateway.mode to local when unset
by AnonO6 · 2026-02-07
83.2%
#21651: fix(gateway): token fallback + operator.admin scope superset in pai...
by lan17 · 2026-02-20
82.6%
#23503: fix: preserve pairing state on device token mismatch + migrate lega...
by dorukardahan · 2026-02-22
82.6%
#16310: fix(ws-connection): skip device pairing when client authenticates w...
by nawinsharma · 2026-02-14
82.3%
#21148: fix(gateway): add request-aware pairing recovery hints and docs
by cluster2600 · 2026-02-19
81.9%
#17425: fix(gateway): auto-approve scope/role upgrades for already-paired d...
by sauerdaniel · 2026-02-15
81.6%
#22262: fix(gateway): add pairing-repair command hint on 1008 connect failures
by karimnaguib · 2026-02-20
81.4%