Repository navigation
feat: add client-side streaming retry and error-recovery contract tests - #395
Merged
Merged
Conversation
The client-side test suite verified stream requests and updates but had no coverage of reconnection behavior: nothing checked that a client-side SDK retries the stream after recoverable failures (IO errors, 400, 408, 429, 5xx) or that it stops after unrecoverable ones (other 4xx). The server-side suite has had these tests for years; this fills the gap for client-side SDKs, where an unnoticed regression means a client silently serving stale flags with no live connection. These mirror the server-side retry tests with one structural change: client-side SDKs resolve initialization on the first connection attempt's outcome instead of blocking through retries, so the initial-connect tests create the client with initCanFail and verify background retry plus eventual data delivery instead of asserting successful initialization.
kinyoklion
marked this pull request as ready for review
July 30, 2026 21:09
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b3a32ac. Configure here.
Two portability fixes from running the new tests against seven client-side SDK implementations: Browser-native EventSource does not expose HTTP response status codes, so browser-based SDKs cannot distinguish unrecoverable errors and treat every stream failure as retryable. Port the client-event-source-http-errors capability from the v3 harness and require it for the do-not-retry test groups. Not every client-side SDK supports configuring the stream retry delay (Flutter's FDv1 data source has no such option), and with a default initial delay of about a second, exponential backoff can put the third retry several seconds out. Widen the incoming-connection wait to 10 seconds; this costs nothing for SDKs that honor the configured delay since the wait returns as soon as the connection arrives.
JS-based client-side SDKs receive their initial flag data from the polling service before connecting to the stream, so asserting the polled value after a successful stream retry proved nothing for those SDKs. Serve different data on the stream than on the polling service and assert the stream's value, so the final check can only be satisfied by the retried stream connection.
kinyoklion
added a commit
to launchdarkly/android-client-sdk
that referenced
this pull request
Jul 31, 2026
The legacy streaming data source's error handler classifies every 4xx response as non-retriable (`code >= 400 && code < 500`), instead of using the shared rule in `LDUtil.isHttpErrorRecoverable`, which exempts 400, 408, and 429. As a result, a single 429 (rate limit) on a stream connection attempt permanently stops the stream: the data source logs "non-retriable", stops the EventSource, and nothing schedules a retry. The client then silently serves cached flags with no live connection until a foreground/background transition, network change, or `identify` call happens to rebuild the data source. 400 and 408 are mishandled the same way. ([SDK-2824](https://launchdarkly.atlassian.net/browse/SDK-2824)) This only affects connect/reconnect-time HTTP errors; mid-stream drops are IO errors and already retry. The FDv2 synchronizers and the events sender already use the shared recoverability rule — the legacy FDv1 streaming path was the only streaming outlier, and every other LaunchDarkly SDK's streaming path treats 400/408/429 as retryable. ## Change `StreamingDataSource.onError` now classifies stream HTTP errors with `LDUtil.isHttpErrorRecoverable(code)`, so 400/408/429 fall through to the existing EventSource retry path with backoff. Handling of unrecoverable codes is unchanged, including the 401 escalation to `shutDown()`. ## Testing - New unit tests: 429/400/408 each report a retryable failure without shutting down the sink, plus an end-to-end test where the server returns 429 then a working SSE stream and the data source reconnects and applies the `put`. - New contract tests in [sdk-test-harness#395](launchdarkly/sdk-test-harness#395) (`streaming/retry behavior` for client-side SDKs), verified on an emulator: on `main` exactly the six recoverable-4xx cases fail (400/408/429 on initial connect and on reconnect); on this branch all of them pass, along with the full `streaming` category (68 tests). [SDK-2824]: https://launchdarkly.atlassian.net/browse/SDK-2824?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes live stream reconnect behavior for specific HTTP statuses; misclassification could either retry forever on bad config or still drop connections on rate limits, but logic is shared with other SDK paths already in production. > > **Overview** > **Legacy FDv1 streaming** no longer treats every 4xx as fatal on connect. `StreamingDataSource.onError` now uses `LDUtil.isHttpErrorRecoverable(code)` instead of `code >= 400 && code < 500`, matching FDv2 streaming, polling, and events. > > **400, 408, and 429** are reported as retryable `LDInvalidResponseCodeFailure` and stay on the EventSource backoff path instead of stopping the stream and serving cached flags until something else restarts the client. Unrecoverable 4xx (e.g. 401/403) and 401 `shutDown()` behavior are unchanged. > > Unit tests cover retryable classification for 400/408/429 and a 429-then-SSE reconnect scenario. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 00a33ae. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
tanderson-ld
approved these changes
Aug 4, 2026
kinyoklion
pushed a commit
that referenced
this pull request
Aug 12, 2026
🤖 I have created a release *beep* *boop* --- ## [2.39.0](v2.38.2...v2.39.0) (2026-08-12) ### Features * add client-side streaming retry and error-recovery contract tests ([#395](#395)) ([5e512a0](5e512a0)) * Add contract test for streaming connection close on client shutdown ([#377](#377)) ([35acfd4](35acfd4)) * Add hook-environment-id capability and test ([#410](#410)) ([dae3bcd](dae3bcd)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > **Release 2.39.0** — bumps the package version from **2.38.2** to **2.39.0** via Release Please (``.release-please-manifest.json`` and ``versionString`` in ``main.go``). > > **CHANGELOG** documents the feature set shipped in this minor release (already merged on main): client-side streaming retry and error-recovery contract tests, streaming connection close on client shutdown, and the ``hook-environment-id`` capability and tests. > > No application or test logic changes appear in this diff—only version metadata and changelog text. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 29fa014. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This was referenced Sep 28, 2026
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.

The client-side test suite covers stream requests and updates but has no coverage of reconnection behavior: nothing checks that a client-side SDK retries the stream after a recoverable failure (IO error, 400, 408, 429, 5xx) or that it stops after an unrecoverable one (other 4xx). The server-side suite has had these tests for years (
server_side_stream_retry.go). This gap is not hypothetical: the Android SDK's legacy streaming data source treats all 4xx statuses as non-retriable, so a single 429 on the stream connection permanently kills the stream until an app lifecycle event happens to rebuild the data source (SDK-2824).This adds
streaming/retry behaviortests for client-side SDKs, mirroring the server-side ones:Three structural differences from the server-side versions, all found by running against real SDKs:
initCanFailand then verify that the SDK keeps retrying in the background and eventually serves the flag data.client-event-source-http-errorscapability is ported from the v3 harness and gates the two do-not-retry groups. SDKs whose event sources do expose status codes should declare it (the Android service already does).Verification against real SDKs
Ran
streaming/retry behaviorlocally against seven client-side SDK implementations:main(bug present)rlamb/sdk-2824/fdv1-stream-429-recoverable)streamingcategory (68 tests) also passesdotnet-coremain)iOS and Roku could not be exercised locally (macOS/device requirements).
Note
Low Risk
Test-harness and capability-definition changes only; no production SDK or runtime behavior in this repo.
Overview
Adds a
streaming/retry behaviorsuite for client-side SDKs, aligned with the existing server-side retry tests, so harnesses can verify reconnect after recoverable failures and no further retries after unrecoverable HTTP errors.The new
doClientSideStreamRetryTestscovers server-initiated stream close, IO and recoverable status codes (400, 408, 429, 5xx) on first connect and on reconnect, and—when the SDK declaresclient-event-source-http-errors—401/403/405 cases that must not retry. Client-specific behavior is baked in:InitCanFailplus background retry assertions on initial connect, JS polling vs stream data to prove updates came from the stream, and a longer connection wait (10s) when retry delay is not configurable.Registers the suite under
doClientSideStreamTestsand documentsCapabilityClientEventSourceHTTPErrorsinservicedeffor SDKs whose EventSource can read HTTP status (browser-native EventSource cannot).Reviewed by Cursor Bugbot for commit d471022. Bugbot is set up for automated code reviews on this repo. Configure here.