Skip to content

fix: Reject an override snapshot that contains a deleted flag or segment - #404

Merged
kinyoklion merged 1 commit into
dotnet-server-sdk-v9from
rlamb/overrides-dotnet-reject-deleted
Nov 20, 2026
Merged

kinyoklion merged 1 commit into
dotnet-server-sdk-v9from
rlamb/overrides-dotnet-reject-deleted

Conversation

@kinyoklion

@kinyoklion kinyoklion commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions (tests ran on net8.0 only; the SDK builds for netstandard2.0, net462 and net8.0)

Related issues

Implements the "reject deleted entries" rule from launchdarkly/sdk-specs#288: Requirements 1.1.1.1 (the override store never holds a deleted item), 1.2.8.1 (the sink rejects a snapshot that contains one, as a whole, and logs it) and 1.3.6.2 (the file source fails a reload whose file has a deleted entry).

Describe the solution you've provided

Before: the override layer stored a deleted item as given. That could be a placeholder from DataKind.Deserialize for "deleted": true, or a definition marked as deleted. The overlay then served it for its key. That hid the LaunchDarkly flag or segment from evaluation, from the flags that depend on it, and from the all-flags state, and listeners were notified of the change. Any source could do this, including a custom one through the public IOverrideSink.

After:

  • OverrideSink.SetOverrides checks every snapshot first. If the snapshot contains a deleted flag or segment, the sink rejects the whole snapshot. The layer keeps its contents, no change notification is sent, and an error is logged that names the kind and the key, for example Ignoring an override snapshot because flag "x" is marked as deleted; .... The sink does not throw, and the IOverrideSink signature is unchanged.
  • OverrideLayer.SetAll also refuses a deleted item (ArgumentException, layer unchanged), so the layer cannot hold one whichever caller reaches it. MarkedCopy no longer mentions placeholders.
  • The file override source already rejected deleted entries in the shared parser. The reload failed and the last good overrides stayed. Its Error line already names the file and the entry: Unable to load flags: error parsing file: flag "x" is marked as deleted; remove the entry instead [<path>]. This PR adds tests for that behavior. Only the parser was covered before.
  • "deleted": false is an ordinary definition and still loads.
  • The ordinary file data source's rejection of deleted entries (feat: Add a shared file data reloader, poller, and watcher #361) is unchanged.
  • Public docs: one sentence each on IOverrideSink.SetOverrides and FileOverrides.Source(). "Flag overrides are currently experimental and subject to change." is still on every public override API.

Tests (replacing MarkedCopyLeavesDeletedItemsAndOtherTypesAlone, which pinned the old behavior):

  • OverrideSinkTest.RejectsASnapshotThatContainsADeletedItem: a theory over a deserialized deleted flag, a deserialized deleted segment, and a flag or segment object marked as deleted. In each case the layer is unchanged (same contents instance), the ordinary entries in the rejected snapshot are not applied, nothing is notified, nothing is thrown, the Error line names the kind and key, and the next valid snapshot applies. There is also a variant with no listeners, and AcceptsDefinitionsThatAreNotDeleted.
  • OverrideLayerTest: FindDeletedItemReportsTheKindAndKey, FindDeletedItemAcceptsDefinitionsThatAreNotDeleted and SetAllRefusesADeletedItemAndKeepsItsContents.
  • LdClientOverridesTest.SnapshotWithADeletedFlagIsRejected: a custom source supplies a deleted LaunchDarkly flag through the public sink. The previous override stays, the LaunchDarkly flag is still evaluated and is still in the all-flags state, and no flag change event fires.
  • FileOverrideSourceTest.ReloadWithADeletedEntryFailsAndKeepsTheOverridesInEffect: covers a deleted flag and a deleted segment. No snapshot reaches the sink, the Error line names the file and the entry, and removing the entry recovers. Also InitialFileWithADeletedEntryLeavesTheLayerEmpty and EntriesWithDeletedFalseLoad.
  • LdClientFileOverridesTest.EditThatAddsADeletedEntryKeepsTheOverridesInEffect: end to end. After the failed edit the client still serves the previous override and the LaunchDarkly flag. Once the entry is removed, the rest of the edit applies.

How I ran them (in pkgs/sdk/server):

  • TESTFRAMEWORK=net8.0 BUILDFRAMEWORKS=net8.0 dotnet test -m:1 test/LaunchDarkly.ServerSdk.Tests.csproj --filter on the Internal.Overrides and Internal.FileLoading namespaces plus LdClientOverridesTest and LdClientFileOverridesTest: 237 passed, 0 failed.
  • The whole server test project on net8.0: 1989 passed, 0 failed.
  • dotnet build -m:1 src/LaunchDarkly.ServerSdk.csproj for all target frameworks: 0 errors, no new warnings.
  • I checked the tests against the code without the sink and layer checks. All the sink tests, the layer SetAll tests and the client-level custom-source test fail there. The file source tests pass there, as expected, because they cover parser behavior that already exists on this branch.

Describe alternatives you've considered

  • Dropping just the deleted entry and applying the rest. The spec requires rejecting the whole snapshot, so the layer is always exactly a snapshot the source supplied. This also matches how the file source treats a file it cannot parse.
  • Throwing from IOverrideSink.SetOverrides. The sink does not throw for any other input, and the spec allows reporting through the log alone.

Additional context

#394 touches FileOverrides.cs and FileOverrideSourceTest.cs near these changes. A trial merge of the two branches is clean.

Opened from termag

SDK-3578


Note

Overview
Rejects override snapshots that include deleted flags or segments instead of storing them and hiding LaunchDarkly data for those keys.

OverrideSink.SetOverrides scans each snapshot with new OverrideLayer.FindDeletedItem logic; if any entry is a deleted placeholder or has "deleted": true, the entire snapshot is dropped, existing overrides stay in place, listeners are not notified, and an error is logged (e.g. flag "x" is marked as deleted). OverrideLayer.SetAll throws ArgumentException on the same condition as a backstop. Entries with "deleted": false still load normally.

Public docs on IOverrideSink.SetOverrides and file overrides note this behavior; file sources already failed parses with deleted entries—tests now cover that path plus client-level custom sources and end-to-end file edits.

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

The override layer held a deleted item as given: a placeholder from
DataKind.Deserialize for "deleted": true, or a definition marked as
deleted. The overlay served it for its key, which hid the LaunchDarkly
flag or segment from evaluation, from the flags that depend on it, and
from the all-flags state.

The sink now rejects such a snapshot as a whole, for every source,
including a custom one: the layer keeps its contents, no change
notification is sent, and an error naming the kind and key is logged.
The layer itself refuses a deleted item. The file override source
already fails a reload whose file has a deleted entry; tests now cover
that the overrides in effect stay and that the log names the file and
the entry.

Spec: launchdarkly/sdk-specs#288, Requirements 1.1.1.1, 1.2.8.1, 1.3.6.2.
@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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit e1ef6a4. Configure here.

@kinyoklion
kinyoklion marked this pull request as ready for review November 10, 2026 19:02
@kinyoklion
kinyoklion requested a review from a team as a code owner November 10, 2026 19:02
kinyoklion added a commit to launchdarkly/sdk-test-harness that referenced this pull request Nov 16, 2026
#599)

<!-- TERMAG_PR_BODY_BEGIN -->
## Summary

launchdarkly/sdk-specs#288 makes a flag or segment marked as deleted
invalid in an override snapshot and in an override file: Requirements
1.1.1.1, 1.2.8.1 and 1.3.6.2. A file that contains one fails the reload
in the same way as a malformed file, so the last good overrides stay in
effect. Before this change, the SDKs did five different things with such
an entry, and no contract test used one.

The hot reload group of the flag overrides suite gains four tests, which
run in both watching and polling mode:

- **file with a deleted flag retains last good overrides**
- **file with a deleted segment retains last good overrides**
- **file with a deleted flag at startup supplies no overrides until it
is corrected**
- **file with a deleted segment at startup supplies no overrides until
it is corrected**

Each file that holds a deleted entry also changes the override of the
evaluated flag. An SDK that dropped only the deleted entry, instead of
discarding the reload, would serve the changed value and fail the test.

The startup tests correct the file afterwards and wait for the
correction to take effect. A source that stops after a failed initial
load fails them.

An entry with `"deleted": false` is an ordinary definition. Every
full-flag override in the suite already carries that property, because
the harness model serializes it, so no new test covers it.

## Results

The `flag overrides` suite, run against each test service:

| Test service | Result |
|---|---|
| go-server-sdk `v7` | all 8 new tests fail: the SDK applies the file
and serves the changed value |
| go-server-sdk launchdarkly/go-server-sdk#510 | 88 ran, all passed |
| js-core launchdarkly/js-core#2187 | 73 ran, all passed |
| java-core launchdarkly/java-core#259 | 48 ran, all passed (the test
service has no listener capabilities) |
| dotnet-core launchdarkly/dotnet-core#404 | 88 ran, all passed |
| python-server-sdk launchdarkly/python-server-sdk#574, sync and async
services | 88 ran on each, all passed |
| ruby-server-sdk launchdarkly/ruby-server-sdk#493 | 88 ran, all passed
|

All 8 new tests ran on every service; none was skipped.

**Related issues**

- launchdarkly/sdk-specs#288
<!-- TERMAG_PR_BODY_END -->

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

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

> [!NOTE]
> **Overview**
> Adds **hot reload contract tests** so override files that include a
flag or segment with `"deleted": true` are treated like **malformed
reloads**: the SDK must keep the last good overrides (or, at startup,
serve **no** overrides until the file is fixed).
> 
> The suite covers **deleted flags and deleted segments** under both
**watching and polling** modes, using a new `docWithDeletedEntry` helper
that pairs a changed `flagValues` entry with a deleted definition so
partial application is detectable.
> 
> After an invalid reload, tests confirm a subsequent valid file still
applies normally.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
cfe421d. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

[SDK-3578]:
https://launchdarkly.atlassian.net/browse/SDK-3578?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
@kinyoklion
kinyoklion merged commit 338d974 into dotnet-server-sdk-v9 Nov 20, 2026
14 of 15 checks passed
@kinyoklion
kinyoklion deleted the rlamb/overrides-dotnet-reject-deleted branch November 20, 2026 17:06
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.

2 participants