Skip to content

fix: Use the server's FDv1 fallback TTL from the header and goodbye - #278

Open
beekld wants to merge 3 commits into
mainfrom
devin/1795126798-server-fallback-ttl
Open

beekld wants to merge 3 commits into
mainfrom
devin/1795126798-server-fallback-ttl

Conversation

@beekld

@beekld beekld commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

Closes SDK-2987. Follows #265 and #273, the goodbye TTL parsing in java-sdk-internal 1.13.1. Spec: DATASYSTEM 1.6 (sdk-specs#251).

Describe the solution you've provided

Previously the server SDK always used the jittered 1h default as the FDv1 fallback TTL. It now uses the TTL the server sends.

  • Reads X-LD-FD-Fallback-TTL from the response that carries X-LD-FD-Fallback, for both polling and streaming.
  • A goodbye that has protocolFallbackTTL is now itself a fallback directive, and its TTL takes precedence over the header's.
  • A server TTL in (0, 1h] is used as-is, with no jitter. A missing, malformed, zero, negative, or >1h TTL uses the jittered 1h default.
  • This applies to the initializer path, to the synchronizer path, and to a directive received during FDv1 fallback, which replaces the TTL.
  • FDv2SourceResult (experimental package) now carries a nullable FDv1Fallback directive, with a nullable getTtl(), in place of the boolean fdv1Fallback.
Implementation details
  • Bumps launchdarklyJavaSdkInternal from 1.13.0 to 1.13.1, which provides FDv2ActionGoodbye.getProtocolFallbackTTLMillis().
  • The header is parsed as whole seconds in HeaderConstants. A non-integer value gives a directive with a null TTL, which means the default.
  • The (0, 1h] check and the jitter live in one place, FDv2DataSource.fallbackTTL(Duration). InitializerOutcome now carries the directive.
  • Callers that passed false (file data source, TestDataV2, DataSourceSynchronizerAdapter) now pass null.
  • Tests: header parsing (valid and malformed), goodbye with and without a TTL in polling and streaming, directive preserved by the result copies, valid TTL used unjittered, invalid TTLs falling back to the default, and initializer and synchronizer fallback. ./gradlew test checkstyleMain checkstyleTest passes in lib/sdk/server.

Link to Devin session: https://app.devin.ai/sessions/cce64c67519f4babaa75176c06961c5e
Open in Devin Desktop: https://app.devin.ai/desktop/session/cce64c67519f4babaa75176c06961c5e?variant=devin
Requested by: @beekld


Note

Overview
Replaces the FDv1 fallback boolean with a structured FDv1Fallback directive (optional TTL) on FDv2SourceResult, and honors server-provided TTL when switching to FDv1.

Polling and streaming now read X-LD-FD-Fallback-TTL alongside X-LD-FD-Fallback, and goodbye events with protocolFallbackTTL can carry the directive with TTL taking precedence over headers. FDv2DataSource.fallbackTTL uses server TTL when it is in (0, 1h] without jitter; otherwise it keeps the jittered default (~1h). That logic applies on initializer fallback, synchronizer fallback, and when a new directive arrives during an active FDv1 fallback run (replacing the remaining TTL). Call sites that meant “no directive” now pass null instead of false. Tests cover header/goodbye parsing, TTL validation, directive survival through result copies, and end-to-end fallback timing.

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

Co-Authored-By: Bee Klimt <bklimt@launchdarkly.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

return interrupted(errorInfo, fdv1Fallback, null, completionCallback);
}

public static FDv2SourceResult interrupted(DataSourceStatusProvider.ErrorInfo errorInfo, boolean fdv1Fallback, Duration fdv1FallbackTTL, Function<Void, Void> completionCallback) {

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.

I think a more future-proof design might be to replace boolean fdv1Fallback, Duration fdv1FallbackTT with a new nullable FDv1Fallback object that contains a Duration ttl. That way, if the format changes in the future, we don't have to change all the interfaces.

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.

Done in 71beeaa. There's a new datasources.FDv1Fallback, holding a nullable Duration ttl. The FDv2SourceResult factories now take a nullable FDv1Fallback in place of the boolean, where null means no directive, so the extra TTL overloads are gone. getFdv1Fallback() returns the directive, and isFdv1Fallback() remains as a != null shorthand.

devin-ai-integration Bot and others added 2 commits November 20, 2026 00:00
Co-Authored-By: Bee Klimt <bklimt@launchdarkly.com>
Co-Authored-By: Bee Klimt <bklimt@launchdarkly.com>
@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review November 30, 2026 23:39
@devin-ai-integration
devin-ai-integration Bot requested a review from a team as a code owner November 30, 2026 23:39
@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 changes FDv1 fallback TTL handling in the Java server SDK data source (FDv2DataSource, PollingBase, StreamingSynchronizerImpl, HeaderConstants, and experimental FDv2SourceResult/FDv1Fallback), a protocol-behavior change across polling, streaming, initializer, and synchronizer paths. Tests cover the new TTL rules, but the blast radius is more than a narrow low-risk edit.

Human review is needed and no reviewers were assigned.

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.

Risk: medium. Not approved: this exceeds the low-risk approval threshold (SDK rules 2–3 would otherwise allow it; rule 1 does not apply). 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

@@ -0,0 +1,30 @@
package com.launchdarkly.sdk.server.datasources;

import java.time.Duration;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is probably fine in server, but we did recently make a PR to change one of these in internal or common. Because it isn't in the android API level that we use. But I wonder if we want to just not use java.time.Duration, or we just avoid it in the common libraries.

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.

This is only in the server SDK, which already uses java.time.Duration in 33 main source files on main, including the existing defaultFDv1FallbackTTL. The goodbye TTL comes from the internal lib as nullable Long millis, as of #273, and is converted to a Duration only here. As far as I can tell, lib/shared/common and lib/shared/internal have no java.time.Duration left. So "avoid it in the common libraries" seems to be the rule today, and this PR follows it. I'll leave it as is unless you'd like the server SDK to avoid it too.

Written by Devin

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.

aside: I've seen so many bugs from code that disagreed about whether a Long was seconds or millis, I'm inclined to use Duration where we can. But I know we don't want to require desugaring in Android, so... well, I'll deal either way.

);
// For initializers, file errors are terminal. For synchronizers, they are recoverable.
return FDv2SourceResult.interrupted(errorInfo, false);
return FDv2SourceResult.interrupted(errorInfo, null);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not convinced of the comment I am making, but it is worth consideration. Should we have some FDv1Fallback.None() or something instead of 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.

I went with null because:

  • FDv2SourceResult.isFdv1Fallback() already wraps the null check, so callers don't touch null directly.
  • A NONE sentinel would need its own "is this a fallback?" flag, or an identity check against the sentinel. That brings back the separate boolean this object replaced.

The cost is that any caller using getFdv1Fallback() has to null-check it, and missing that check isn't caught at compile time. Today the only one is FDv2DataSource, and only after isFdv1Fallback(). I could also return Optional<FDv1Fallback> from the getter, since this is server-only so Android isn't a concern. I'll leave it as is unless you or Bee would prefer one of those.

Written by Devin

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.

Correction to my reply above: FileInitializer also calls getFdv1Fallback(), but it only passes the value on to a new result and never dereferences it. FDv2DataSource is still the only place that reads it.

Written by Devin

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.

aside: I don't feel strongly about this, but None() doesn't feel very idiomatic Java to me. Optional would be fine, if you prefer it to null checking.

This branch has not been deployed

No deployments
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