feat: debounce_timing [android]#21
Merged
choudlet merged 5 commits intoApr 10, 2026
Merged
Conversation
…gration [android] Add network connectivity monitoring to pause HTTP delivery when offline and resume with circuit breaker reset when connectivity returns. This is PR 1 of 2 for the network reachability feature. New: - NetworkMonitor interface + AndroidNetworkMonitor (ConnectivityManager) - CircuitBreaker.reset() for offline->online transitions - Dispatcher.pauseForOffline()/resumeFromOffline() with networkPaused guard - InitOptions.maxOfflineDiskEvents parameter (default 10000) - FakeNetworkMonitor test helper for DI in tests - getDebugInfo() includes "networkStatus": "connected"|"disconnected" Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Online transitions are debounced by 2s before triggering circuit breaker reset and dispatcher flush. Offline transitions remain immediate. Rapid flapping collapses into a single online action once connectivity stabilizes. New DebouncedNetworkHandler class sits between the network monitor callback and dispatcher side-effects. 10 new unit tests cover debounce timing, flapping, cancellation, and cleanup. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
brandon-metarouter
approved these changes
Apr 10, 2026
brandon-metarouter
left a comment
There was a problem hiding this comment.
Pre-approving, left a comment abount consolidating some cancels, but just a nit.
Comment on lines
+26
to
+43
| fun onConnectivityChanged(connected: Boolean) { | ||
| if (connected) { | ||
| // Online: debounce — only act after connectivity is stable for 2s | ||
| debounceJob?.cancel() | ||
| Logger.log("Network connectivity detected — debouncing for stability") | ||
| debounceJob = scope.launch { | ||
| delay(DEBOUNCE_MS) | ||
| Logger.log("Network connectivity stable — resuming dispatcher") | ||
| onOnline() | ||
| } | ||
| } else { | ||
| // Offline: act immediately, cancel any pending online debounce | ||
| debounceJob?.cancel() | ||
| debounceJob = null | ||
| Logger.log("Network connectivity lost — pausing HTTP delivery") | ||
| onOffline() | ||
| } | ||
| } |
There was a problem hiding this comment.
So debounceJob?.cancel() is called in both if and else, maybe extract it and move it up? Also maybe just call in the cancel method instead? Note: I don't think it is a biggie or breaks anything if you call cancel() and it debounceJob = null... you reassign it in the if block anyway.
fun onConnectivityChanged(connected: Boolean) {
cancel()
if (connected) {
...
} else {
....
}
}
choudlet
added a commit
that referenced
this pull request
Apr 10, 2026
* feat: network reachability awareness — core monitor + dispatcher integration [android] Add network connectivity monitoring to pause HTTP delivery when offline and resume with circuit breaker reset when connectivity returns. This is PR 1 of 2 for the network reachability feature. New: - NetworkMonitor interface + AndroidNetworkMonitor (ConnectivityManager) - CircuitBreaker.reset() for offline->online transitions - Dispatcher.pauseForOffline()/resumeFromOffline() with networkPaused guard - InitOptions.maxOfflineDiskEvents parameter (default 10000) - FakeNetworkMonitor test helper for DI in tests - getDebugInfo() includes "networkStatus": "connected"|"disconnected" * fix: @volatile on callback + listener fields * feat: debounce network reachability online transitions (2s) Online transitions are debounced by 2s before triggering circuit breaker reset and dispatcher flush. Offline transitions remain immediate. Rapid flapping collapses into a single online action once connectivity stabilizes. New DebouncedNetworkHandler class sits between the network monitor callback and dispatcher side-effects. 10 new unit tests cover debounce timing, flapping, cancellation, and cleanup. * pr review comments ---------
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ticket: SC-37713
Adds debouncing to network reachability online transitions in the Android SDK:
Implementation
New
DebouncedNetworkMonitordecorator implementsNetworkMonitor, wrapping the rawAndroidNetworkMonitor. The client creates it asDebouncedNetworkMonitor(rawMonitor, scope)and uses it like any otherNetworkMonitor— the debounce is transparent. (DebouncedNetworkMonitorimplementingNetworkReachability), keeping cross-platform alignment.Uses coroutine
delay()+Jobcancellation for the timer mechanism, with@Volatileon the debounce job reference.stop()handles both inner monitor teardown and debounce cancellation — no separate cleanup needed in the client.Files Changed
DebouncedNetworkMonitor.ktNetworkMonitorwith debounced online transitions (~60 lines)DebouncedNetworkMonitorTest.ktisConnectedstate, cleanupMetaRouterAnalyticsClient.ktreset()cleanup