Skip to content

feat: add client-side streaming retry and error-recovery contract tests - #395

Merged
kinyoklion merged 3 commits into
v2from
rlamb/sdk-2824/client-stream-retry-tests
Aug 5, 2026
Merged

kinyoklion merged 3 commits into
v2from
rlamb/sdk-2824/client-stream-retry-tests

Conversation

@kinyoklion

@kinyoklion kinyoklion commented Jul 30, 2026 •

Copy link
Copy Markdown
Member

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 behavior tests for client-side SDKs, mirroring the server-side ones:

  • retry after the stream is closed by the server
  • retry after IO errors and recoverable HTTP errors (400, 408, 429, 500, 503), on initial connect and on reconnect
  • no retry after unrecoverable HTTP errors (401, 403, 405), on initial connect and on reconnect

Three structural differences from the server-side versions, all found by running against real SDKs:

  1. Init semantics. Client-side SDKs resolve initialization as soon as the first connection attempt completes rather than blocking through retries, so the initial-connect tests create the client with initCanFail and then verify that the SDK keeps retrying in the background and eventually serves the flag data.
  2. Status visibility. Browser-native EventSource does not expose HTTP status codes, so browser SDKs cannot distinguish unrecoverable errors. The client-event-source-http-errors capability 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).
  3. Retry-delay configurability. Not every client-side SDK supports configuring the stream retry delay (Flutter's FDv1 data source has no such option), so the incoming-connection wait is 10s rather than 2s. This costs nothing for SDKs that honor the configured delay, since the wait returns as soon as the connection arrives.

Verification against real SDKs

Ran streaming/retry behavior locally against seven client-side SDK implementations:

SDK Result
Android main (bug present) Exactly the six recoverable-4xx cases fail: 400/408/429 on initial connect and on reconnect. Everything else passes, so the tests isolate the bug.
Android fix branch (rlamb/sdk-2824/fdv1-stream-429-recoverable) All 25 pass; full streaming category (68 tests) also passes
.NET client (dotnet-core main) All pass; do-not-retry groups verified passing before the capability gate was added, skipped after, pending capability declaration in the service
Flutter (main) All 25 pass
js-core node-client (main) All pass (do-not-retry groups verified passing before the capability gate was added; skipped after, pending capability declaration in the service)
js-core browser (main, headless Chromium) All pass; do-not-retry groups skip via the capability gate (native EventSource hides statuses)
C++ client (main) All pass; do-not-retry groups skip pending capability declaration in the service
Legacy node-client-sdk (main) All pass; do-not-retry groups skip pending capability declaration in the service

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 behavior suite 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 doClientSideStreamRetryTests covers server-initiated stream close, IO and recoverable status codes (400, 408, 429, 5xx) on first connect and on reconnect, and—when the SDK declares client-event-source-http-errors—401/403/405 cases that must not retry. Client-specific behavior is baked in: InitCanFail plus 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 doClientSideStreamTests and documents CapabilityClientEventSourceHTTPErrors in servicedef for 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.

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
kinyoklion marked this pull request as ready for review July 30, 2026 21:09
@kinyoklion
kinyoklion requested a review from a team as a code owner July 30, 2026 21:09

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread sdktests/client_side_stream_retry.go Resolved
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 -->
@kinyoklion
kinyoklion merged commit 5e512a0 into v2 Aug 5, 2026
8 checks passed
@kinyoklion
kinyoklion deleted the rlamb/sdk-2824/client-stream-retry-tests branch August 5, 2026 20:31
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants