Skip to content

[FFL-2929] Add Flags initialization timeout - #3693

Open
leoromanovsky wants to merge 4 commits into
developfrom
agent/ffe-precompute-timeout-retry
Open

[FFL-2929] Add Flags initialization timeout#3693
leoromanovsky wants to merge 4 commits into
developfrom
agent/ffe-precompute-timeout-retry

Conversation

@leoromanovsky

@leoromanovsky leoromanovsky commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Motivation

The first Flags context operation can wait without a limit. Mobile applications need a bounded initialization wait during normal onboarding.

Changes and Decisions

  • Add FlagsConfiguration.Builder.initializationTimeout(timeoutMs).
  • Use 5,000 milliseconds by default.
  • Apply the timeout only to the first setEvaluationContext operation.
  • Report FlagsInitializationTimeoutException when the timeout expires.
  • Publish Stale when matching cached assignments are available.
  • Otherwise, publish Error unless another operation already published Ready or Stale.
  • Keep the initialization operation running. A late success can publish Ready.
  • Map the timeout to a recoverable OpenFeature GeneralError.
  • Do not change the HTTP client timeout.
  • Preserve the existing public eight-parameter FlagsConfiguration.copy(...) signature.
flowchart TD
    A[First setEvaluationContext] --> B{Completes within timeout?}
    B -->|Yes| C[Report success and publish Ready]
    B -->|No| D[Report initialization timeout]
    D --> E{Matching cached assignments?}
    E -->|Yes| F[Publish Stale]
    E -->|No| G[Publish Error unless already Ready or Stale]
    D --> H[Initialization continues]
    H -->|Late success| C
    I[Later setEvaluationContext calls] --> J[No initialization timer]
Loading

Direct Flags use applies the 5,000-millisecond default:

Flags.enable(FlagsConfiguration.Builder().build())

OpenFeature uses the same configuration and timeout:

import com.datadog.android.flags.Flags
import com.datadog.android.flags.FlagsClient
import com.datadog.android.flags.FlagsConfiguration
import com.datadog.android.flags.openfeature.asOpenFeatureProvider
import dev.openfeature.kotlin.sdk.ImmutableContext
import dev.openfeature.kotlin.sdk.OpenFeatureAPI

val configuration = FlagsConfiguration.Builder()
    .initializationTimeout(2_000)
    .build()
Flags.enable(configuration)

val provider = FlagsClient.Builder()
    .build()
    .asOpenFeatureProvider()

OpenFeatureAPI.setProviderAndWait(
    provider = provider,
    initialContext = ImmutableContext(targetingKey = "user-123")
)

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.70968% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.41%. Comparing base (2dafcfa) to head (36e415d).

Files with missing lines Patch % Lines
...s/internal/net/PrecomputedAssignmentsDownloader.kt 91.49% 0 Missing and 4 partials ⚠️
...in/kotlin/com/datadog/android/flags/FlagsClient.kt 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3693      +/-   ##
===========================================
- Coverage    73.41%   73.41%   -0.00%     
===========================================
  Files          999      999              
  Lines        36564    36589      +25     
  Branches      6181     6190       +9     
===========================================
+ Hits         26842    26859      +17     
+ Misses        8000     7996       -4     
- Partials      1722     1734      +12     
Files with missing lines Coverage Δ
...in/com/datadog/android/flags/FlagsConfiguration.kt 91.84% <100.00%> (+5.79%) ⬆️
...in/kotlin/com/datadog/android/flags/FlagsClient.kt 44.34% <0.00%> (-0.85%) ⬇️
...s/internal/net/PrecomputedAssignmentsDownloader.kt 92.16% <91.49%> (-4.14%) ⬇️

... and 43 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leoromanovsky leoromanovsky changed the title [FFL-2929] Bound assignment request latency [FFL-2929] Bound Android assignment request latency Aug 3, 2026
@datadog-official

datadog-official Bot commented Aug 28, 2026

Copy link
Copy Markdown

Tests

All CI checks and tests passed. Datadog automation helped this PR pass.

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🔄 Datadog retried 1 test - 1 passed on retry View in Datadog

🎯 Code Coverage (details)
Patch Coverage: 87.93%
Overall Coverage: 71.77% (+0.03%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: a24f147 | Docs | View more details | Give us feedback!

@leoromanovsky leoromanovsky changed the title [FFL-2929] Bound Android assignment request latency [FFL-2929] Add assignment request timeout and retries Aug 28, 2026
@leoromanovsky leoromanovsky changed the title [FFL-2929] Add assignment request timeout and retries [FFL-2929] Add composable assignment request transport Aug 28, 2026
@leoromanovsky
leoromanovsky force-pushed the agent/ffe-precompute-timeout-retry branch from 1067781 to fed07a5 Compare August 28, 2026 23:20
@leoromanovsky
leoromanovsky marked this pull request as ready for review September 3, 2026 03:34
@leoromanovsky
leoromanovsky requested review from a team as code owners September 3, 2026 03:34
@leoromanovsky
leoromanovsky requested review from greghuels and pavlokhrebto and removed request for a team September 3, 2026 03:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-06T04:51:53.042348Z a24f147 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@leoromanovsky
leoromanovsky requested review from sameerank and typotter and removed request for greghuels and pavlokhrebto September 3, 2026 03:35

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5d4e97b3c4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8b9d07dd29

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread features/dd-sdk-android-flags/build.gradle.kts Outdated

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b483e44da7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e31877035c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f37a45aab3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 85179d8be9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 020623761b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5385089b8f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eb8bd4db00

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 83e6b6e4b3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0eb7c93052

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4801e004db

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 005c189429

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7769d47233

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e324c3e0a1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5dc7137226

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e08700f7a1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@leoromanovsky
leoromanovsky force-pushed the agent/ffe-precompute-timeout-retry branch from e08700f to f3322d8 Compare September 6, 2026 03:17

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f3322d8d65

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0819b7675d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f1eec0f714

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@leoromanovsky
leoromanovsky requested review from a team September 6, 2026 04:49

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a24f14745c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +191 to +193
val currentState = flagStateManager.getCurrentState()
if (currentState != FlagsClientState.Ready && currentState != FlagsClientState.Stale) {
val timeoutState = if (matchingCachedAssignments.get()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid publishing the first cache state over a newer context

When the first request has matching cached assignments, a second setEvaluationContext call can publish Reconciling and remain in flight until the first request's deadline. The timeout then sees Reconciling and uses the first request's matchingCachedAssignments value to publish Stale, causing OpenFeature to announce that flags are usable even though the cache belongs to the superseded context. Track whether a newer context has started and avoid applying the first request's timeout state over it.

Useful? React with 👍 / 👎.

Comment on lines 129 to +132
val hadFlags = flagsRepository.hasFlags()
matchingCachedAssignments.set(
hadFlags && flagsRepository.getEvaluationContext() == context
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recheck cached assignments when the deadline fires

When persistence takes longer than DefaultFlagsRepository's 100 ms wait but completes before the initialization deadline, this one-time snapshot remains false even though matching assignments are installed by timeout time. The timeout therefore publishes Error and emits ProviderError while those cached flags are immediately resolvable. Fresh evidence beyond the earlier cache finding is that the reviewed implementation samples the cache only here, before the network read, rather than classifying the repository at the deadline.

Useful? React with 👍 / 👎.

Comment on lines +102 to +104
val cancellation: () -> Unit = {
future?.cancel(false)
executor.shutdownSafely()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Do not cancel a timeout future that has begun running

When network completion acquires initializationTerminalLock just as the deadline runnable starts and waits for that lock, this cancellation marks the already-running scheduled future as cancelled without stopping its action. LoggingScheduledThreadPoolExecutor.afterExecute subsequently calls get() on that cancelled future and reports its CancellationException as an uncaught USER/TELEMETRY error. Fresh evidence beyond the earlier cancellation finding is this started-runnable race; cancellation should be guarded so a claimed/running deadline is allowed to finish normally.

Useful? React with 👍 / 👎.

Comment on lines +577 to +578
val firstCallback = mock<EvaluationContextCallback>()
val nestedCallback = mock<EvaluationContextCallback>()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Prefix verified callback mocks with mock

These Mockito doubles are later verified but are named firstCallback and nestedCallback rather than using the required mock prefix; the added race test likewise declares a verified mock as callback. Fresh evidence after the earlier claimed rename is that these unprefixed verified mocks remain in the reviewed commit, so rename them according to their role.

AGENTS.md reference: AGENTS.md:L77-L81

Useful? React with 👍 / 👎.

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.

5 participants