Skip to content

feat: Apply RETRY to FDv2 synchronizer orchestration - #418

Merged
beekld merged 6 commits into
mainfrom
bklimt/SDK-3508/retry-orchestration
Dec 1, 2026
Merged

beekld merged 6 commits into
mainfrom
bklimt/SDK-3508/retry-orchestration

Conversation

@beekld

@beekld beekld commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Applies the RETRY behavior to FDv2 synchronizer orchestration in launchdarkly_common_client. A synchronizer that fails is parked and retried later, instead of being blocked for good, and the data system no longer stops because of an HTTP or transport failure.

Parking

  • A synchronizer that fails unexpectedly is parked. That covers:
    • a terminal error,
    • a shutdown or end of its results that the SDK didn't ask for,
    • an error while it runs,
    • a failure to build.
  • 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, two successful polls in a row.
    • For streaming, 60 seconds after the first change set on a connection. A change set from a ping-triggered poll counts.
  • When every synchronizer is parked, the data source reports INTERRUPTED and waits for the earliest unpark time. A pending identify keeps waiting.
  • Fallback and recovery switch only to a synchronizer that isn't parked. If the condition is met while every other candidate is parked, the current synchronizer keeps running, and the switch happens as soon as one unparks. A change set from the current synchronizer before then cancels a pending fallback.

Directed fallback

  • The fallback to FDv1 now ends after its TTL. The data source then restarts the FDv2 synchronizers.
  • A TTL from the server is used when it's in (0, 1 hour]. Otherwise the TTL is 1 hour with jitter. A TTL of zero no longer means "fall back indefinitely".
  • A directive received during the fallback replaces the TTL.
  • With no FDv1 fallback synchronizer configured, a directive stops the FDv2 synchronizers until the TTL ends, and the data source reports INTERRUPTED.
  • When an initializer's directive comes with a payload, the payload marks the data source ready only if it has a selector. Before, it never did with an FDv1 fallback synchronizer configured, and always did without one.

Not included

  • Readiness for synchronizer results. Any synchronizer change set still marks the data source ready, where the data system spec allows only a full payload.
  • Checking for a delta or up-to-date response to a request that had no basis, which the spec says to report as interrupted.
  • Honoring Retry-After on a failure.

Note

Overview
Reworks FDv2 synchronizer orchestration so failed sources are parked and retried instead of permanently blocked, and aligns FDv1 fallback, status reporting, and tier switching with the RETRY behavior.

Parking and backoff: Unexpected failures (terminal error, unexpected shutdown/stream end, build/run errors) park the slot with exponential backoff (5 minutes base, capped at 1 hour, jittered), then failover to another synchronizer after a short delay. SourceManager tracks unpark times and per-slot park counts; meeting a reset threshold clears the count (two consecutive successful polls for polling; 60 seconds of healthy streaming after the first change set). When every synchronizer is parked, the orchestrator emits INTERRUPTED and waits for the earliest unpark or FDv1 fallback end.

Orchestration model: Removes the separate conditions.dart stream/timers; fallback and recovery deadlines are handled inline via a monotonic clock and _awaitUntil waits. Terminal errors no longer block slots—they park. Status goes through StatusEvent on the data source stream instead of DataSourceStatusManager on the orchestrator.

FDv1 directive: Fallback is time-bounded (startFdv1Fallback / endFdv1FallbackIfExpired); server TTL is honored in (0, 1 hour], otherwise ~1 hour with jitter (zero is no longer “indefinite”). Goodbye and many HTTP paths carry fdv1Fallback on the result instead of forcing terminal error solely to trigger fallback.

Tests: Large additions to orchestrator, source manager, streaming/polling, and removal of conditions_test.dart.

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

@beekld
beekld marked this pull request as ready for review November 30, 2026 18:40
@beekld
beekld requested a review from a team as a code owner November 30, 2026 18:40
@cursor cursor Bot added the risk:medium label Nov 30, 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 retry, parking, and fallback TTL in orchestrator.dart, source_manager.dart, and related data-source files, which is a large existing-behavior change rather than a narrow fix. Cursor Bugbot also did not reach a terminal state within the wait window.

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

@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 06cebc4. Configure here.

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

Stale comment

Risk: medium. Not approved under the risk-threshold rule (only low-risk PRs may be auto-approved) and because Cursor Bugbot reported 1 unresolved high-severity finding; SDK rules 1–3 otherwise allow this author and change set to be reviewed. Human review is needed and no reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: SDK - Pull Request Router and Approver

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

Stale comment

Risk: medium. Not approved under the risk-threshold rule (only low-risk PRs may be auto-approved); SDK rules 1–3 otherwise allow this author and change set, and Cursor Bugbot completed with no unresolved findings. Human review is needed and no reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: SDK - Pull Request Router and Approver

/// with no FDv1 fallback tier configured and no server-provided TTL.
static const Duration _defaultFallbackRetryInterval = Duration(hours: 1);
/// True if the last status reported for this data source was a failure.
bool _failed = false;

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.

AI review comment: _failed is a little smelly.

  • The name overpromises. It really means "the last event this orchestrator emitted was an error status", and only a payload clears it (a valid status does not). Something like _lastEventWasError would say what it does.
  • It is a hand-synced mirror of emission history, overlapping with _emittedPayload. It has two writers (_reportStatus sets it, the payload path clears it), so every future emit path has to remember to update it.
  • The only reader is _reportInterrupted, which skips emitting so the earlier specific error is "kept". That relies on DataSourceManager still holding the previous error, which is an implicit contract with code outside this file. If the manager stops retaining it, this becomes a silent no-op that loses the error.

Suggestion: keep a single StatusEvent? _lastStatus, updated in one _emit helper that both payloads and statuses go through, and have _reportInterrupted use _lastStatus ?? generic (re-emitting the real last error). That removes the boolean and the dependency on the manager.

Nit-level, not a blocker.

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.

AI response:

1. "The name overpromises." In practice, "the last event emitted was an error status" and "the last status was a failure" are the same thing here. The orchestrator never emits a valid status; DataSourceManager sets valid when it applies a payload. Android's flag has the same name, failed in ConnectivityManager.DataSourceUpdateSinkImpl, documented as "True if the last FDv2 status that this sink recorded was a failure". Android clears it on the valid status it sends right after applying a change set, which is where Flutter clears it, in _emitPayload.

2. "A hand-synced mirror with two writers." True, but each side has a single writer: every failure goes through _reportStatus, which sets it, and every payload goes through _emitPayload, which clears it. Android has the same two writers in its sink's setStatus. The only status that skips _reportStatus is _halt's shutdown event, and nothing follows a halt.

3. "It relies on DataSourceManager keeping the previous error." That's the same contract Android has. Its rule, "Keep the error that is already recorded", relies on the connection info still holding the last failure. In Flutter, DataSourceStatusManager keeps lastError until a new error replaces it, and setValid() doesn't clear it. That's also what the public DataSourceStatus.lastError promises: "the last error will still be reported in this property even if the state later becomes valid."

The suggestion to store StatusEvent? _lastStatus and have _reportInterrupted() re-emit it would change behavior: DataSourceManager would record the old error again with a new time, and every status listener would get a second notification for an error that didn't happen again. Android deliberately doesn't do that; it returns early to keep the recorded error.

fallbackTime ??= _now().add(_fallbackTimeout);
}
_reportTransientError(result);
case SourceState.terminalError:

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.

AI review comment: a fallback directive that is not an unexpected failure now parks the FDv2 synchronizer, so recovery after the FDv1 TTL can be delayed by tens of minutes.

This case parks on every terminalError before the directive is handled below (around line 648). That was harmless before, when terminalError only meant "move on". Now it means "park", and these existing mappings feed it:

  • streaming_base.dart turns a goodbye carrying a fallback TTL (or following a header directive) into terminalError.
  • streaming_base.dart turns any HTTP error carrying the fallback header into terminalError, including a recoverable 503.
  • polling_base.dart turns a goodbye carrying a directive into terminalError.

A goodbye is not a failure and a 503 is a normal, recoverable failure, so neither should park. The data system spec parks on a directive only for an unexpected failure, and java-core does not park in either case: it emits a goodbye result for the first and an interrupted result for the second.

Effect, from a fake_async test using a goodbye with a 60s TTL, polling or background mode (one FDv2 synchronizer plus FDv1):

  • FDv1 runs for the TTL. When it ends, FDv1 is blocked again but FDv2 is still parked, so nothing runs and the status is INTERRUPTED.
  • Each repeated directive bumps the park count, and the count cannot reset because the slot is directed away immediately. Gaps between TTL end and FDv2 restart over six cycles: 195, 475, 1072, 2286, 3008, 3331 seconds.
  • So after the server stops directing, a client can go roughly 55 minutes without flag updates.
  • Flutter web cannot read response headers, so a goodbye is its only directive channel there. Every directed fallback on web takes this path.
  • An error status ("Server requested FDv1 fallback (goodbye)") is also reported for what is a normal server instruction.

The test at orchestrator_test.dart "FDv2 still parked when the fallback ends waits for its park" builds terminalError + directive by hand, so it endorses this without exercising the real mappings.

Suggestion: emit goodbye-with-directive as a goodbye (or another non-park state) that carries fdv1Fallback, and a recoverable error with the header as interrupted with fdv1Fallback. The orchestrator already handles a directive on any result. Keep terminalError + directive only for non-recoverable statuses such as 401 and 403. Alternatively, skip the park in this case when the result carries a directive and the failure is not unexpected.

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 in f87ca83.

}

/// The park delay after [parkCount] unexpected failures, including this one.
Duration _parkDelay(int parkCount) {

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.

AI review comment: nit: indicate that parkCount must be 1 or greater.

This matters a little more in Dart than usual: 1 << math.min(parkCount - 1, 10) throws an ArgumentError for a negative shift, so a parkCount of 0 would throw instead of returning a delay. It is unreachable today because the caller passes the result of incrementCurrentSynchronizerParkCount(), which is at least 1, but a doc line (and perhaps an assert(parkCount >= 1)) would make the precondition explicit.

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 in 4782384.

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

Stale comment

Risk: medium. Not approved under the risk-threshold rule (only low-risk PRs may be auto-approved); SDK rules 1–3 otherwise allow this author and change set, and Cursor Bugbot completed with no unresolved findings. Human review is needed and no reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: SDK - Pull Request Router and Approver

@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. Not approved under the risk-threshold rule (only low-risk PRs may be auto-approved); SDK rules 1–3 otherwise allow this author and change set, and Cursor Bugbot completed with no unresolved findings. Human review is needed and no reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: SDK - Pull Request Router and Approver

@tanderson-ld
tanderson-ld self-requested a review December 1, 2026 14:09

@tanderson-ld tanderson-ld left a comment

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.

One low that may be worth addressing:

1 │ Low │ Initializer-only mode with an FDv1 fallback never recovers after the TTL; logs an error every 5 minutes and reports INTERRUPTED forever │ orchestrator.dart 515-536, source_manager.dart

@beekld

beekld commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Initializer-only mode with an FDv1 fallback never recovers after the TTL; logs an error every 5 minutes and reports INTERRUPTED forever

Done in 1b9b3bd.

@beekld
beekld merged commit 5eb95f5 into main Dec 1, 2026
11 checks passed
@beekld
beekld deleted the bklimt/SDK-3508/retry-orchestration branch December 1, 2026 21:06
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