Repository navigation
fix(ble): resume Limitless recording after network-only reconnect - #7842
Conversation
When the Limitless pendant is recording and the server WebSocket drops (network gone, BLE stays up), the device stops emitting BLE audio after its internal timeout. The app's keep-alive timer reconnects the socket but never re-sends the enable-data-stream command, so no audio flows to the new socket. The UI stays on deviceRecord giving no hint, and the only recovery is force-closing the app or disconnecting BT. This is the network-side counterpart of the BT reconnect fix (BasedHardware#7725). That fix added _handleTransportReconnected() which re-sends the command after a BLE drop. We apply the same treatment for network-only drops. Add onNetworkSocketReconnected() as a no-op virtual hook on DeviceConnection. LimitlessDeviceConnection overrides it to call _reinitializeAfterReconnect() (re-sends enable-data-stream, same as the BT path). In CaptureProvider, _socketReconnectPending is set in onClosed() when the socket drops during deviceRecord state, and consumed in _initiateWebsocket() after a successful reconnect — guarded by recordingState == deviceRecord so it is skipped when the user has paused (no point waking the device when _bleBytesStream is cancelled). _cleanupCurrentState() clears the flag on explicit stop so it does not carry over into the next session. Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Greptile SummaryThis PR fixes a network-only Limitless pendant recording outage by adding a
Confidence Score: 4/5Safe to merge for the primary fix. The two observations (concurrent reinit bypass and no-retry after failed BLE write) represent edge-case hardening gaps rather than broken behavior in the intended network-only outage scenario. The core flag wiring and state-guard logic in CaptureProvider is sound — set on socket close during device recording, cleared on cleanup, consumed only when both the flag and the deviceRecord state agree. The LimitlessDeviceConnection override is simple and delegates to the well-tested _reinitializeAfterReconnect(). The two observations are narrow edge cases (simultaneous BT+network recovery, and a BLE write failure during reinit) that don't affect the main fix path and match the existing BT-reconnect behavior. app/lib/services/devices/limitless_connection.dart — the new onNetworkSocketReconnected() override bypasses the _isReinitializing serialization guard used by the BT-reconnect path. Important Files Changed
Sequence DiagramsequenceDiagram
participant App as CaptureProvider
participant KA as KeepAlive Timer
participant Sock as TranscriptSocket
participant Dev as DeviceService
participant LC as LimitlessDeviceConnection
Note over App,LC: Normal recording (recordingState = deviceRecord)
Sock-->>App: onClosed() [network drop]
App->>App: "_socketReconnectPending = true"
loop Every 15s
KA->>App: keep-alive tick
App->>Sock: _initiateWebsocket()
Sock-->>App: socket connected
App->>App: "check _socketReconnectPending && deviceRecord"
App->>App: "_socketReconnectPending = false"
App->>Dev: ensureConnection(_recordingDevice.id)
Dev-->>App: conn (BLE still connected)
App->>LC: conn.onNetworkSocketReconnected()
LC->>LC: _reinitializeAfterReconnect()
LC->>LC: writeCharacteristic(enable-data-stream)
Note over LC: Pendant resumes BLE audio stream
end
Note over App,LC: Explicit stop
App->>App: _cleanupCurrentState()
App->>App: "_socketReconnectPending = false"
Reviews (1): Last reviewed commit: "fix(ble): resume Limitless recording aft..." | Re-trigger Greptile |
| @override | ||
| Future<void> onNetworkSocketReconnected() async { | ||
| // The Limitless pendant stops streaming BLE audio after an extended period | ||
| // without a live server connection. Re-send the enable-data-stream command | ||
| // so it resumes, just as _reinitializeAfterReconnect() does after BT reconnect. | ||
| await _reinitializeAfterReconnect(); | ||
| } |
There was a problem hiding this comment.
Missing
_isReinitializing guard — duplicate concurrent writes possible
_handleTransportReconnected() serializes BT-reconnect reinit calls via _isReinitializing / _pendingReinit to prevent two concurrent writeCharacteristic calls from racing. onNetworkSocketReconnected() calls _reinitializeAfterReconnect() directly, bypassing that guard entirely.
If a BT transport reconnect fires while onNetworkSocketReconnected() is already awaiting the BLE write (e.g., network recovers just before BLE finishes cycling), both paths call _reinitializeAfterReconnect() simultaneously. The pendant receives two back-to-back enable-data-stream commands; whether this causes a stutter or is silently idempotent depends on firmware behavior. Routing through the same serialization used by _handleTransportReconnected() would prevent this ambiguity.
| if (_socketReconnectPending && _recordingDevice != null && recordingState == RecordingState.deviceRecord) { | ||
| _socketReconnectPending = false; | ||
| final conn = await ServiceManager.instance().device.ensureConnection(_recordingDevice!.id); | ||
| await conn?.onNetworkSocketReconnected(); | ||
| } |
There was a problem hiding this comment.
_socketReconnectPending cleared before reinit completes — silent no-retry on BLE write failure
_socketReconnectPending is set to false before ensureConnection and onNetworkSocketReconnected() are awaited. If the BLE write inside _reinitializeAfterReconnect() throws (transport error, pendant busy), the error is swallowed and the flag is already gone, so no further keep-alive cycle will retry. The pendant stays silent without any indication. The BT-reconnect path has the same no-retry characteristic, so this is consistent, but it's worth confirming the pendant's error-recovery on failed enable-data-stream writes is robust enough.
kodjima33
left a comment
There was a problem hiding this comment.
Good BLE reconnect fix with clear root cause; lint check failing — fix to land
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Formatting fix pushed. Good to go. |
kodjima33
left a comment
There was a problem hiding this comment.
Mobile BLE bug fix: resume Limitless recording after network-only reconnect; clear root cause, mirrors existing reconnect path.
Problem
When the Limitless pendant is recording and the network drops entirely (Bluetooth stays connected), the pendant silently stops streaming BLE audio after its internal timeout elapses. When the network comes back, the app's keep-alive timer successfully reconnects the transcription WebSocket, but no audio flows — the pendant is no longer emitting frames. The UI continues to show
deviceRecord, giving no indication that transcription has stopped. The only recovery is force-closing the app or disconnecting/reconnecting Bluetooth.This is the network-side analog of #7725 (BT reconnect fix). That fix added
_handleTransportReconnected()to re-send theenable-data-streamcommand after a BLE drop. This PR does the same for network-only drops.Fixes #7841
Root Cause
_initiateWebsocket()inCaptureProviderhas no way to notify the active device connection that the socket has recovered. After reconnecting the socket, the_bleBytesStreampipeline is live and waiting, but the Limitless pendant stopped producing BLE audio frames while the socket was dead. Nobody re-sent the enable-data-stream command.CaptureProvider.onConnected()is the natural hook, but it is unreachable from the keep-alive reconnect path:subscribe()is called afterstart()completes (socket already connected), so theonConnectedevent fires on an empty listeners map and never reachesCaptureProvider. Even if it did, it only handles theinterruptedstate (phone mic).Solution
Add
onNetworkSocketReconnected()as a virtual hook onDeviceConnection(no-op default).LimitlessDeviceConnectionoverrides it to call_reinitializeAfterReconnect()— the same enable-data-stream command used by the BT reconnect fix.A
_socketReconnectPendingboolean inCaptureProvidergates the call:onClosed()whenrecordingState == deviceRecord(socket dropped during active device recording)_initiateWebsocket()after successful reconnect, guarded byrecordingState == deviceRecord(skipped if the user paused between the drop and the reconnect)_cleanupCurrentState()on explicit stop so it does not carry over into the next sessionExplicit socket stops call
TranscriptSegmentSocketService.stop()which clears listeners before the async close fires, soCaptureProvider.onClosed()is never reached from those paths — the flag is never set spuriously.Changes
device_connection.dart—onNetworkSocketReconnected()no-op hook on the base class; all existing device types unaffectedlimitless_connection.dart— override calls_reinitializeAfterReconnect()(re-sends enable-data-stream)capture_provider.dart—_socketReconnectPendingflag wiring inonClosed(),_cleanupCurrentState(), and_initiateWebsocket()Note: the diff also includes formatter-only normalizations in
capture_provider.dartanddevice_connection.dartproduced by the pre-commit hook (dart format --line-length 120). No logic is changed in those lines.Testing
Verified on hardware (Limitless pendant on iOS):
Regression verified:
_handleTransportReconnected()path unchanged) ✅_cleanupCurrentState()) ✅deviceRecordguard prevents reinit while paused) ✅