Skip to content

feat(flags): add retained first-flags callbacks to Dart and Flutter clients - #1204

Draft
typotter wants to merge 15 commits into
developfrom
codex/flutter-first-flags-retained
Draft

typotter wants to merge 15 commits into
developfrom
codex/flutter-first-flags-retained

Conversation

@typotter

@typotter typotter commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

What and why?

Applications need to react when the first usable flag configuration is installed, including cached flags available before network initialisation finishes. Add onFirstFlags directly to the Dart and Flutter flags clients:

typedef FlagsClientEventListener = void Function(FlagsClientEvent event);
void Function() onFirstFlags(FlagsClientEventListener listener);

Each registration receives the first accepted configuration once. Plain configurations supply an immutable list of logical flag keys, including an empty list for an empty configuration. Obfuscated configurations supply flagsChanged: null because logical keys are unavailable. Late registrations receive the retained event. If no usable configuration is installed, the registration can remain pending until cancelled. Evaluations in the callback read current flag values.

This is a source-breaking interface addition: custom DatadogFlagsClient implementations must implement the method. Both packages remain at 1.2.0, with Flutter requiring core ^1.2.0. Publish core before the Flutter integration.

How?

Core retains the first event, binds listeners to their registration zones and schedules delivery in a later microtask. The returned unregister function is idempotent and suppresses delivery until the callback starts. Callback references are cleared on cancellation or delivery. Synchronous listener errors are isolated; the application owns errors from asynchronous work started by its callback.

Flutter resolves its underlying client and forwards registration, delivery and cancellation. Cancellation also works while that resolution is pending. If shutdown occurs before resolution finishes, the registration is cancelled without forwarding to the terminated client. FlagsClientEvent keeps its constructor annotated @internal and defensively copies its key list.

The CLI example loads .env, prints the first event and evaluates its selected flag. Command-line --env and --site options override configuration values. The Flutter example registers in initState, displays a callback evaluation and unregisters in dispose; it uses the repository's .env convention and reports unsupported sites as unconfigured.

The Flutter app registers and cleans up as follows (exact excerpt):

@override
void initState() {
  super.initState();
  final client = DatadogSdk.instance.flags?.sharedClient();
  if (widget.isConfigured && client != null) {
    _unregisterFirstFlags = client.onFirstFlags((event) {
      debugPrint('First installed flags: ${event.flagsChanged}');
      final details = client.getBooleanDetails(
        key: _flagKey,
        defaultValue: false,
      );
      if (mounted) setState(() => _firstDetails = details);
    });
  }
  unawaited(_evaluate());
}

@override
void dispose() {
  _unregisterFirstFlags?.call();
  super.dispose();
}

Local validation: 30 Flutter wrapper tests and 2 example configuration tests passed, including regressions for shutdown during delegate resolution with and without a retained event. Both packages and both examples analyse cleanly; changed Dart files pass formatting and whitespace checks. The CLI executable and Flutter debug bundle build successfully. The unchanged core runtime passed 238 VM tests and 235 tests on each of Chrome and Wasm during validation of obfuscated-event delivery. These checks use companion source packages and do not establish published-package compatibility or live Datadog delivery.

Review checklist

  • This pull request has appropriate unit and / or integration tests
  • This pull request references a Github or JIRA issue

FFE reviewer selection

Reviewers: @sameerank, @leoromanovsky

Why: dart — The PR adds a public onFirstFlags listener API to the Dart and Flutter flags clients. Reviewers come from the matched pod.

🤖 Automated selection.

Selection details

Initiative: fallback / dart

Why this match: The PR adds a public onFirstFlags listener API to the Dart and Flutter flags clients. Through a new FlagsClientEvent (CONFIGURATION_CHANGED), it notifies the app once when the first cached or network flag configuration is installed. Late registrations get the stored event. Unregistering is idempotent. The Flutter plugin forwards registration and handles cancellation while it is still resolving its client. This is a general client lifecycle and event feature. No registered project covers it: it is not onboarding diagnostics or telemetry (guided-onboarding), not one of the listed migration gaps (sdk-migration-parity), and not about offline startup, tag scoping, delivery mode or EVP telemetry. So it falls back to the Dart flags subject area.

  • @sameerank — primary (client-dart): Matched pod member. Existing review coverage preserved.
  • @leoromanovsky — floating (client-dart): Coverage and knowledge sharing. Existing review coverage preserved.

The PR author was excluded. Existing reviewers and teams were preserved.

Debug or fix a problem

Workflow run · Bits Code session

  • Wrong project or pod? Clarify this PR’s purpose, or correct the reviewer registry and publish the change. Sheet edits take effect after publication.
  • Need another reviewer now? Request them in GitHub. This workflow only adds requests and keeps existing reviewers.
  • Stuck beyond five minutes or failed? Inspect the run’s failed step and available Bits session. After fixing the cause, rerun the workflow with this PR URL and dry_run=false. Unchanged completed runs are skipped. If the receipt says needs_reconciliation or a write outcome is uncertain, ask the workflow owner to reconcile GitHub and the receipt before retrying; do not delete the lock blindly.
  • Report a problem: Comment on the reviewer-routing skill PR with this PR URL, the workflow run link, and the expected initiative or reviewer correction.
Evidence and run details

✅ Complete — reviewer coverage verified. The workflow checked pending requests or submitted reviews on the evaluated head.

Generated asynchronously by the FFE reviewer-routing workflow.

Changed paths: packages/datadog_flags/lib/src/flags_client.dart, packages/datadog_flags/lib/src/flags_client_event.dart, packages/datadog_flags/lib/src/default_flags_client.dart, packages/datadog_flags/lib/src/flags_repository.dart, packages/datadog_flags/lib/src/no_op_flags_client.dart, packages/datadog_flags_flutter/lib/src/datadog_flags_plugin.dart, packages/datadog_flags/test/first_flags_callback_test.dart, packages/datadog_flags_flutter/test/first_flags_registration_test.dart

Evaluated head: 41fe9f7daa37f325bc7ed500567289dd558baf67

Registry revision: revision:1946aa2a-530e-487a-84a7-83aff44a1089

Pinned skill source: d214cfc65ae154b97d39af5cf32caf48aaec9bf0

Instructions: workflow-injected snapshot (no plugin loaded)

Instruction snapshot SHA-256: f23b2a88c13c0da90e2dd58246a14f257af91e2195c555039bd555b52e6f3516

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Pipelines

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 465610a | Docs | Give us feedback!

@typotter
typotter marked this pull request as ready for review October 5, 2026 16:53
@typotter
typotter requested review from a team as code owners October 5, 2026 16:53
@typotter
typotter requested review from sameerank and vjfridge and removed request for a team October 5, 2026 16:53
@drichards-87 drichards-87 self-assigned this Oct 5, 2026
@typotter
typotter requested review from leoromanovsky and removed request for vjfridge October 5, 2026 18:17
drichards-87
drichards-87 previously approved these changes Oct 5, 2026
@drichards-87 drichards-87 removed their assignment Oct 5, 2026
@typotter
typotter requested a balanced review from Copilot October 5, 2026 18:29

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

Cross-package asynchronous lifecycle, weak-reference, and cancellation semantics warrant final human validation despite extensive coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Adds retained first-install flag callbacks across Dart core and Flutter, including cancellation, documentation, examples, and comprehensive tests.

Changes:

  • Adds immutable flag events and an event facade backed by weak client associations.
  • Implements one-shot asynchronous delivery and cancellation in core and Flutter.
  • Updates examples, documentation, and lifecycle/GC test coverage.
File Description
packages/​datadog_flags/​lib/​datadog_flags.dart Exports event APIs.
packages/​datadog_flags/​lib/​datadog_flags_internal.dart Exports the companion-package bridge.
packages/​datadog_flags/​lib/​src/​default_flags_client.dart Registers core event delivery.
packages/​datadog_flags/​lib/​src/​flags_client.dart Clarifies initialization documentation.
packages/​datadog_flags/​lib/​src/​flags_client_event.dart Defines immutable event data.
packages/​datadog_flags/​lib/​src/​flags_event_registry.dart Adds weak event-source associations.
packages/​datadog_flags/​lib/​src/​flags_events.dart Adds the public facade and extension.
packages/​datadog_flags/​lib/​src/​flags_repository.dart Retains and delivers the first event.
packages/​datadog_flags/​lib/​src/​no_op_flags_client.dart Supports no-op registration.
packages/​datadog_flags/​test/​flags_events_compatibility_test.dart Tests legacy-client compatibility.
packages/​datadog_flags/​test/​flags_client_event_test.dart Tests event immutability and type mapping.
packages/​datadog_flags/​test/​first_flags_registration_test.dart Tests registration and cancellation.
packages/​datadog_flags/​test/​first_flags_callback_test.dart Tests installation callback behavior.
packages/​datadog_flags/​test_vm/​helpers/​force_gc.dart Adds VM garbage-collection support.
packages/​datadog_flags/​test_vm/​first_flags_capture_test.dart Tests capture release and facade lifetime.
packages/​datadog_flags/​example/​bin/​typed_evaluation.dart Demonstrates first-install callbacks.
packages/​datadog_flags/​example/​test/​typed_evaluation_test.dart Tests the CLI example.
packages/​datadog_flags/​example/​pubspec.yaml Adds example test dependencies.
packages/​datadog_flags/​README.md Documents the core API.
packages/​datadog_flags/​CHANGELOG.md Records the core feature.
packages/​datadog_flags_flutter/​lib/​datadog_flags_flutter.dart Re-exports event APIs.
packages/​datadog_flags_flutter/​lib/​src/​datadog_flags_plugin.dart Forwards registrations to core.
packages/​datadog_flags_flutter/​test/​helpers/​first_flags_test_client.dart Adds a wrapper test factory.
packages/​datadog_flags_flutter/​test/​flags_events_compatibility_test.dart Tests Flutter compatibility.
packages/​datadog_flags_flutter/​test/​first_flags_registration_test.dart Tests forwarding and cancellation.
packages/​datadog_flags_flutter/​test_vm/​helpers/​force_gc.dart Adds Flutter VM GC support.
packages/​datadog_flags_flutter/​test_vm/​first_flags_capture_test.dart Tests wrapper capture release.
packages/​datadog_flags_flutter/​example/​lib/​main.dart Demonstrates callback lifecycle handling.
packages/​datadog_flags_flutter/​example/​test/​first_flags_example_test.dart Tests the Flutter example.
packages/​datadog_flags_flutter/​example/​pubspec.yaml Adds example test dependencies.
packages/​datadog_flags_flutter/​README.md Documents Flutter behavior and release coordination.
packages/​datadog_flags_flutter/​CHANGELOG.md Records the Flutter feature.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

sameerank
sameerank previously approved these changes Oct 5, 2026

@sameerank sameerank 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 found one correctness issue but I assume it's non-blocking. Doesn't sound common to register and initialize in different Dart zones

Base automatically changed from typo/flutter-cached-reason to develop October 5, 2026 20:09
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot dismissed stale reviews from sameerank and drichards-87 October 5, 2026 20:09

The base branch was changed.

@typotter typotter changed the title feat: retain first flags events for Dart and Flutter client callbacks feat: add retained first flags callbacks directly to Dart and Flutter clients Oct 6, 2026
@typotter
typotter requested a balanced review from Copilot October 6, 2026 20:18

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

The source-breaking cross-package API and deferred release-version coordination require final human validation.

Review effort: Balanced
Findings: None

leoromanovsky
leoromanovsky previously approved these changes Oct 6, 2026

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

Didn't find any actionable defects.

@fuzzybinary fuzzybinary left a comment

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.

The two very big things here that I'm concerned about:

  • Calling the GC directly, even in tests. Unless I'm mistaken, that is not publicly documented, and we have no control over what Dart does with that call, or even what type of GC it might trigger.
  • The additions both README are way too detailed for public facing documentation and in some cases are specifically instructions to us as maintainers. If we want to retain that information, it needs to go somewhere else.

Comment thread packages/datadog_flags/CHANGELOG.md Resolved
Comment thread packages/datadog_flags/README.md Resolved
Comment thread packages/datadog_flags/README.md Resolved
@barboraplasovska
barboraplasovska removed their request for review October 9, 2026 13:38
Notify applications when the first usable flag configuration is installed. Core retains the immutable key inventory and delivers callbacks asynchronously in their registration zones; Flutter bridges registration and cancellation to core.

Validate with 148 core and Flutter tests, static analysis, formatting, and compiled CLI and Flutter examples.

BREAKING CHANGE: Custom DatadogFlagsClient implementations must implement onFirstFlags.
Comment thread packages/datadog_flags/README.md Resolved
leoromanovsky
leoromanovsky previously approved these changes Oct 28, 2026

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

🤖 Review submitted by Codex at @leoromanovsky’s explicit request. One non-blocking documentation correction is posted separately. Core tests: 238 passed. Flutter tests: 30 passed. CI provider-log verification remains incomplete; this approval does not confirm merge-queue readiness.

@leoromanovsky

leoromanovsky commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

FFE reviewer selection

Reviewers: @leoromanovsky

Why: dart — The PR adds a Dart SDK feature to the Dart and Flutter flags clients: an onFirstFlags callback that keeps the first accepted cached or network configuration and delivers it… Reviewers come from the matched pod.

🤖 Automated selection.

Selection details

Initiative: fallback / dart

Why this match: The PR adds a Dart SDK feature to the Dart and Flutter flags clients: an onFirstFlags callback that keeps the first accepted cached or network configuration and delivers it once to each registration, including late ones. It lists logical keys for plain configurations and gives null keys for obfuscated ones. The Flutter plugin forwards registration and cancellation, and handles shutdown while client resolution is pending. No registered project fits. It is not an onboarding diagnostic, a migration-parity gap or an offline-bootstrap deliverable, so the Dart SME owns it. The Swift change is an unrelated macOS watchdog guard.

Why these owners: Eligible reviewers have already approved the current head; no additional reviewers are needed for the responsibilities those approvals cover.

  • @leoromanovsky — floating (client-dart): Coverage and knowledge sharing. Covers: openfeature-architecture. Existing review coverage preserved.

Additional review: openfeature-architecture — The PR adds a new client lifecycle and readiness event contract to the public DatadogFlagsClient interface, which custom implementations must now implement (a source-breaking change). The contract covers a FlagsClientEvent type using the cross-SDK CONFIGURATION_CHANGED code, retained first-configuration delivery on cache restore and network install, and the meaning of null versus empty key lists for obfuscated configurations. The Flutter plugin forwards this lifecycle through delegate resolution and shutdown. Coverage: @leoromanovsky. Evidence: packages/datadog_flags/lib/src/flags_client.dart, packages/datadog_flags/lib/src/flags_client_event.dart, packages/datadog_flags/lib/src/flags_repository.dart, packages/datadog_flags_flutter/lib/src/datadog_flags_plugin.dart

The PR author was excluded. Existing reviewers and teams were preserved.

Debug or fix a problem

Workflow run · Bits Code session

  • Wrong project or pod? Clarify this PR’s purpose, or correct the reviewer registry and publish the change. Sheet edits take effect after publication.
  • Need another reviewer now? Request them in GitHub. This workflow only adds requests and keeps existing reviewers.
  • Stuck beyond five minutes or failed? Inspect the run’s failed step and available Bits session. After fixing the cause, rerun the workflow with this PR URL and dry_run=false. Unchanged completed runs are skipped. If the receipt says needs_reconciliation or a write outcome is uncertain, ask the workflow owner to reconcile GitHub and the receipt before retrying; do not delete the lock blindly.
  • Report a problem: Comment on the reviewer-routing skill PR with this PR URL, the workflow run link, and the expected initiative or reviewer correction.
Evidence and run details

✅ Complete — reviewer coverage verified. The workflow checked pending requests or submitted reviews on the evaluated head.

Generated asynchronously by the FFE reviewer-routing workflow.

Changed paths: packages/datadog_flags/lib/src/flags_client.dart, packages/datadog_flags/lib/src/flags_client_event.dart, packages/datadog_flags/lib/src/flags_repository.dart, packages/datadog_flags/lib/src/default_flags_client.dart, packages/datadog_flags/lib/src/no_op_flags_client.dart, packages/datadog_flags/lib/datadog_flags.dart, packages/datadog_flags_flutter/lib/src/datadog_flags_plugin.dart, packages/datadog_flags_flutter/lib/datadog_flags_flutter.dart

Evaluated head: 4c84221b73b3a22c11175ee9c3e5c276cda74f4e

Registry revision: revision:fe6a8bb4-aeba-4b6e-af89-db919eb47638

Pinned skill source: 7e3283c602f6b18a7e3e623eecb52d3a9c091a2e

Instructions: workflow-injected snapshot (no plugin loaded)

Instruction snapshot SHA-256: 52ed8cb68675dde1a47addaefe4a9500891c24014abf7dade6dfe38cf836c1d2

@typotter
typotter dismissed stale reviews from leoromanovsky and fuzzybinary via a244242 October 30, 2026 14:47
@leoromanovsky
leoromanovsky self-requested a review October 30, 2026 14:53
leoromanovsky
leoromanovsky previously approved these changes Nov 2, 2026

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

🤖 Review submitted by Codex at @leoromanovsky’s explicit request. The previous documentation finding is addressed. No new actionable defect was found in the continuation delta. Full native build and CI-log verification remain incomplete.

@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: 24974ba658

ℹ️ 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".

Copilot AI 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.

🟡 Changes recommended

The example can call setState() after disposal during initialization, and the public listener interface lacks the delivery and cancellation contract needed by custom implementations.

2 open issues

Review effort: Balanced

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 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.

Bits Code Review: PASS

More details

Confidence is limited to static inspection: Dart and Flutter SDKs are unavailable, so callback delivery and cancellation could not be exercised.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit c970f29

@leoromanovsky
leoromanovsky self-requested a review November 11, 2026 02:46
leoromanovsky
leoromanovsky previously approved these changes Nov 11, 2026

@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: 465610acaf

ℹ️ 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 +37 to +38
FlagsData _cached({String subject = 'example-user', bool empty = false}) =>
FlagsData.fromJson({

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 Inline the cached snapshot construction helper

The new _cached helper only returns a preconfigured FlagsData fixture, which violates the repository's explicit prohibition on helpers whose only job is to return a prebuilt object. Construct the snapshots in the owning test cases or suite setup instead.

AGENTS.md reference: AGENTS.md:L63-L64

Useful? React with 👍 / 👎.

@typotter
typotter marked this pull request as draft November 16, 2026 16:32
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.

6 participants