#3859: fix(macOS): keep Not configured from snapping back to remote (AI-assisted)
app: macos
Cluster:
Gateway and macOS Improvements
AI-assisted: yes
Testing: fully tested locally
## What & Why
Bug: From Remote mode, switching **Moltbot runs → Not configured** immediately snapped back to Remote.
Cause: `gateway.mode` was removed, but a stale `gateway.remote.url` remained. On reload, the app treated "mode unset + remote url present" as Remote.
## Fix
When `connectionMode == .unconfigured`, clear `gateway.remote.url` during config sync so the app does not implicitly re-select Remote mode.
## Test plan
- ./scripts/restart-mac.sh --no-sign
- cd apps/macos && swift build
- Verified the picker stays on **Not configured** after switching from Remote.
## Notes
- I understand this change clears `gateway.remote.url` when selecting "Not configured".
---
*Rebased from #2628 to resolve merge conflicts*
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adjusts macOS config sync to avoid the UI snapping back to Remote after selecting **Not configured**. In `AppState.syncGatewayConfigIfNeeded`, when `connectionMode == .unconfigured` it now clears the persisted `gateway.remote.url` key so that `applyConfigOverrides` won’t infer `.remote` on reload when `gateway.mode` is absent but a stale remote URL remains.
Change is localized to macOS app state/config persistence logic (`apps/macos/Sources/Moltbot/AppState.swift`) and aligns with existing behavior where `gateway.mode` is removed when unconfigured.
<h3>Confidence Score: 4/5</h3>
- This PR looks safe to merge with low risk; it’s a small, targeted config-write change.
- The change is localized to the unconfigured branch of config syncing and only removes a single persisted key (`gateway.remote.url`) to prevent unintended mode inference. No API surface changes and minimal control-flow impact; main risk is whether other components relied on the URL being preserved while unconfigured.
- apps/macos/Sources/Moltbot/AppState.swift
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#8260: fix(macOS): gateway readiness detection + reversible Configure later
by xksteven · 2026-02-03
76.7%
#21124: fix(config): preserve missing keys from original in restoreRedacted...
by Marvae · 2026-02-19
75.0%
#6770: fix(gateway): protect host-local transport fields from config.patch
by ryx2 · 2026-02-02
75.0%
#11455: fix(gateway): default gateway.mode to local when unset
by AnonO6 · 2026-02-07
73.1%
#10744: fix: update stale MoltbotProtocol paths to OpenClawProtocol
by marezgui · 2026-02-06
72.6%
#19088: fix(gateway): allow startup with unset mode and fix pairing for local…
by mdanassaif · 2026-02-17
72.4%
#11208: fix(config): prevent __OPENCLAW_REDACTED__ corruption on config writes
by janckerchen · 2026-02-07
72.3%
#2530: fix(gateway): improve auth error for native apps
by Episkey-G · 2026-01-27
72.0%
#20272: fix: LaunchAgent KeepAlive causes restart loop (fixes #20257)
by MisterGuy420 · 2026-02-18
71.9%
#4109: fix(cli): bypass config guard for tui --url
by hopenjin · 2026-01-29
71.5%