fix(ios): force reconnect bypasses disconnected connection guard#6156
Conversation
ensureConnection returned null for the same device when disconnected, even with force=true. This meant user-initiated reconnect taps were silently ignored on iOS where native auto-reconnect left a stale _connection object with the correct device ID but disconnected status.
Greptile SummaryThis PR fixes a silent no-op on iOS when a user manually taps to reconnect a device that is in a stale-disconnected state. The root cause was that Changes:
Confidence Score: 4/5Safe to merge after removing the debug print() statements; the logic fix itself is correct and well-scoped. The one-line guard change is correct and the described iOS scenario is well-reasoned. Score is 4 rather than 5 because six raw app/lib/services/devices.dart — the debug print() statements need to be converted to Logger.debug() or removed Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["ensureConnection(deviceId, force)"] --> B{Same device & connected?}
B -- Yes --> C[return _connection]
B -- No --> D{"!force && same device ID? (stale disconnected)"}
D -- "true (force=false)" --> E[return null - native auto-reconnect handles it]
D -- "false (force=true OR different device)" --> F{force?}
F -- No --> G[return null]
F -- Yes --> H["_connectToDevice(deviceId)"]
H --> I{existing _connection?}
I -- Yes, connected --> J[disconnect + dispose transport]
I -- Yes, disconnected --> K[dispose transport only]
J --> L[_connection = null]
K --> L
I -- No --> M[lookup device]
L --> M
M --> N[DeviceConnectionFactory.create]
N --> O[connect with callback]
O --> P[return _connection]
|
…edHardware#6156) ## Summary - `ensureConnection` returned `null` for the same device when disconnected, even with `force=true` (user-initiated reconnect) - After the first connection + disconnect, the `_connection` object persists with the matching device ID but `disconnected` status - Line 237 (`if (_connection?.device.id == deviceId) return null`) blocks ALL subsequent reconnection attempts regardless of `force` — the `force` flag was never checked on that path - This made user-initiated reconnect taps silently do nothing on iOS (Android was unaffected because `_connection` gets fully cleaned up on disconnect) - Fix: add `!force &&` so `force=true` calls fall through to `_connectToDevice` ## Test plan - [x] iOS: disconnect device manually, tap to reconnect — should reconnect - [x] iOS: device goes out of range and back — native auto-reconnect still works (force=false path unchanged) - [x] Android: no behavioral change expected 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Summary
ensureConnectionreturnednullfor the same device when disconnected, even withforce=true(user-initiated reconnect)_connectionobject persists with the matching device ID butdisconnectedstatusif (_connection?.device.id == deviceId) return null) blocks ALL subsequent reconnection attempts regardless offorce— theforceflag was never checked on that path_connectiongets fully cleaned up on disconnect)!force &&soforce=truecalls fall through to_connectToDeviceTest plan
🤖 Generated with Claude Code