Repository navigation
feat: Apply RETRY to FDv2 synchronizer orchestration - #418
Conversation
There was a problem hiding this comment.
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.
Sent by Cursor Approval Agent: Dry-Run PR Approver
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 06cebc4. Configure here.
There was a problem hiding this comment.
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.
Sent by Cursor Approval Agent: SDK - Pull Request Router and Approver
There was a problem hiding this comment.
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.
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; |
There was a problem hiding this comment.
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
_lastEventWasErrorwould say what it does. - It is a hand-synced mirror of emission history, overlapping with
_emittedPayload. It has two writers (_reportStatussets 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 onDataSourceManagerstill 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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.dartturns a goodbye carrying a fallback TTL (or following a header directive) intoterminalError.streaming_base.dartturns any HTTP error carrying the fallback header intoterminalError, including a recoverable 503.polling_base.dartturns a goodbye carrying a directive intoterminalError.
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.
| } | ||
|
|
||
| /// The park delay after [parkCount] unexpected failures, including this one. | ||
| Duration _parkDelay(int parkCount) { |
There was a problem hiding this comment.
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.
…or that directs fallback
There was a problem hiding this comment.
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.
Sent by Cursor Approval Agent: SDK - Pull Request Router and Approver
There was a problem hiding this 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.
Sent by Cursor Approval Agent: SDK - Pull Request Router and Approver
tanderson-ld
left a comment
There was a problem hiding this comment.
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
Done in 1b9b3bd. |



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
identifykeeps waiting.Directed fallback
Not included
Retry-Afteron 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.
SourceManagertracks 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.dartstream/timers; fallback and recovery deadlines are handled inline via a monotonic clock and_awaitUntilwaits. Terminal errors no longer block slots—they park. Status goes throughStatusEventon the data source stream instead ofDataSourceStatusManageron 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 carryfdv1Fallbackon 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.