Skip to content

feat: Let each data source decide whether FDv2 writes its data to a persistent store - #390

Merged
kinyoklion merged 6 commits into
dotnet-server-sdk-v9from
rlamb/fdv2-persist-flag-v9
Nov 20, 2026
Merged

kinyoklion merged 6 commits into
dotnet-server-sdk-v9from
rlamb/fdv2-persist-flag-v9

Conversation

@kinyoklion

@kinyoklion kinyoklion commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Summary

In the FDv2 data system with a persistent store in read-write mode, the SDK wrote the data of every initializer and synchronizer to the store, and wrote all of the memory store back to it after an outage. A file data source used as an initializer or synchronizer therefore replaced the LaunchDarkly data in a shared Redis, DynamoDB, or Consul store, on start, on every reload, and again on every store recovery.

The data system spec requires each data source to say whether its data may be persisted, and the SDK to mirror only that data: requirement 1.1.7 for initializers and 1.2.8 for synchronizers (specs/DATASYSTEM-data-system/v2/README.md). Its example is the file initializer, which does not persist. The decision is not based on the payload selector, because the FDv1 fallback synchronizer has no selector and its data must still be persisted (the spec's definition of a basis notes that neither a file data source nor the FDv1 fallback synchronizer can provide one).

The Java SDK is the complete reference implementation, and this change follows its design, with one difference described below.

How it works

  • ChangeSet and FullDataSet carry an internal persist flag. It is stored inverted, so that a defaulted struct, or one built with an existing constructor, means "persist". The public API of both types is unchanged.
  • WriteThroughStore writes a full data set or a change set to the persistent store only if its flag is set. Data that is not persisted still goes to the memory store, which becomes the store that evaluations read from, as before.
  • InMemoryDataStore remembers the flag of the latest full or partial change set and returns it from ExportAll. Like the transactional persistent store spec (requirement 1.4.3.2), it tracks a single, most recent indicator, not one per item.
  • PersistentStoreWrapper.PollAvailabilityAfterOutage skips the write when the exported data must not be persisted. The store still reports that it has recovered, and keeps its contents.
  • DataStoreSorter keeps the flag when it sorts a data set or change set.

How a data source states its flag

FDv2 polling and streaming declare that their data may be persisted when they translate a change set: FDv2ChangeSetTranslator.ToChangeSet takes the flag as a required argument, as Java's translator does, and both sources pass true. The data system applies FDv2 change sets as they are, so that argument is the only persistence control for them.

Every other source is an FDv1-style source run through DataSourceUpdatesV2ToV1Adapter. An FDv1 Upsert call has no data set that could carry a flag. So the data system reads the flag from the source's configurer each time it builds the source, through the internal interface IDataSourcePersistence, and gives it to the adapter. A configurer that does not implement the interface is persisted.

The file and test data sources also put the flag on the full data sets they deliver, so that their data stays out of the store when an application's own configurer wraps theirs and hides the interface. The adapter persists a full data set only if both the configurer and the data set allow it, and an upsert takes the flag of the last full data set, the data it changes.

This is where the change differs from Java. Java's adapter copies the flag from the full data set but always sets it on upserts, so a Java TestData configured with shouldPersist(false) keeps its initial data out of the store but writes every later update to it. After one update the memory store's flag says "persist", so the next store recovery writes the initial data as well.

Defaults

Source Persisted
FDv2 polling and streaming yes
FDv1 fallback synchronizer (DataSystemComponents.FDv1Polling()) yes
A custom data source yes, as before
FileData.DataSource() no; FileDataSourceBuilder.ShouldPersist(true) opts in
TestData no; TestData.ShouldPersist(true) opts in. Before this change, it was persisted.

The FDv1 data system is unchanged: its data store, persistent or not, receives all data, including the file data source's. The flag is read only by the FDv2 data system.

Mixed sequences

  • A file initializer followed by a persisted synchronizer's basis: the basis is written to the store and replaces whatever the store held, and a recovery after it writes the memory store.
  • A delta whose flag differs from the basis it applies to: the write-through store writes or skips each change set by its own flag, and recovery follows the flag of the latest change set, as the spec says. A persisted delta can only follow a basis that was not persisted if a source sends a delta without a basis of its own. A file source never sends deltas, TestData starts with a full data set, and an FDv2 synchronizer that follows a basis without a selector (the file and test data sources provide none) requests a full transfer.

Testing

  • FDv2DataSystemPersistenceTest runs real clients against a mock persistent store, for each case:
    • A file initializer is not written.
    • A file synchronizer's reload is not written.
    • File data with ShouldPersist(true) is written.
    • TestData is written neither for its initial data nor for an update by default.
    • TestData with ShouldPersist(true) is written, initial data and updates.
    • A custom FDv1-style data source is written.
    • The FDv1 fallback synchronizer's data is written.
    • A persisted synchronizer basis after a file initializer is written, and the file data is not; the store's Init count shows it, because the mock store's Init replaces all of its data.
    • A file data source or TestData behind an application's own wrapping configurer is not written.
    • The FDv1 data system with a file data source still writes to the store.
  • Unit tests for the write-through store, the memory store's flag of the latest change set, recovery with data that must not be persisted and with persisted data that replaced it, the adapter, the sorter, and the flag on FDv2 polling and streaming change sets.
  • To check that the tests detect the defects they target, each of thirteen parts of the fix was reverted on its own, and every reversion failed at least one test:
    • The write-through check.
    • The adapter's upsert flag, reverted to Java's behavior.
    • The recovery skip.
    • The memory store's flag for partial payloads.
    • Reading the configurer's flag.
    • The sorter.
    • The TestData flag.
    • The file data default.
    • The flag on the file data source's data set.
    • The flag on TestData's data set.
    • The adapter's use of the data set's flag.
    • The upsert's use of the last data set's flag.
    • The memory store's update of the flag on a partial payload.
  • The full server SDK test suite passes on net8.0 (2012 tests on this branch). The SDK builds for netstandard2.0, net462, and net8.0.

The contract tests do not cover this. The harness persistence suites have no test of file or test data, and this repository runs them with enable_persistence_tests: 'false'; the contract test service has no persistent store support. A separate change enables them, and the harness gains tests of these cases.

This is the dotnet-server-sdk-v9 version of #389. It differs only in the TestData default: on main, TestData stays persisted by default and ShouldPersist(false) opts out; for the next major version it is not persisted by default, like the file data source. The file data source builder conflicts with the shared file data engine from #376 only in its using directives, in where the new method sits, and in where the file data source builds its data set.

Found in review, not changed here

A multi-agent review of this change found three gaps in code it does not change. Java has the same three:

  • TXNS 1.4.3.1: with an infinite cache TTL, a store recovery before the first payload takes the cache-based branch of PollAvailabilityAfterOutage and writes an empty data set. Consul's Init deletes every key under the prefix that is not in the data, so this empties a shared Consul store.
  • TXNS 1.3.5: when a shared store rejects a delta item because it already holds that version or a newer one, WriteThroughStore stops applying the rest of the delta and throws, so the SDK reports a store error and skips the flag change events.
  • TXNS 1.4.3.3: the recovery write back is not serialized with concurrent updates, so a newer item that this SDK writes during it can be replaced by the older snapshot.

Opened from termag

SDK-3493


Note

Overview
The FDv2 data system now honors each data source’s persist decision instead of writing every initializer/synchronizer payload (and post-outage memory snapshots) into a read-write persistent store. File and TestData default to not persisting; LaunchDarkly streaming/polling, FDv1 fallback, and custom sources still persist unless they opt out.

ChangeSet and FullDataSet carry an internal ShouldPersist flag. WriteThroughStore and PersistentStoreWrapper skip persistent writes and recovery sync when that flag is false. IDataSourcePersistence on configurers plus flags on file/test payloads (and DataSourceUpdatesV2ToV1Adapter logic) set the flag end-to-end; FileDataSourceBuilder.ShouldPersist and TestData.ShouldPersist opt in explicitly.

Contract-test support adds file/test data synchronizers, updateTestData, and capabilities file-data-source, test-data-source, data-source-persist-opt-in. Broad unit/integration tests cover stores, recovery, and mixed initializer/synchronizer sequences.

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

…ersistent store

The FDv2 data system wrote the data of every initializer and synchronizer to a
persistent store in read-write mode, and wrote the memory store back after a
store outage. The data system spec requires each source to state whether its
data is persisted (requirements 1.1.7 and 1.2.8), so that, for example, file
data does not replace the LaunchDarkly data in a shared store.

Change sets and full data sets now carry an internal persist flag. The write-
through store writes a change set to the persistent store only if the flag is
set, the memory store remembers the flag of the data it holds, and store
recovery leaves the persistent store as it is when the memory store holds data
that must not be persisted.

An FDv1-style source states its flag on its configurer, and the data system
applies it to the source's full data sets and upserts alike:

- The file data source is not persisted by default. FileDataSourceBuilder.
  ShouldPersist(true) opts in.
- TestData is not persisted by default. TestData.ShouldPersist(true) opts in,
  and covers later updates as well as the initial data. Before this change,
  TestData was persisted.
- FDv2 polling and streaming, the FDv1 fallback synchronizer, and custom data
  sources are persisted, as before.

The FDv1 data system is unchanged: its data store receives all data.
@kinyoklion

Copy link
Copy Markdown
Member Author

bugbot review

1 similar comment
@kinyoklion

Copy link
Copy Markdown
Member Author

bugbot review

The transactional persistent store spec (requirement 1.4.3.2) has the data
system track a single, most recent persistence indicator, and requires the
write back whenever that indicator allows it (requirement 1.4.3). The memory
store let a partial payload only clear its flag, so a persisted delta on a
basis that was not persisted would have skipped the write back. Use the flag
of the latest change set, as the spec, Java and Go do.

@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 Bugbot comment from a previous run.

@kinyoklion
kinyoklion marked this pull request as ready for review October 30, 2026 23:49
@kinyoklion
kinyoklion requested a review from a team as a code owner October 30, 2026 23:49
… wraps theirs

The data system read the persistence flag only from the configurer it was
given, so an application configurer that delegates to FileData.DataSource()
made file data persisted again. The file and test data sources now also put
the flag on the full data sets they deliver. The adapter persists a full data
set only if both its configurer and the data set allow it, and an upsert
takes the flag of the last full data set, the data it changes.

Also from the review of this change:
- The TestData docs said a change to ShouldPersist applies to clients created
  after it. The data system reads it each time it starts the source, which a
  running client also does.
- The mixed-sequence test now checks the store's Init count: the mock store's
  Init replaces all its data, so the old assertion could not fail.
- WriteThroughStore.Upsert says why it ignores the flag, the recovery skip is
  logged at Info, and the read-write mode docs name the FDv1 fallback, custom
  data sources and the write back after an outage.
@kinyoklion

Copy link
Copy Markdown
Member Author

bugbot review

@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 Bugbot comment from a previous run.

… the calling source

The translator marked every change set it produced as persistable, a decision that belongs to the source. The data system applies FDv2 change sets as they are, so for those sources the value is the only persistence control, and a future source that reused the translator would have persisted its data without declaring it. ToChangeSet now takes shouldPersist as a required argument, and the streaming and polling sources pass true at their call sites, as Java's translator does.
kinyoklion added a commit that referenced this pull request Nov 6, 2026
<!-- TERMAG_PR_BODY_BEGIN -->
## Summary

The server SDK's contract test service had no persistent store support:
the data system store configuration in `SdkClientEntity.cs` was
commented out with a TODO about the store packages, and the FDv1
`persistentDataStore` configuration was not handled. CI therefore ran
both harness versions with `enable_persistence_tests: 'false'`. This
change makes the service drive real Redis, DynamoDB, and Consul stores
and runs the persistence suites in CI.

It is separate from the persistence fix in #390 (and #389 on `main`),
which these tests do not cover yet; the harness gains tests for that
behavior in a separate change.

## Test service

- The FDv2 `dataSystem.store` and `storeMode` configuration (harness v3)
and the FDv1 top-level `persistentDataStore` configuration (harness v2)
build the store with `Components.PersistentDataStore`, with the
requested prefix and cache mode.
- An FDv1 configuration with a store and no streaming, polling, or
service endpoint configuration runs in daemon mode
(`Components.ExternalUpdatesOnly`), which the v2 suite expects. Without
this, the client tried to reach LaunchDarkly and failed to initialize.
- An empty prefix means the store's default prefix, and a store
configuration without a DSN is rejected.
- The Redis and DynamoDB clients fail fast (500 ms timeouts, no DynamoDB
retries), as the store recovery tests require. The Consul client does
not retry.
- The service advertises `persistent-data-store-redis`,
`persistent-data-store-dynamodb`, `persistent-data-store-consul`, and
`persistent-data-store-recovery`.
- The service already takes its port as an optional first argument; CI
now passes one. Its default stays 8000.

### Building against the local SDK

The store projects in `pkgs/` reference the published
`LaunchDarkly.ServerSdk` package, so a reference to them would bring a
second copy of the SDK into the service. Instead, a small project per
store under `contract-tests/Stores/` compiles that store's sources
against the SDK project, with the same client library and version range
as the store's own project. There is one project per store because the
Redis and DynamoDB stores share internal type names. The store projects
themselves are not changed, and neither are their packages or their
builds.

On this branch the SDK is 9.0.0-alpha, outside the stores' published
range (`[8.0.0, 9.0.0)`); the stores build and pass against it from
their sources.

## CI

- `.github/actions/contract-tests` gains `enable_persistence_tests`
(default `false`) and `test_service_port` (default `8000`). With
persistence enabled, it starts the stores with
`launchdarkly/gh-actions/actions/persistent-stores`, waits until they
accept connections and Consul has a leader, and enables the tests in
both harness runs.
- The server SDK workflow enables the persistence tests on the Linux
runner only, where the stores start in Docker, and passes port 9000 on
every runner: the harness expects DynamoDB on port 8000, the service's
default. The client SDK workflow uses the same action with the default
port, because its test service always listens on 8000.

## Suppressed tests

The persistence suites found three pre-existing defects in the store
integrations. They are suppressed with a comment in each suppression
file. The harness reads every non-blank line as a test ID, so a line
that starts with `#` matches no test.

1. A deleted flag is stored without a `"key"` property:
`{"version":N,"deleted":true}`, from the `ItemDescriptor` serializer in
`DataStoreTypes.cs` (Redis and Consul store that string), or as the
placeholder `"null"` in the item attribute
(`DynamoDBDataStoreImpl.MarshalItem`). The harness expects a JSON
tombstone with a `key` property, the item key or `$deleted`. This fails
`read-write/data source deletions respect versioning` for each store
(both harness versions) and, in v3, the five store recovery tests that
check a deleted flag after the write back. With a one-line serializer
change that writes `"key": "$deleted"`, the Redis and Consul tests pass,
and the recovery write back itself works; DynamoDB needs its own fix.
2. `ConsulDataStoreImpl.GetAllAsync` iterates `result.Response`, which
is null when no key has the collection's prefix, so reading an empty
collection throws. This fails `collection cardinality/collection holds
no flags` for Consul.

These need SDK and store changes, which this PR does not make. For the
keyless tombstone, the v3 harness's own tombstone suite lists
`{"version":N,"deleted":true}` as a shape that .NET, Java, and Node
write and that readers must accept, so for Redis and Consul the fix may
belong in the harness's read-write matcher instead. DynamoDB's `"null"`
placeholder is not one of the accepted shapes. Until one of these lands,
CI does not check the store write back after recovery or the store side
of deletions for any store; the only recovery test that runs checks
evaluations from memory during the outage.

## Testing

With Redis, DynamoDB local, and Consul running in Docker on their
default ports:

- Harness v2 (2.41.1), full suite with persistence enabled and the
suppression file: all tests passed (4989 ran).
- Harness v3 (3.2.0-alpha.15, from `v3` at 58f4122), full suite with
persistence enabled and the FDv2 suppression file: all tests passed
(5174 ran).

Without the suppressions, the persistence suites fail exactly the tests
listed above (4 in v2, 19 in v3).

After the review changes (the store projects, the port default, the
readiness wait), both persistence suites pass again with the
suppressions (v3: 141 ran; v2: 111 ran), and
`LaunchDarkly.ServerSdk.sln` builds with no errors.

This is the `dotnet-server-sdk-v9` version of #391.
<!-- TERMAG_PR_BODY_END -->

<!-- termag: box=i-0575d1c54853058d7 project=Overrides -->
<sub>Opened from termag</sub>

[SDK-3493](https://launchdarkly.atlassian.net/browse/SDK-3493)
<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> **Enables the SDK test harness’s persistent-store suites in CI** by
wiring the contract test service to real Redis, DynamoDB, and Consul
integrations and extending the shared contract-test GitHub Action.
> 
> The contract test service now maps harness **FDv1
`persistentDataStore`** and **FDv2 `dataSystem.store`** into
`Components.PersistentDataStore` (Redis, DynamoDB, Consul) with
prefix/cache options, **500 ms fail-fast** client settings for recovery
tests, and **daemon mode** (`ExternalUpdatesOnly`) when a store is
configured without streaming/polling. It advertises the new persistence
capabilities. **Wrapper projects under `Stores/`** compile each
integration’s sources against the in-repo SDK so CI does not pull a
second published SDK copy.
> 
> **CI:** `enable_persistence_tests` and `test_service_port` are plumbed
through the composite action; when enabled it starts stores, waits on
ports **6379/8000/8500** and Consul leadership, and launches the service
on a non-8000 port (DynamoDB local uses 8000). **Server SDK workflow**
turns persistence on **Linux only** and uses port **9000**.
> 
> **Known integration gaps** are temporarily **skipped** via suppression
entries (deletion tombstone shape without `"key"`, DynamoDB `"null"`
deletes, Consul empty collection reads)—CI still runs the rest of the
persistence suites.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
8f77f3f. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

[SDK-3493]:
https://launchdarkly.atlassian.net/browse/SDK-3493?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
kinyoklion added a commit that referenced this pull request Nov 6, 2026
<!-- TERMAG_PR_BODY_BEGIN -->
## Summary

The server SDK's contract test service had no persistent store support:
the data system store configuration in `SdkClientEntity.cs` was
commented out with a TODO about the store packages, and the FDv1
`persistentDataStore` configuration was not handled. CI therefore ran
both harness versions with `enable_persistence_tests: 'false'`. This
change makes the service drive real Redis, DynamoDB, and Consul stores
and runs the persistence suites in CI.

It is separate from the persistence fix in #389 (and #390 on
`dotnet-server-sdk-v9`), which these tests do not cover yet; the harness
gains tests for that behavior in a separate change.

## Test service

- The FDv2 `dataSystem.store` and `storeMode` configuration (harness v3)
and the FDv1 top-level `persistentDataStore` configuration (harness v2)
build the store with `Components.PersistentDataStore`, with the
requested prefix and cache mode.
- An FDv1 configuration with a store and no streaming, polling, or
service endpoint configuration runs in daemon mode
(`Components.ExternalUpdatesOnly`), which the v2 suite expects. Without
this, the client tried to reach LaunchDarkly and failed to initialize.
- An empty prefix means the store's default prefix, and a store
configuration without a DSN is rejected.
- The Redis and DynamoDB clients fail fast (500 ms timeouts, no DynamoDB
retries), as the store recovery tests require. The Consul client does
not retry.
- The service advertises `persistent-data-store-redis`,
`persistent-data-store-dynamodb`, `persistent-data-store-consul`, and
`persistent-data-store-recovery`.
- The service takes its port as an optional first argument, as on
`dotnet-server-sdk-v9`. Its default stays 8000.

### Building against the local SDK

The store projects in `pkgs/` reference the published
`LaunchDarkly.ServerSdk` package, so a reference to them would bring a
second copy of the SDK into the service. Instead, a small project per
store under `contract-tests/Stores/` compiles that store's sources
against the SDK project, with the same client library and version range
as the store's own project. There is one project per store because the
Redis and DynamoDB stores share internal type names. The store projects
themselves are not changed, and neither are their packages or their
builds.

## CI

- `.github/actions/contract-tests` gains `enable_persistence_tests`
(default `false`) and `test_service_port` (default `8000`). With
persistence enabled, it starts the stores with
`launchdarkly/gh-actions/actions/persistent-stores`, waits until they
accept connections and Consul has a leader, and enables the tests in
both harness runs.
- The server SDK workflow enables the persistence tests on the Linux
runner only, where the stores start in Docker, and passes port 9000 on
every runner: the harness expects DynamoDB on port 8000, the service's
default. The client SDK workflow uses the same action with the default
port, because its test service always listens on 8000.
- The nightly enables them too, also with port 9000.

## Suppressed tests

The persistence suites found three pre-existing defects in the store
integrations. They are suppressed with a comment in each suppression
file. The harness reads every non-blank line as a test ID, so a line
that starts with `#` matches no test.

1. A deleted flag is stored without a `"key"` property:
`{"version":N,"deleted":true}`, from the `ItemDescriptor` serializer in
`DataStoreTypes.cs` (Redis and Consul store that string), or as the
placeholder `"null"` in the item attribute
(`DynamoDBDataStoreImpl.MarshalItem`). The harness expects a JSON
tombstone with a `key` property, the item key or `$deleted`. This fails
`read-write/data source deletions respect versioning` for each store
(both harness versions) and, in v3, the five store recovery tests that
check a deleted flag after the write back. With a one-line serializer
change that writes `"key": "$deleted"`, the Redis and Consul tests pass,
and the recovery write back itself works; DynamoDB needs its own fix.
2. `ConsulDataStoreImpl.GetAllAsync` iterates `result.Response`, which
is null when no key has the collection's prefix, so reading an empty
collection throws. This fails `collection cardinality/collection holds
no flags` for Consul.

These need SDK and store changes, which this PR does not make. For the
keyless tombstone, the v3 harness's own tombstone suite lists
`{"version":N,"deleted":true}` as a shape that .NET, Java, and Node
write and that readers must accept, so for Redis and Consul the fix may
belong in the harness's read-write matcher instead. DynamoDB's `"null"`
placeholder is not one of the accepted shapes. Until one of these lands,
CI does not check the store write back after recovery or the store side
of deletions for any store; the only recovery test that runs checks
evaluations from memory during the outage.

## Testing

With Redis, DynamoDB local, and Consul running in Docker on their
default ports:

- Harness v2 (2.41.1), full suite with persistence enabled and the
suppression file: all tests passed (4989 ran).
- Harness v3 (3.2.0-alpha.15, from `v3` at 58f4122), full suite with
persistence enabled and the FDv2 suppression file: all tests passed
(5095 ran).
- After moving the port to the first argument: both persistence suites
with the service on port 9000 passed.

Without the suppressions, the persistence suites fail exactly the tests
listed above (4 in v2, 19 in v3).

After the review changes (the store projects, the port default, the
readiness wait), both persistence suites pass again with the
suppressions (v3: 141 ran; v2: 111 ran), and
`LaunchDarkly.ServerSdk.sln` builds with no errors.

#392 makes the same change on `dotnet-server-sdk-v9`.
<!-- TERMAG_PR_BODY_END -->

<!-- termag: box=i-0575d1c54853058d7 project=Overrides -->
<sub>Opened from termag</sub>

[SDK-3493](https://launchdarkly.atlassian.net/browse/SDK-3493)
<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Enables **persistent store contract tests** in CI by wiring the server
SDK contract test service to real Redis, DynamoDB, and Consul, and
turning those suites on in GitHub Actions.
> 
> The contract test service now builds Redis, DynamoDB, and Consul
integrations from in-repo sources (via `Stores/*` wrapper projects)
against the local SDK, implements `CreatePersistentDataStore` for
harness FDv1 `persistentDataStore` and FDv2 `dataSystem.store`, supports
**daemon mode** when a store is configured without streaming/polling,
advertises the new store capabilities, and accepts an **optional listen
port** (9000 in CI so DynamoDB can use 8000). Store clients use short
timeouts for recovery tests.
> 
> The **contract-tests** composite action gains
`enable_persistence_tests` and `test_service_port`, starts stores and
waits for readiness when enabled, and forwards those flags to both
harness runs. **sdk-server-ci** runs persistence tests on Linux only;
**nightly** always enables them with port 9000.
> 
> Known failures from **pre-existing tombstone / empty-collection bugs**
in the store integrations are listed in `test-supressions*.txt` so CI
stays green until separate fixes land.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
fd9c0d6. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

[SDK-3493]:
https://launchdarkly.atlassian.net/browse/SDK-3493?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
kinyoklion added a commit to launchdarkly/sdk-test-harness that referenced this pull request Nov 6, 2026
<!-- TERMAG_PR_BODY_BEGIN -->
## Summary

The data system spec requires each data source to state whether its data
is persisted (requirements 1.1.7 and 1.2.8 of
`DATASYSTEM-data-system/v2`). Its example is the file initializer, which
does not persist: file data must not replace the LaunchDarkly data in a
store that other SDK instances read. The persistence suites had no test
of this. This change adds tests for the file data source and for the
SDK's test data source, which is not persisted by default either.

## Service spec

Three new capabilities, all optional:

- `file-data-source`: a `file` object in a `dataSystem.initializers` or
`dataSystem.synchronizers` entry, with `filePaths`, configures the SDK's
file data source. The harness writes the files on the shared filesystem,
as for override files, and changes a file by rewriting it in place,
which is not atomic: the data source must not serve a partly written
file, and must end up with the complete content. As a synchronizer, the
data source reloads the files within ten seconds of a change.
- `test-data-source`: a `testData` object in one
`dataSystem.synchronizers` entry, with `flags` mapping each flag key to
a value, configures the SDK's test data source; each flag serves its
value to every context. The new `updateTestData` command changes one
flag. An SDK whose test data source is persisted by default must not
declare this capability.
- `data-source-persist-opt-in`: `persist: true` on a `file` or
`testData` object requests persistence.

## Tests

New tests under `persistent data store/<store>/data source persistence`,
so they need a store capability and `-enable-persistence-tests`, like
the rest of the persistence suite:

- `file data` (`file-data-source`):
- An initializer, and a synchronizer including a reload, leave the store
unchanged: both an empty store and one seeded with LaunchDarkly data.
- File data from a synchronizer does not replace the LaunchDarkly data
that the SDK itself wrote from a polling initializer.
- A LaunchDarkly basis after a file initializer is written to the store.
The streaming synchronizer holds its response until the test has checked
that the store is still empty, because the basis would otherwise replace
file data that the SDK wrongly wrote and hide the write.
- Store recovery (`persistent-data-store-recovery`): with file data in
memory last, the SDK does not write it back to the store after an outage
(TXNS requirement 1.4.3.2). An SDK detects an outage only when a store
operation fails, and it never writes file data, so the test holds a
LaunchDarkly polling initializer's response until the store is
unreachable; the SDK's write of that basis fails, and the file
synchronizer's data follows.
- With persistence requested (`data-source-persist-opt-in`): an
initializer's data and a synchronizer's reload are written, and a
read-only store is still not written.
- `test data` (`test-data-source`):
- The initial data and an update leave the store unchanged, empty or
seeded.
- With persistence requested: the initial data and an update are
written.

`RedisPersistentStore.Get` now reports a missing key as no value without
an error, as the Consul and DynamoDB stores do. Every existing caller
already ignored the error.

## Verification

- Against the .NET server SDK on `dotnet-server-sdk-v9`, with the
persistence fix (launchdarkly/dotnet-core#390), persistent store support
in its test service (launchdarkly/dotnet-core#392), and the new
capabilities (launchdarkly/dotnet-core#393): all the new tests pass for
Redis, DynamoDB, and Consul.
- Each of these defects, put into the .NET SDK one at a time, fails the
tests that target it, for every store:
- The write-through store's persistence check removed: the tests of data
that must not be persisted.
- Upserts always persisted, as Java's FDv1 adapter does: the test data
update test.
- The recovery write back done whatever the persistence indicator: the
store recovery test.
- Persisting everything once anything was persisted: the
file-after-LaunchDarkly test.
- The store mode ignored for data that requests persistence: the
read-only store test.
- `make lint` reports no issues, and the data source tests pass three
times in a row against the .NET service with the in-place rewrites.

No other SDK declares the new capabilities yet. The Go, Python, and Ruby
SDKs write synchronizer data to the store whatever its persist flag, so
their file synchronizer and test data tests would fail. The Node SDK
does not mirror conditionally yet (`TransactionalFeatureStore.ts`,
`TODO: SDK-1047`), so its file initializer test would fail too. Java's
test data sources are persisted by default, so it cannot declare
`test-data-source`, though its file data sources could declare
`file-data-source`.
<!-- TERMAG_PR_BODY_END -->

<!-- termag: box=i-0575d1c54853058d7 project=sdk-test-harness -->
<sub>Opened from termag</sub>

[SDK-3493](https://launchdarkly.atlassian.net/browse/SDK-3493)
<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Adds **contract coverage and service-spec support** for which data
sources write to a shared persistent store in read-write mode, matching
the data-system persist opt-in rules.
> 
> **Service spec** documents three optional capabilities
(`file-data-source`, `test-data-source`, `data-source-persist-opt-in`),
`file` / `testData` entries on `dataSystem` initializers and
synchronizers (with optional `persist`), the `updateTestData` command,
and clarifies that **store recovery write-back** and **read-write
`storeMode`** apply only to sources that request persistence.
> 
> **Harness** wires a new **`data source persistence`** sub-suite under
server-side persistent-store tests: file initializer/synchronizer
(including reloads and outage recovery), test-data updates, coexistence
with LaunchDarkly-written store data, and opt-in persistence plus
read-only store behavior. Helpers add shared **`DataSourceFile`**
fixtures (non-atomic in-place rewrites) and SDK config/command plumbing.
**`RedisPersistentStore.Get`** now treats a missing key as absent
without error, consistent with other store backends.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
8775a41. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

[SDK-3493]:
https://launchdarkly.atlassian.net/browse/SDK-3493?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
kinyoklion added a commit that referenced this pull request Nov 10, 2026
…ersistent store (#389)

<!-- TERMAG_PR_BODY_BEGIN -->
## Summary

In the FDv2 data system with a persistent store in read-write mode, the
SDK wrote the data of every initializer and synchronizer to the store,
and wrote all of the memory store back to it after an outage. A file
data source used as an initializer or synchronizer therefore replaced
the LaunchDarkly data in a shared Redis, DynamoDB, or Consul store, on
start, on every reload, and again on every store recovery.

The data system spec requires each data source to say whether its data
may be persisted, and the SDK to mirror only that data: requirement
1.1.7 for initializers and 1.2.8 for synchronizers
(`specs/DATASYSTEM-data-system/v2/README.md`). Its example is the file
initializer, which does not persist. The decision is not based on the
payload selector, because the FDv1 fallback synchronizer has no selector
and its data must still be persisted (the spec's definition of a basis
notes that neither a file data source nor the FDv1 fallback synchronizer
can provide one).

The Java SDK is the complete reference implementation, and this change
follows its design, with one difference described below.

## How it works

- `ChangeSet` and `FullDataSet` carry an internal persist flag. It is
stored inverted, so that a defaulted struct, or one built with an
existing constructor, means "persist". The public API of both types is
unchanged.
- `WriteThroughStore` writes a full data set or a change set to the
persistent store only if its flag is set. Data that is not persisted
still goes to the memory store, which becomes the store that evaluations
read from, as before.
- `InMemoryDataStore` remembers the flag of the latest full or partial
change set and returns it from `ExportAll`. Like the transactional
persistent store spec (requirement 1.4.3.2), it tracks a single, most
recent indicator, not one per item.
- `PersistentStoreWrapper.PollAvailabilityAfterOutage` skips the write
when the exported data must not be persisted. The store still reports
that it has recovered, and keeps its contents.
- `DataStoreSorter` keeps the flag when it sorts a data set or change
set.

### How a data source states its flag

FDv2 polling and streaming declare that their data may be persisted when
they translate a change set: `FDv2ChangeSetTranslator.ToChangeSet` takes
the flag as a required argument, as Java's translator does, and both
sources pass `true`. The data system applies FDv2 change sets as they
are, so that argument is the only persistence control for them.

Every other source is an FDv1-style source run through
`DataSourceUpdatesV2ToV1Adapter`. An FDv1 `Upsert` call has no data set
that could carry a flag. So the data system reads the flag from the
source's configurer each time it builds the source, through the internal
interface `IDataSourcePersistence`, and gives it to the adapter. A
configurer that does not implement the interface is persisted.

The file and test data sources also put the flag on the full data sets
they deliver, so that their data stays out of the store when an
application's own configurer wraps theirs and hides the interface. The
adapter persists a full data set only if both the configurer and the
data set allow it, and an upsert takes the flag of the last full data
set, the data it changes.

This is where the change differs from Java. Java's adapter copies the
flag from the full data set but always sets it on upserts, so a Java
`TestData` configured with `shouldPersist(false)` keeps its initial data
out of the store but writes every later update to it. After one update
the memory store's flag says "persist", so the next store recovery
writes the initial data as well.

### Defaults

| Source | Persisted |
|---|---|
| FDv2 polling and streaming | yes |
| FDv1 fallback synchronizer (`DataSystemComponents.FDv1Polling()`) |
yes |
| A custom data source | yes, as before |
| `FileData.DataSource()` | no;
`FileDataSourceBuilder.ShouldPersist(true)` opts in |
| `TestData` | yes, as before; `TestData.ShouldPersist(false)` opts out
|

The FDv1 data system is unchanged: its data store, persistent or not,
receives all data, including the file data source's. The flag is read
only by the FDv2 data system.

**Behavior change:** an application that uses the file data source as an
FDv2 initializer or synchronizer with a read-write persistent store no
longer has the file data written to the store.
`FileDataSourceBuilder.ShouldPersist(true)` restores that.

### Mixed sequences

- A file initializer followed by a persisted synchronizer's basis: the
basis is written to the store and replaces whatever the store held, and
a recovery after it writes the memory store.
- A delta whose flag differs from the basis it applies to: the
write-through store writes or skips each change set by its own flag, and
recovery follows the flag of the latest change set, as the spec says. A
persisted delta can only follow a basis that was not persisted if a
source sends a delta without a basis of its own. A file source never
sends deltas, `TestData` starts with a full data set, and an FDv2
synchronizer that follows a basis without a selector (the file and test
data sources provide none) requests a full transfer.

## Testing

- `FDv2DataSystemPersistenceTest` runs real clients against a mock
persistent store, for each case:
  - A file initializer is not written.
  - A file synchronizer's reload is not written.
  - File data with `ShouldPersist(true)` is written.
  - `TestData` is written by default, initial data and updates.
- `TestData` with `ShouldPersist(false)` is written neither for its
initial data nor for an update.
  - A custom FDv1-style data source is written.
  - The FDv1 fallback synchronizer's data is written.
- A persisted synchronizer basis after a file initializer is written,
and the file data is not; the store's `Init` count shows it, because the
mock store's `Init` replaces all of its data.
- A file data source or `TestData` behind an application's own wrapping
configurer is not written.
- The FDv1 data system with a file data source still writes to the
store.
- Unit tests for the write-through store, the memory store's flag of the
latest change set, recovery with data that must not be persisted and
with persisted data that replaced it, the adapter, the sorter, and the
flag on FDv2 polling and streaming change sets.
- To check that the tests detect the defects they target, each of
thirteen parts of the fix was reverted on its own, and every reversion
failed at least one test:
  - The write-through check.
  - The adapter's upsert flag, reverted to Java's behavior.
  - The recovery skip.
  - The memory store's flag for partial payloads.
  - Reading the configurer's flag.
  - The sorter.
  - The `TestData` flag.
  - The file data default.
  - The flag on the file data source's data set.
  - The flag on `TestData`'s data set.
  - The adapter's use of the data set's flag.
  - The upsert's use of the last data set's flag.
  - The memory store's update of the flag on a partial payload.
- The full server SDK test suite passes on net8.0 (1697 tests). The SDK
builds for netstandard2.0, net462, and net8.0.

The contract tests do not cover this. The harness persistence suites
have no test of file or test data, and this repository runs them with
`enable_persistence_tests: 'false'`; the contract test service has no
persistent store support. A separate change enables them, and the
harness gains tests of these cases.

#390 makes the same change on `dotnet-server-sdk-v9`, where `TestData`
is not persisted by default.

## Found in review, not changed here

A multi-agent review of this change found three gaps in code it does not
change. Java has the same three:

- TXNS 1.4.3.1: with an infinite cache TTL, a store recovery before the
first payload takes the cache-based branch of
`PollAvailabilityAfterOutage` and writes an empty data set. Consul's
`Init` deletes every key under the prefix that is not in the data, so
this empties a shared Consul store.
- TXNS 1.3.5: when a shared store rejects a delta item because it
already holds that version or a newer one, `WriteThroughStore` stops
applying the rest of the delta and throws, so the SDK reports a store
error and skips the flag change events.
- TXNS 1.4.3.3: the recovery write back is not serialized with
concurrent updates, so a newer item that this SDK writes during it can
be replaced by the older snapshot.
<!-- TERMAG_PR_BODY_END -->

<!-- termag: box=i-0575d1c54853058d7 project=dotnet-core -->
<sub>Opened from termag</sub>


[SDK-3493](https://launchdarkly.atlassian.net/browse/SDK-3493)

[SDK-3493]:
https://launchdarkly.atlassian.net/browse/SDK-3493?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
…act test service (#393)

<!-- TERMAG_PR_BODY_BEGIN -->
## Summary

The test harness gains tests that a file data source and a test data
source do not write their data to a persistent store, and that they do
when they request it (launchdarkly/sdk-test-harness#537). This change
lets the server SDK's contract test service run them, on
`dotnet-server-sdk-v9`, where `TestData` is not persisted by default
(#390).

- A `file` entry in `dataSystem.initializers` or
`dataSystem.synchronizers` configures `FileData.DataSource()` with the
given file paths. As a synchronizer it reloads the files when they
change (`AutoUpdate(true)`).
- A `testData` synchronizer configures a `TestData` source whose flags
each serve one value to every context (`ValueForAll`), and the
`updateTestData` command changes one of its flags. A configuration may
have one `testData` synchronizer, and no `testData` initializer, as the
service spec says.
- A `file` entry needs at least one file path, and `updateTestData`
needs a flag key; the service rejects the configuration or the command
otherwise.
- `persist: true` on either entry calls `ShouldPersist(true)`.
- The service advertises `file-data-source`, `test-data-source`, and
`data-source-persist-opt-in`.

`BuildSdkConfig` and `CreateSynchronizer` become instance methods, so
that the client entity keeps its test data source for the command.

## Dependencies

- This branch is based on #390, which adds `ShouldPersist` to
`FileDataSourceBuilder` and `TestData`.
- The new tests are in the persistence suite, so they run only with the
persistent store support and the CI changes of #392. Until both land,
the new capabilities have no effect in CI.
- There is no `main` version. On `main`, `TestData` is persisted by
default, so the test data tests, which expect it not to be, would fail
there.

## Testing

Against a local merge of this branch and #392, with Redis, DynamoDB
local, and Consul in Docker, the harness branch's `data source
persistence` tests pass for all three stores.

To check that the tests catch the defects they target, defects were put
into the SDK one at a time, and each failed the tests that target it for
every store: the write-through store's persistence check removed;
upserts always persisted, as Java's FDv1 adapter does; the recovery
write back done whatever the persistence indicator; persisting
everything once anything was persisted; and the store mode ignored for
data that requests persistence.
<!-- TERMAG_PR_BODY_END -->

<!-- termag: box=i-0575d1c54853058d7 project=Overrides -->
<sub>Opened from termag</sub>

[SDK-3493](https://launchdarkly.atlassian.net/browse/SDK-3493)
<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> The .NET server **contract test service** now implements harness
scenarios for **file** and **test data** sources, including optional
persistence to the data store.
> 
> Harness JSON can configure a **`file`** initializer or synchronizer
(paths plus optional `persist`); synchronizers use **auto-reload** on
file changes. A **`testData`** synchronizer seeds flags with
`ValueForAll`, and the new **`updateTestData`** command updates a flag
on the single registered `TestData` instance. Invalid configs (empty
file paths, duplicate testData, missing test data on update) fail fast.
> 
> **`BuildSdkConfig`** / **`CreateSynchronizer`** are instance methods
so each client keeps its `TestData` reference for commands. The status
endpoint advertises **`file-data-source`**, **`test-data-source`**, and
**`data-source-persist-opt-in`**.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
165061a. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

[SDK-3493]:
https://launchdarkly.atlassian.net/browse/SDK-3493?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

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

builder.ShouldPersist(p.Persist.Value);
}
return builder;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

File data source omits YAML parsers

Medium Severity

CreateFileDataSource builds FileData.DataSource() without registering .yaml/.yml parsers. The SDK treats a YAML path with no parser as a configuration error and throws at client creation, so harness file-data tests that use YAML never start. The nearby override builder already registers YamlDotNet for those extensions, and this service already depends on that package.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d19e661. Configure here.

@cursor cursor Bot added the risk:medium label Nov 18, 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 FDv2 write-through and recovery for persistent stores (WriteThroughStore, PersistentStoreWrapper, and TestData/FileDataSourceBuilder defaults), and Cursor Bugbot reported an unresolved finding in the contract-test file data source. 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

@kinyoklion
kinyoklion merged commit 6c9675c into dotnet-server-sdk-v9 Nov 20, 2026
8 of 9 checks passed
@kinyoklion
kinyoklion deleted the rlamb/fdv2-persist-flag-v9 branch November 20, 2026 17: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