Skip to content

feat: Apply RETRY to FDv2 synchronizer orchestration - #423

Merged
beekld merged 27 commits into
mainfrom
bklimt/SDK-3507/retry-orchestration
Nov 30, 2026
Merged

beekld merged 27 commits into
mainfrom
bklimt/SDK-3507/retry-orchestration

Conversation

@beekld

@beekld beekld commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Applies the RETRY behavior to FDv2 synchronizer orchestration in the Android SDK, following launchdarkly/java-core#252 and launchdarkly/java-core#253. A synchronizer that fails is parked and retried later, instead of being blocked for good.

Parking

  • A synchronizer that fails unexpectedly is parked. That covers a terminal error, a failed or throwing next(), a failure to build, or shutting down on its own. The park delay starts at 5 minutes, doubles with each failure up to 1 hour, and has jitter. After a park, the next synchronizer starts after a failover delay of 0.5-1 seconds.
  • A synchronizer's park count resets when it meets its reset threshold. For the FDv2 polling and FDv1 fallback synchronizers, that's two successful polls in a row. For streaming, it's staying connected for 60 seconds.
  • The poll that a ping event triggers counts as a success or a failure for the streaming reset threshold.
  • When every synchronizer is parked, the data source reports INTERRUPTED and waits for the earliest unpark time. Synchronization stops only when the data source is stopped.
  • Fallback and recovery switch only to a synchronizer that isn't parked. When the fallback condition is met but no other synchronizer is available, the current synchronizer keeps running.
  • An exception on the stream thread is now terminal, so the streaming synchronizer is parked and rebuilt instead of staying dead.
  • The FDv2 status sink in ConnectivityManager now records an INTERRUPTED status with no error as a failure instead of a successful connection.

Directed fallback

  • The fallback to FDv1 now ends after a TTL, which defaults to 1 hour with jitter. The data source then restarts the FDv2 synchronizers.
  • A directive received during the fallback extends the TTL.
  • A directive with no FDv1 fallback synchronizer configured is no longer ignored. The data source reports INTERRUPTED, runs no synchronizer, and restarts the FDv2 synchronizers when the TTL ends.
  • When an initializer's directive comes with a payload that has no selector, the payload is applied but no longer marks the data source ready. Readiness waits for the next source's data, as the data system spec requires.

Deadlines

  • The synchronizer loop checks its fallback, recovery, unpark, and TTL deadlines each time it wakes. The deadlines use System.nanoTime(), so changes to the system clock don't move them. FDv2DataSourceConditions is removed.

Public API

This extends the public FDv2SourceResult class in com.launchdarkly.sdk.android.subsystems, the result type that initializers and synchronizers return. It adds two methods:

  • isResetThresholdMet() returns true if the source met its reset threshold at the time of the result. When a synchronizer returns such a result, the data source resets that synchronizer's park count. Results from the existing changeSet() and status() factory methods return false.
  • withResetThresholdMet() returns a copy of the result with isResetThresholdMet() set to true.

FDv2SourceResult is part of the early access FDv2 data system. It now carries the same note as the other early access types, saying that it is not stable and not subject to backwards compatibility guarantees or semantic versioning.

Not included

  • Treating TLS certificate failures as terminal. That needs FailureClass from a newer java-sdk-internal.
  • Honoring Retry-After, and reading the TTL from the response. Every directive uses the 1-hour default.

Note

Overview
Replaces permanent synchronizer blocking with park-and-retry: failed synchronizers back off (exponential delay with jitter), then become eligible again; FDv2DataSourceConditions and its timer-based fallback/recovery races are removed in favor of a MonotonicTime-driven loop that wakes on results, fallback/recovery deadlines, unpark times, and FDv1 fallback TTL.

Synchronizers now signal FDv2SourceResult.isResetThresholdMet() / withResetThresholdMet() (two good polls for FDv1/FDv2 polling, ~60s healthy stream including ping-triggered polls); the orchestrator clears park counts when that fires. Streaming treats unexpected stream-thread death as terminal (rebuild after park). Directed FDv1 fallback uses a default ~1h TTL with jitter, can extend on repeat directives, and can run with no FDv1 synchronizer (INTERRUPTED until TTL). Initializer FDv1 payloads without a selector no longer mark the data source ready.

ConnectivityManager keeps the last failure when an INTERRUPTED status arrives with no error. An e2e test stops awaiting identify().get() when polling never succeeds, relying on cached context instead.

Reviewed by Cursor Bugbot for commit a80efe9. Bugbot is set up for automated code reviews on this repo. Configure here.

@beekld
beekld force-pushed the bklimt/SDK-3507/retry-orchestration branch from f6af197 to c2788f3 Compare November 12, 2026 22:51
@beekld
beekld marked this pull request as ready for review November 13, 2026 18:11
@beekld
beekld requested a review from a team as a code owner November 13, 2026 18:11

@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 843447f. Configure here.

@cursor cursor Bot added the risk:medium label Nov 13, 2026

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

Risk: medium.

Automated risk review (dry run): Medium

This PR would not be automatically approved. Human approval required.

Why: This reworks FDv2 synchronizer parking, retry, fallback TTL, and the public FDv2SourceResult API in FDv2DataSource, SourceManager, and related synchronizers. Cursor Bugbot also reported an unresolved medium-severity issue in FDv2StreamingSynchronizer where a failed ping poll can be overwritten by the reset-threshold timer.

If you disagree with this review, share this PR in #feedback-agent-approvals or submit a changes-requested review explaining why.

Open in Web View Automation 

Sent by Cursor Approval Agent: Dry-Run PR Approver

if (!changeSet.getSelector().isEmpty()) {
sink.setStatus(DataSourceState.VALID, null);
tryCompleteStart(true, null);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this change necessarily in scope? Seems like it could be out of scope.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is admittedly difficult to draw the line how much to implement at once, and the orchestrator changes necessarily include some FDv1 fallback. If you want me to pull out this block and do it later, I can.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good with this change after reading/digging more.

* @return the delay after jitter, in milliseconds
*/
private static long jittered(long delayMillis) {
return delayMillis - ThreadLocalRandom.current().nextLong(delayMillis / 2 + 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: ThreadLocalRandom isn't common in the code base. Usually an injected Random is used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ThreadLocalRandom is used in java-core and okhttp-eventsource. I could inject Random, but we can't use Random.nextLong in Android's version of Java, so it wouldn't be a drop-in replacement exactly. I'm inclined to leave it, unless you feel strongly.

/**
* Computes the park delay for a synchronizer.
*
* @param parkCount the park count of the synchronizer, including the current failure

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: indicate that parkCount must be 1 or greater.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@beekld
beekld merged commit 0379078 into main Nov 30, 2026
7 checks passed
@beekld
beekld deleted the bklimt/SDK-3507/retry-orchestration branch November 30, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants