Repository navigation
feat: Add experimental support for file-based flag overrides - #303
Conversation
## Summary The OVERRIDE specification marks an evaluation as override-affected when any definition it read came from the SDK's override store: the flag itself, a prerequisite at any depth, or a segment consulted during matching. The evaluation reason carries that marking as a boolean indicator named `overrideAffected`, alongside `inExperiment`, so callers of the variation detail methods can tell such evaluations apart. `EvaluationReason` gains `isOverrideAffected()` and `withOverrideAffected(boolean)`. The latter returns the same instance when the value is unchanged, so the shared static instances stay shared. The indicator takes part in equality and hashing. The JSON representation writes `overrideAffected` only when it is true, and parsing accepts the property. The string representation is unchanged. Flag overrides are currently experimental and subject to change. The server SDK change that sets the indicator depends on the release of this package. [SDK-3246](https://launchdarkly.atlassian.net/browse/SDK-3246) [SDK-3246]: https://launchdarkly.atlassian.net/browse/SDK-3246?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Adds an experimental **`overrideAffected`** flag on `EvaluationReason` so variation-detail callers can see when an evaluation (or a prerequisite/segment it used) drew from the SDK override store. > > **`EvaluationReason`** stores the boolean (default `false`), exposes `isOverrideAffected()` / `withOverrideAffected(boolean)` (identity-preserving when unchanged), and includes it in `equals`/`hashCode` without changing `toString()`. **`EvaluationReasonTypeAdapter`** reads `overrideAffected` from JSON and writes it only when `true`, matching `inExperiment`. Tests cover defaults, copying, equality, and JSON round-trips. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b5deba0. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
…vidual events for them (#219) ## Summary The OVERRIDE specification marks an evaluation as override-affected when any definition it read came from the SDK's override store. Such an evaluation appears in summary events only: it produces no individual feature event and no debug event, whatever the flag's configuration requests, and it is counted in a separate summary counter that carries an `overrideAffected` marker, so override-affected and ordinary evaluations of the same flag, variation, and version are never collapsed together. - `Event.FeatureRequest` carries the marking as a boolean that the SDK sets from its evaluation result. The existing constructors keep working and leave it false; `toDebugEvent()` keeps the value. - `DefaultEventProcessor` keys individual feature event and debug event emission on the marking. Index events and summaries are unchanged. - `EventSummarizer` keeps a second set of counters per flag for marked evaluations, created on first use so unmarked flags pay nothing. `EventOutputFormatter` writes `overrideAffected: true` only on those counters, the same way the `unknown` marker is written. - `EventSummarizerInterface` gains the marker parameter and keeps the previous signature as a default method that delegates with false. Flag overrides are currently experimental and subject to change. The server SDK change that sets the marking depends on the release of this package. [SDK-3246](https://launchdarkly.atlassian.net/browse/SDK-3246) [SDK-3246]: https://launchdarkly.atlassian.net/browse/SDK-3246?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Adds **override-affected** handling for flag evaluations tied to the experimental override store: `Event.FeatureRequest` carries an `overrideAffected` flag (existing constructors default to false). > > **`DefaultEventProcessor`** still summarizes and emits index events, but **suppresses individual feature and debug events** whenever `isOverrideAffected()` is true, regardless of `trackEvents` or debug configuration. > > **`EventSummarizer`** (and aggregated/per-context wrappers) buckets those evaluations in a **separate counter map** per flag so they are not merged with normal counts for the same version/variation; **`EventOutputFormatter`** emits `overrideAffected: true` only on those summary counters. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 0e7744f. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
Brings feat/overrides up to date with main: the 7.18.0 release, CI on the latest v3 contract tests, flag change listener support in the contract test service, and the java-sdk-internal 1.12.1 and 1.12.2 fixes that a common 2.6.0 and internal 1.13.0 release from this branch needs.
<!-- TERMAG_PR_BODY_BEGIN --> ## Update, 2026-12-01 - Rebased onto `feat/overrides`, which has `main` merged into it again. From `main` it gets the 7.19.0 to 7.19.2 releases, `java-sdk-internal` 1.14.0, and the FDv2 fix that leaves out an empty selector (#261). The v3.2.0-alpha.21 contract tests check that fix, so CI failed three FDv2 streaming tests without it. Changes from the review: - The reloader and the poller run on one executor that the caller owns, at the SDK's thread priority. The watcher keeps its own thread. - An unexpected exception from a load is a failed load, and it is retried. An `Error` is logged like any failure but arms no timed retry; the next change reloads. A stack overflow while parsing a file is a parse failure of that file, and a path that is not a regular file fails before it is read. - Every load sets the retry that it asks for, so the retry and its log message always come from the latest load. - The reloader's handler has only the apply callback. The error callback had one implementation, an empty one in #224, because the reloader logs every failure itself. Options that no caller used are gone too: skipping unchanged content is always on, the retry delay must be positive, and every load has a content digest. - The poller Javadoc says to create it before the initial load, and the `reloadNow` Javadoc says that loads run one at a time. #224 now starts change detection before the initial load. - Failure messages no longer quote file content, for the override source and the existing file data source, in the log and in the data source status. Neither keeps the parser's exception as the cause. - A YAML syntax error gives SnakeYAML's problem and position, without the quoted lines. - A JSON syntax error gives Gson's problem and position, without the JSON path, which can hold a value. A malformed `\u` escape also leaves out the characters after `\u`. - A YAML value that cannot be converted to the type that its tag names fails without the value. For the file data source this is now a parse failure, where the exception escaped the loader before. - A string in a number property of an override entry fails without the string, and every data model failure of an override entry names the flag or segment. - YAML files parsed at the same time no longer return each other's documents: each parse has its own `Yaml` instance. The file data source shared the same static instance. - The watcher keeps watching after an unexpected exception. On macOS it removes the overrides of a file whose directory is deleted (tested with a scripted watch service, not run on macOS). It stops watching a directory that no configured link leads into any more. - The watcher Javadoc names what watching does not follow: a configured directory replaced by rename, and a configured link whose target does not exist yet. - The empty JSON file message says how to remove the file's overrides: delete the file or write `{}`. - Verified with the v3.2.0-alpha.21 harness that CI runs, with `common` 2.6.0 and `internal` 1.15.0 published locally from `feat/overrides`: - #220 itself builds against the released libraries, as CI builds it: the server unit tests pass (2180, with the 72 existing skips), and the full v3 contract tests pass (6369 tests ran), including the three FDv2 tests that failed in CI; - every PR in the stack compiles, with Javadoc, at its own head; - the server unit tests pass at the top (2348, with the 72 existing skips); - the full v3 contract tests pass at the top (6457 tests ran). That includes the flag overrides suite and both flag listener suites. ## Update, 2026-11-13 - Rebased onto `feat/overrides`, which now includes #218 and #219 and has `main` merged into it. From `main` it gets the 7.18.0 release, CI on the latest v3 contract tests, flag change listener support in the contract test service, and the `java-sdk-internal` 1.12.1 and 1.12.2 fixes. A common 2.6.0 and internal 1.13.0 release from this branch needs those fixes. - New commit, "fix: Follow symbolic links when watching the override files". In watching mode, the watcher counted only events that named a configured file. A mounted Kubernetes ConfigMap updates its files by swapping a `..data` link, so no event named the file and the update was never picked up. A configured link to a file in another directory wasn't followed either. Polling picked up both, and the Node, .NET, Python and Ruby watchers follow these links. - An event for another entry in a watched directory now counts when a configured file, read through any symbolic link, leads to another file, or its file's modification time or size changed. A busy sibling file still costs no reload. - The directory of each link's final target is watched too, and is found again after every event. One that is deleted, like a ConfigMap's previous version, is dropped instead of being retried with a warning. - New `FileDataWatcherTest` cases cover a ConfigMap update, a change to a link target in another directory, and a link pointed at a file in a third directory. Three mutants each fail at least one of them: other entries never count, target directories aren't watched, and a deleted target directory is retried. - Verified at the top of the stack, with `common` and `internal` published locally from `feat/overrides`: - every PR in the stack compiles, with Javadoc, at its own head; - the server unit tests pass (2285, with the 72 existing skips); - the full v3 contract tests pass (6321 tests). That includes the flag overrides suite, with the deleted-entry tests of launchdarkly/sdk-test-harness#599, and both flag listener suites. ## Summary The flag overrides feature defined by the OVERRIDE specification needs a file source that reloads reliably: coalesced change notifications, retry after a failed read, retention of the last good data, sequential reloads, support for files that do not exist yet, and files that are rewritten in place. This change adds that infrastructure to the integrations package for the file-based override source that follows. The existing file data source keeps its current behavior, apart from the parsing fixes in the 2026-12-01 update. - `FileDataReloader` serializes reloads, debounces change signals with a 100 ms settle window, keeps the last good data on failure by not applying, retries a failed load after one second, reports an identical repeated failure once, and skips a reload whose content did not change. Close never waits for an in-flight read. An exception from the apply callback is reported like any other load failure and retried, and nothing from that load is remembered. A load that holds an emptied file back (below) applies nothing, reports no failure, and arms its retry for the time the loader asks for; a failure still arms the normal retry. The loader is told of every result that becomes the data in effect, applied or skipped as unchanged, through `Loader.accepted`. - `FileDataPoller` detects changes by examining each file's modification time and size on a fixed interval, including a file that appears or disappears. A change callback that throws is logged and polling continues. Its `observe` is package-private, so that the loader reads a file's state the same way, through symbolic links. - `FileDataWatcher` watches parent directories through the file system watch service and signals once after start so a change made between an initial load and the start of watching is not missed. A directory that is missing at start or deleted later is registered again on a one-second schedule once it exists, and one change is signaled so the reload picks up what was written meanwhile. - `OverrideFileLoader` reads a list of files with the override source's rules: a file that does not exist contributes no entries, entries keep the versions that the documents specify, a value-only entry becomes a flag that is on and serves the value by fallthrough, a document that parses but holds a flag the model rejects is reported as a file data error, and the result carries a per-file summary and a content digest of each file's path, whether it exists, and its content. ### Format, encoding and empty files The override loader chooses the parser by the file name: `.yaml` and `.yml`, in any case, are YAML, and any other file, including one with no extension, is JSON. The OVERRIDE spec (requirement 1.3.3, sdk-specs #272) recommends the extension and lets an SDK whose file data source inspects the content keep doing so; the override source is unreleased, so it follows the extension, which lets the format decide whether an empty file is valid. - The text encoding is detected from a byte order mark (UTF-8 or UTF-16) and is UTF-8 otherwise, for both formats, through SnakeYAML's `UnicodeReader`. A UTF-32 file fails to parse, and the last good overrides stay. - An empty or white-space JSON file fails with `the file has no content, which is not a JSON document`, and the last good overrides stay. An empty JSON placeholder therefore fails the whole reload. A JSON document that is not an object, such as `null` or `[]`, fails with `the JSON document is not an object`. - An empty YAML file, or YAML with only a comment or a `---` marker, is a document with no entries. - Compatibility with choosing by content: a JSON file in UTF-16, or in UTF-8 with a byte order mark, still loads. JSON indented with tabs, or with the escape `\/`, loads from a `.json` file; SnakeYAML, which reads YAML 1.1, rejects it in a `.yaml` file. ### In-place rewrites Applications and editors rewrite a file in place: they truncate it and then write the new content. A load in between finds the file empty. A YAML file can legitimately be empty, so its parser cannot tell an emptied file from one in the middle of a rewrite. The loader keeps, for each file, whether it contributed content to the data in effect (updated by `accepted`), and, for a file whose content is in effect and that loads have found empty, since when it has been empty without being written, its state then (modification time and size, read through any symbolic link, compared only for equality), and when a load first held it back. - A file whose content is not in effect, such as a placeholder or a file whose empty state was applied, is parsed right away. - Otherwise a new state restarts the file's delay, and the file is held back while it has stayed empty for less than the retry delay R, and for at most 5 R from the first load that held it back. The clock is read after the file's own read, so a slow read of another file does not shorten its delay. The hold asks for its retry when the first held file's delay or bound is over, plus R/10, so that a timer that fires a little early still finds the time over. - A file's bound starts over only at a load that holds nothing back, for every file that load read, whether the load is applied, skipped as unchanged, or fails. A read with content, even content that fails to parse, or a missing file ends the file's empty state, so its next emptying starts a new delay even where a coarse modification time makes it look the same. - A load reads and classifies every configured file, also after a read or parse failure, so files emptied together start their delays in the same load. It then fails with the first failure; then holds files back; and only then merges the entries, so a duplicate key or an entry that the data model rejects cannot keep a later file from being read. A holding load keeps the data in effect, including changes to the other files, because a reload applies all the files or none. - Elapsed times are differences of `System.nanoTime()` readings, which do not overflow. A rewrite is covered when the gap between truncating and writing is shorter than the retry delay. Not changed: a read that sees YAML cut off between two entries, after `flagValues:`, or inside an unquoted value parses as valid YAML and is applied until the next reload; JSON cut off anywhere fails to parse. Go still detects the format from the content; Node chooses by extension case-sensitively, while this change, like .NET, ignores case. ### The existing file data source `FileDataSourceImpl`, `FileSynchronizer` and `FileInitializer` are unchanged from `feat/overrides`. `FileDataSourceBase` changes only a comment, and `FileDataException.getDescription` no longer throws when there is no cause. `FileDataSourceParsing` gains, for the override source: two `FlagFactory` methods that keep document versions; `selectForPath` and `parseForPath` (extension and encoding); the `NO_DOCUMENT` result that the YAML parser returns for content with no document, which has all-null maps as before; `JsonFlagFileParser.parse(Reader)`; and the two JSON rules above, which the file data source cannot reach because it parses a file as JSON only when it starts with `{`. `parse(InputStream)` keeps reading JSON in the platform's default encoding for the file data source. The file data source still requires every configured file to exist, assigns a load version to every entry, expands a value-only entry to an on flag with a single fallthrough variation, reloads on every watch event with no debounce, no retry timer, and no skip, and reports every failure. Two new test classes pin that behavior: `FileSynchronizerReloadBehaviorTest` (identical rewrite emits another change set, every failed reload is reported and logged as the plain description at error level, no retry without a file change, missing file logged with the path) and `FileDataLoadingBehaviorTest` (a model-rejected document escapes as a `SerializationException`, and `FileDataException.getDescription` shows the cause when there is one). The existing tests pass unmodified. ## Testing - `OverrideFileLoaderTest`, on real files rewritten in place (`InPlaceWrites`), with a test clock that crosses the `long` overflow: the format by extension, empty and non-object JSON, YAML with no document, the encoding (UTF-8 with and without a byte order mark, UTF-16LE and UTF-16BE with one, a non-ASCII value), the hold at 0.95 R and its end at exactly R, the requested retries, a new write restarting the delay (also through a symbolic link), the per-file bound with one file kept written and with files rewritten in turn or emptied in staggered turns, the bound starting over at a load that holds nothing back and not otherwise, a file read during another file's failure, the fix of a file saved with a mistake or a duplicate key, the first failure reported, the digest covering paths and presence. - `FileDataReloaderTest` (scripted loader): a hold applies nothing, reports nothing, and is retried after the time the loader asks for; a failure arms the normal retry delay; `accepted` is called for applied and unchanged results only. - `FileDataReloaderEmptiedFileTest` (the reloader with the real loader on real files): with a test clock and an hour-long retry delay, the hold's end and the requested retry delays on both arming paths; with the real clock, an emptied file held back and the rewrite applied with no empty application in between, a file that stays empty applied by the retry, two quick rewrites, a change to another file while one is empty, a retry finding a second truncation, a file moved between configured paths, the same bytes moved from `.yaml` to `.json`. - The in-place rewrite handling was reviewed in eight rounds as #248 (general and adversarial reviews, Bugbot). Mutation check with a clean build per mutant: 57 mutants, each failing at least one test. The override test classes ran 12 times in a row with no failure. [SDK-3246](https://launchdarkly.atlassian.net/browse/SDK-3246) <!-- TERMAG_PR_BODY_END --> <!-- termag: box=i-0575d1c54853058d7 project=java-core --> <sub>Opened from termag</sub> [SDK-3246]: https://launchdarkly.atlassian.net/browse/SDK-3246?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Adds **reload infrastructure** for the upcoming file-based flag override source: **`FileDataReloader`** (serialized loads, 100ms debounce, 1s retry, content-hash skip, empty-file deferral via `EmptiedFileException`), **`FileDataPoller`** (interval mtime/size polling), **`FileDataWatcher`** (directory watches with symlink/ConfigMap-style updates, missing-directory retry), and **`OverrideFileLoader`** (multi-file merge, extension-based JSON/YAML, UTF BOM detection, in-place rewrite hold-back). > > **Parsing changes** in `FileDataSourceParsing` support overrides: parser selection by `.yaml`/`.yml`, safer error text (no quoted file content in logs), per-parse YAML instances, `NO_DOCUMENT` for comment-only YAML, and `FileDataException.getDescription()` fixed when cause is null. The existing **file data source** behavior is largely unchanged aside from those shared parsing fixes; new tests pin synchronizer reload and loader error semantics. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9e9909b. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
… evaluations (#221) <!-- TERMAG_PR_BODY_BEGIN --> ## Update, 2026-12-03 - `launchdarkly-java-sdk-common` 2.6.0 is released from `main` (#298). Its source is the same as on `feat/overrides`, and the pin is unchanged. - Verified against the Maven Central artifact: this head builds, with the contract test service, and CI passes. ## Update, 2026-12-01 - Rebased onto `feat/overrides`, which has `main` merged into it again. From `main` it gets the 7.19.0 to 7.19.2 releases, `java-sdk-internal` 1.14.0, and the FDv2 fix that leaves out an empty selector (#261). The v3.2.0-alpha.21 contract tests check that fix, so CI failed three FDv2 streaming tests without it. - Rebase conflict in `build.gradle`: `main`'s internal 1.14.0, with this PR's common 2.6.0. - `main` added a `clientSideAvailability` argument to the `FeatureFlag` constructor (#275). The marked copy of a flag now passes it on, so an override keeps the flag's client-side availability. The change is in the first commit, and its test checks it. - Verified with the v3.2.0-alpha.21 harness that CI runs, with `common` 2.6.0 and `internal` 1.15.0 published locally from `feat/overrides`: - every PR in the stack compiles, with Javadoc, at its own head; - the server unit tests pass at the top (2348, with the 72 existing skips); - the full v3 contract tests pass at the top (6457 tests ran). That includes the flag overrides suite and both flag listener suites. ## Update, 2026-11-13 - Rebased onto `feat/overrides`, which now includes #218 and #219 and has `main` merged into it. From `main` it gets the 7.18.0 release, CI on the latest v3 contract tests, flag change listener support in the contract test service, and the `java-sdk-internal` 1.12.1 and 1.12.2 fixes. A common 2.6.0 and internal 1.13.0 release from this branch needs those fixes. - Rebase conflicts with `main`, both resolved by keeping both sides: - `Evaluator.java`: `main`'s #258 keeps the big segments status on an error reason, and this PR marks that result as override-affected. - `build.gradle`: `main`'s `jsr305` and internal 1.12.2, with this PR's common 2.6.0. - Verified at the top of the stack, with `common` and `internal` published locally from `feat/overrides`: - every PR in the stack compiles, with Javadoc, at its own head; - the server unit tests pass (2285, with the 72 existing skips); - the full v3 contract tests pass (6321 tests). That includes the flag overrides suite, with the deleted-entry tests of launchdarkly/sdk-test-harness#599, and both flag listener suites. ## Summary The OVERRIDE specification requires an evaluation to be marked as override-affected when any definition it read carried the override marker: the evaluated flag, a prerequisite at any depth, or a segment consulted during matching, whether or not the segment matched. The marking propagates upward only: a prerequisite's own record reflects only the definitions that its own subtree read, while the evaluation that requested it accumulates the result. An evaluation that fails is still marked when it read a marked definition, and a requested-type mismatch keeps the marking on its error reason, as does the WRONG_TYPE error that `migrationVariation` returns for an unrecognized stage. - `DataModel.FeatureFlag` and `DataModel.Segment` carry a transient `isOverride` marker. It is never serialized and never read from JSON. `markedAsOverride()` returns a shallow copy with the marker set, sharing nested collections and preprocessing with the source and never modifying it. The override layer will use it in the next change. - The evaluator tracks the marking per evaluation scope. The scope starts from its own flag's marker, each segment read can set it, and the value is saved, reset to the prerequisite's own marker, and restored around every prerequisite evaluation. Each result and each prerequisite record carries the marking on its reason. - `EvalResult.isOverrideAffected()` reads the reason's indicator, and `withOverrideAffected(boolean)` returns a copy so that the shared precomputed results are never mutated. - An evaluation that throws returns an `EXCEPTION` result marked with the evaluated flag's own marker, because that definition was read before the failure. - The server SDK now depends on launchdarkly-java-sdk-common 2.6.0, which adds `EvaluationReason.isOverrideAffected()` and the `overrideAffected` JSON property (written only when true). Flag overrides are currently experimental and subject to change. The existing file data source keeps its current behavior; this change does not touch its code paths. [SDK-3246](https://launchdarkly.atlassian.net/browse/SDK-3246) [SDK-3246]: https://launchdarkly.atlassian.net/browse/SDK-3246?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Adds **experimental flag-override tracking** so evaluations can report when they were influenced by local override definitions rather than LaunchDarkly data. > > **FeatureFlag** and **Segment** gain a transient `isOverride` marker (never serialized) and `markedAsOverride()` shallow copies for the override layer to use. The **Evaluator** tracks whether the current scope read any marked flag, prerequisite subtree, or segment (match or not), propagating upward while keeping each prerequisite record scoped to its own subtree. **`EvalResult`** exposes `isOverrideAffected()` and `withOverrideAffected()` via `EvaluationReason` so shared precomputed results stay immutable. > > **InputValidatingEvaluator**, **MigrationStageEnforcingEvaluator**, and `allFlagsState` preserve override marking across type errors, exceptions, and malformed evaluations. Dependency **`launchdarkly-java-sdk-common`** is bumped to **2.6.0** for `EvaluationReason.isOverrideAffected()`. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a2a5c8e. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> <!-- TERMAG_PR_BODY_END --> <!-- termag: box=i-0575d1c54853058d7 project=java-core --> <sub>Opened from termag</sub>
…rce configuration (#222) <!-- TERMAG_PR_BODY_BEGIN --> ## Update, 2026-12-01 - Rebased onto `feat/overrides`, which has `main` merged into it again. From `main` it gets the 7.19.0 to 7.19.2 releases, `java-sdk-internal` 1.14.0, and the FDv2 fix that leaves out an empty selector (#261). The v3.2.0-alpha.21 contract tests check that fix, so CI failed three FDv2 streaming tests without it. - The `@since` tags this PR adds now say 7.20.0, because 7.19.0 to 7.19.2 shipped from `main` without flag overrides. The change is in the existing commit "docs: Give the flag override API the version that will ship it". - `main` replaced the boolean FDv1 fallback argument of `FDv2SourceResult.changeSet` with an `FDv1Fallback` (#278). The override test data source passes `null`, as `main`'s own callers do. The change is in the first commit. - Verified with the v3.2.0-alpha.21 harness that CI runs, with `common` 2.6.0 and `internal` 1.15.0 published locally from `feat/overrides`: - every PR in the stack compiles, with Javadoc, at its own head; - the server unit tests pass at the top (2348, with the 72 existing skips); - the full v3 contract tests pass at the top (6457 tests ran). That includes the flag overrides suite and both flag listener suites. ## Update, 2026-11-13 - Rebased onto `feat/overrides`, which now includes #218 and #219 and has `main` merged into it. From `main` it gets the 7.18.0 release, CI on the latest v3 contract tests, flag change listener support in the contract test service, and the `java-sdk-internal` 1.12.1 and 1.12.2 fixes. A common 2.6.0 and internal 1.13.0 release from this branch needs those fixes. - New commit, "docs: Give the flag override API the version that will ship it". Java 7.18.0 was released from `main` without flag overrides, so the `@since` tags this PR adds now say 7.19.0, the next minor release. - Verified at the top of the stack, with `common` and `internal` published locally from `feat/overrides`: - every PR in the stack compiles, with Javadoc, at its own head; - the server unit tests pass (2285, with the 72 existing skips); - the full v3 contract tests pass (6321 tests). That includes the flag overrides suite, with the deleted-entry tests of launchdarkly/sdk-test-harness#599, and both flag listener suites. ## Summary This adds the override layer that the OVERRIDE specification describes: an override source supplies complete snapshots of flag and segment definitions to an override store, and an overlay at the store read boundary returns the store's entry for a key in preference to LaunchDarkly data. Evaluation, prerequisite and segment resolution, and the all-flags state all read through the overlay, so an override is a full definition that evaluates like any other. Overrides do not take part in the data system: they have no effect on initialization status, data availability, or data source status, and they are never written to a persistent store. Public surface, all marked experimental and subject to change: - `DataSystemBuilder.overrides(ComponentConfigurer<OverrideSource>)` and `DataSystemConfiguration.getOverrideSource()`. The option lives on the FDv2 data system builder only. An FDv1 data source configuration has no place to supply one. - `subsystems.OverrideSource` (start with a sink, close) and `subsystems.OverrideSink` (replace the whole layer with one snapshot). The SDK builds the source like any other component, starts it before the data source so its initial load completes during client construction, and closes it with the client; the sink stops accepting snapshots before the source is closed, and an exception from the source's `close` is logged while the rest of the shutdown proceeds. An offline client does not build or start the override source, and logs a warning that it does not. A source that cannot be built fails client construction the same way other invalid component configuration does. An exception from the source's `start` does not: the SDK logs it, closes the source, clears anything the source supplied before failing, and the client runs without overrides. Internals: - `OverrideLayer` holds marked shallow copies of the supplied entities in an immutable map that is swapped on each update. The source's objects are never modified. - `OverrideOverlayStore` implements the read boundary: per-key reads prefer the layer, enumeration is the union with override precedence, and a failure of the base store propagates, as it does without the overlay. - `OverrideSinkImpl` serializes snapshot application and fires the normal flag change notifications for every flag whose merged-view evaluation may have changed, using the dependency tracker over both the old and the new merged views so prerequisite and segment dependents are included. - The not-initialized short-circuit consults the layer first: a flag that the layer holds is served before the client has LaunchDarkly data, and any other flag returns the client-not-ready default as before. Before the store is initialized, the all-flags state contains only the flags that the layer holds, read from the layer rather than the merged store so that LaunchDarkly data in a store without an init marker stays out, and it logs once that it returned only override entries; with no override flags the state is invalid, as it is without a source. Without a source this state is empty, because the SDK reports no flags before the store is initialized, so the override flags only add to what it reports; overrides never remove a flag from the state. When the store fails to list its flags, the failure is logged as before; the state, invalid and empty without a source, then holds the override layer's flags and stays invalid (empty and invalid when the layer holds no flags), because a client-side SDK bootstrapped from it uses its flags whatever `$valid` says. The all-flags state presents an override-affected flag with `trackEvents` and `trackReason` false and no `debugEventsUntilDate`. The OVERRIDE specification's test vectors run as a unit test through the full client stack (value, variation index, and reason). The per-evaluation summary marker in the vectors is asserted by the events change that follows. This PR depends on the model and evaluator marking change (rlamb/overrides-java-model-marker) and is based on that branch; retarget it to feat/overrides once that branch merges. The existing file data source keeps its current behavior; this change does not touch its code paths. [SDK-3246](https://launchdarkly.atlassian.net/browse/SDK-3246) [SDK-3246]: https://launchdarkly.atlassian.net/browse/SDK-3246?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ ## Follow-ups from review - A LaunchDarkly change now notifies the flags whose overrides depend on it. The override layer keeps the dependency edges of its own entries, rebuilt on every replacement, and `DataSourceUpdatesImpl` expands each changed LaunchDarkly item through both its own tracker and the layer's until nothing new is reached, so an override that matches a LaunchDarkly segment or has a LaunchDarkly prerequisite is notified like the LaunchDarkly flags that depend on it. - `isFlagKnown` consults the override layer before the not-initialized short circuit, the same as evaluation does, so an override-only flag is known while the client is uninitialized. - When the evaluation of a flag throws during `allFlagsState`, the `EXCEPTION` result carries that flag's own override marking, so an overridden flag keeps its marked reason with event tracking off. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Adds an **experimental flag/segment override** path for FDv2 clients so operators can force known definitions without changing initialization or data-source status. > > Configuration wires in `DataSystemBuilder.overrides()` with public `OverrideSource` / `OverrideSink` APIs. When configured, `FDv2DataSystem` builds an `OverrideLayer`, applies snapshots via `OverrideSinkImpl`, and exposes evaluations through `OverrideOverlayStore` (overrides win per key). The override source starts before the main data source; start/close failures are logged and the client can run without overrides. Offline mode skips the override source. > > Evaluation and client behavior are updated so override-backed flags work **before** the client is initialized (`isFlagKnown`, single-flag eval, `allFlagsState` with override-only/bootstrap semantics). Override-affected results carry marking in reasons and **disable** per-flag analytics fields in `FeatureFlagsState`. Flag-change notifications fan out across merged LaunchDarkly + override dependency graphs via `ExternalDependencies` on `DataSourceUpdatesImpl`. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 59f203e. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> <!-- TERMAG_PR_BODY_END --> <!-- termag: box=i-0575d1c54853058d7 project=java-core --> <sub>Opened from termag</sub>
…ide-affected evaluations (#223) <!-- TERMAG_PR_BODY_BEGIN --> ## Update, 2026-12-03 - `launchdarkly-java-sdk-internal` 1.15.0 is released from `main` (#299), and the pin is unchanged. The release has the event changes from #219 that this PR uses. It also keeps the existing `EventSummarizerInterface` method abstract and makes the overload with the override marker the default, so that summarizers outside the library still compile. The server SDK does not use that interface. - Verified against the Maven Central artifacts of common 2.6.0 and internal 1.15.0: this head builds, with the contract test service, and CI passes. ## Update, 2026-12-01 - Rebased onto `feat/overrides`, which has `main` merged into it again. From `main` it gets the 7.19.0 to 7.19.2 releases, `java-sdk-internal` 1.14.0, and the FDv2 fix that leaves out an empty selector (#261). The v3.2.0-alpha.21 contract tests check that fix, so CI failed three FDv2 streaming tests without it. - The pin moves from `java-sdk-internal` 1.13.0 to 1.15.0. Versions 1.13.0 to 1.14.1 were released from `main` without the override changes, so 1.15.0 is the version that a release of internal from `feat/overrides` gets. CI for this PR stays red until that release exists. - The `@since` tag of the new `EventProcessor` method now says 7.20.0, in the existing commit "docs: Give the flag override API the version that will ship it". - Verified with the v3.2.0-alpha.21 harness that CI runs, with `common` 2.6.0 and `internal` 1.15.0 published locally from `feat/overrides`: - every PR in the stack compiles, with Javadoc, at its own head; - the server unit tests pass at the top (2348, with the 72 existing skips); - the full v3 contract tests pass at the top (6457 tests ran). That includes the flag overrides suite and both flag listener suites. ## Update, 2026-11-13 - Rebased onto `feat/overrides`, which now includes #218 and #219 and has `main` merged into it. From `main` it gets the 7.18.0 release, CI on the latest v3 contract tests, flag change listener support in the contract test service, and the `java-sdk-internal` 1.12.1 and 1.12.2 fixes. A common 2.6.0 and internal 1.13.0 release from this branch needs those fixes. - New commit: the `@since` tag of the new `EventProcessor` method now says 7.19.0, because 7.18.0 shipped from `main` without flag overrides. - Rebase conflict in `build.gradle` with `main`'s internal 1.12.2 pin, resolved to this PR's 1.13.0. - Verified at the top of the stack, with `common` and `internal` published locally from `feat/overrides`: - every PR in the stack compiles, with Javadoc, at its own head; - the server unit tests pass (2285, with the 72 existing skips); - the full v3 contract tests pass (6321 tests). That includes the flag overrides suite, with the deleted-entry tests of launchdarkly/sdk-test-harness#599, and both flag listener suites. ## Summary This connects the override-affected marking of an evaluation to analytics events, as the OVERRIDE specification requires. An evaluation that read a definition from the override store, directly or through a prerequisite or a segment, produces no individual feature event and no debug event, whatever the flag's configuration requests. It is still counted in summary events, in a separate counter that carries `overrideAffected: true`, so LaunchDarkly can tell override-affected counts from ordinary counts of the same flag, variation, and version. A prerequisite record carries the prerequisite's own marking: an unaffected prerequisite evaluated inside a marked evaluation still produces its individual event. - `EventProcessor` gains an overload of `recordEvaluationEvent` with the marking. It is a default method that ignores the marking and delegates to the existing method, so a custom implementation keeps compiling and behaving as before. The SDK's implementations override it. - The evaluator's event recorder passes the evaluation result's marking for top-level, prerequisite, and requested-type-mismatch records. An evaluation that throws records its error event with the evaluated flag's own marking, because that definition was read before the failure. Event generation keys on that value alone and does not read the evaluation reason. - The server SDK now depends on launchdarkly-java-sdk-internal 1.15.0, whose event processor suppresses individual events for marked evaluations and splits the summary counters by the marker. - The OVERRIDE specification's vector runner now also asserts the per-evaluation summary marking. Flag overrides are currently experimental and subject to change. This PR depends on the override layer change (rlamb/overrides-java-override-layer) and is based on that branch; retarget it to feat/overrides once that branch merges. The existing file data source keeps its current behavior; this change does not touch its code paths. [SDK-3246](https://launchdarkly.atlassian.net/browse/SDK-3246) [SDK-3246]: https://launchdarkly.atlassian.net/browse/SDK-3246?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Evaluations that read from the override store now pass an **`overrideAffected`** marker from the evaluator into **`EventProcessor.recordEvaluationEvent`**, including a new default overload on the public interface so existing custom processors keep compiling. > > **`InputValidatingEvaluator`** forwards each result’s marking for successful evals, prerequisites, type-mismatch errors, and exception paths (from the flag definition read before failure). **`DefaultEventProcessorWrapper`** passes it into **`Event.FeatureRequest`**. The dependency **`launchdarkly-java-sdk-internal`** moves to **1.15.0**, which is expected to suppress individual feature/debug events for marked evals and emit summary counters tagged with **`overrideAffected`**. > > New integration tests (**`LDClientOverrideEventsTest`**) cover marking for flags, prerequisites, segments, and flushed analytics payloads; OVERRIDE vector tests and **`TestEventProcessor`** assert **`summaryOverrideAffected`** end-to-end. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ef3bc21. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> <!-- TERMAG_PR_BODY_END --> <!-- termag: box=i-0575d1c54853058d7 project=java-core --> <sub>Opened from termag</sub>
<!-- TERMAG_PR_BODY_BEGIN --> ## Update, 2026-12-01 - Rebased onto `feat/overrides`, which has `main` merged into it again. From `main` it gets the 7.19.0 to 7.19.2 releases, `java-sdk-internal` 1.14.0, and the FDv2 fix that leaves out an empty selector (#261). The v3.2.0-alpha.21 contract tests check that fix, so CI failed three FDv2 streaming tests without it. - The `@since` tags of `FileOverrides`, `FileOverrideSourceBuilder` and `DataSystemBuilder.overrides` now say 7.20.0, because 7.19.0 to 7.19.2 shipped from `main` without flag overrides. Rebased onto the review changes in #220. Changes from the review: - The source gives the reloader only its apply callback, because the reloader in #220 no longer has an error callback. - The source runs its reloader and poller on one executor at the SDK's thread priority, and shuts it down on close. - Change detection starts before the initial load, so a change made while the client starts is applied. Any failure to set up watching, not only a watch service that cannot be created, falls back to polling. A start that fails closes the source. - The `WATCHING` docs list the deployments that need `POLLING`: a configured directory replaced by rename, a configured link whose target does not exist yet, and a configured directory or link that is pointed at another location. - The docs say that a file is read as UTF-8, or as UTF-16 when it starts with a UTF-16 byte order mark. - Tests: the empty JSON file test expects the remedy in the message, and the thread tests count only the threads that the test started. - Verified as in #220: every PR compiles with Javadoc at its own head, the server unit tests pass at the top (2348, with the 72 existing skips), and the full v3.2.0-alpha.21 contract tests pass at the top (6457 tests ran). ## Update, 2026-11-13 - Rebased onto `feat/overrides`, which now includes #218 and #219 and has `main` merged into it. From `main` it gets the 7.18.0 release, CI on the latest v3 contract tests, flag change listener support in the contract test service, and the `java-sdk-internal` 1.12.1 and 1.12.2 fixes. A common 2.6.0 and internal 1.13.0 release from this branch needs those fixes. - New commit, "docs: Say what watching follows, and give the API the version that will ship it": - The `WATCHING` docs say that watching follows the configured files and the files that configured symbolic links lead to, including a mounted ConfigMap update, and they name what it doesn't follow (a configured directory, or a link further along the path, pointed elsewhere), which needs `POLLING`. - The `@since` tags of `FileOverrides` and `FileOverrideSourceBuilder` say 7.19.0. - `FileOverrideSourceTest` adds a ConfigMap update in both modes. The watching case fails with the watcher from before the symbolic link change in #220. - Rebase conflict in the `DataSystemBuilder.overrides` Javadoc: kept this PR's `@see FileOverrides` with the 7.19.0 tag. - Verified at the top of the stack, with `common` and `internal` published locally from `feat/overrides`: - every PR in the stack compiles, with Javadoc, at its own head; - the server unit tests pass (2285, with the 72 existing skips); - the full v3 contract tests pass (6321 tests). That includes the flag overrides suite, with the deleted-entry tests of launchdarkly/sdk-test-harness#599, and both flag listener suites. ## Summary This adds the file-based override source that the OVERRIDE specification defines, as `FileOverrides.source()` in the integrations package, configured through `DataSystemBuilder.overrides(...)`: ```java LDConfig config = new LDConfig.Builder() .dataSystem(Components.dataSystem().defaultMode() .overrides(FileOverrides.source().filePaths("/etc/launchdarkly/overrides.json"))) .build(); ``` The source reads one or more JSON or YAML files in the file data source document format (`flags`, `flagValues`, `segments`) in the configured order. A file whose name ends in `.yaml` or `.yml`, in any case, is YAML, and any other file is JSON; a file is read as UTF-8, or as UTF-16 when it starts with a UTF-16 byte order mark. A `flagValues` entry becomes a flag that is on and serves the value as its single variation by fallthrough, so it evaluates with the `FALLTHROUGH` reason kind. Entries keep the versions that the documents specify. - `duplicateKeysHandling`: `FAIL` (the default) fails the reload when the same key appears in more than one file; `IGNORE` keeps the entry from the first configured file. - `changeDetection`: `POLLING` (the default) examines each file's modification time and size on an interval; `WATCHING` uses file system notifications. The two are alternatives. When watching cannot be set up, for example because the limit on inotify instances is reached, the source logs an error and polls the files instead, at no less than the minimum poll interval. - `pollInterval`: one second by default and at minimum; a smaller value is raised to the minimum with a warning. - A configured file that does not exist contributes no overrides and is not an error. Creating it later takes effect, and deleting it removes its overrides. - A file that exists but cannot be read or parsed fails that whole reload: the last good overrides stay in effect, the failure is logged, and the source retries after a bounded delay as well as on the next change. An empty JSON file is not a valid document, so it fails the reload too; to remove a file's overrides, delete it or write `{}`. An empty YAML file has no entries. - Files can be rewritten in place. A file whose content is in effect and that a reload finds empty is held back by the reloader from the earlier change: the overrides in effect, and the other files' changes, stay until the new content is written, for at most one retry delay (1 s) after the file was last written while empty and five retry delays from the first hold. `FileOverrideSourceImpl` passes the loader itself to the reloader, so that the loader learns which content is in effect, and takes the retry delay as a package-private constructor parameter for tests. For a YAML file, replacing its contents in one operation avoids briefly applying a partly written file. - Change detection starts before the initial load, so a change made while the client starts is not missed. The initial load completes during client construction. Every applied change is logged at Info with the overrides in effect and what each file supplied. - No file paths, a null change detection mode, a null poll interval, or a file path that is not on the default file system (a zip file system, for example) with `WATCHING` selected is a configuration error that fails client construction. Polling reads such a path through its own provider. A path listed more than once is logged at Warn and the repeats are ignored; the first occurrence keeps its place in the order. The public docs say what an application needs: the extension rule and the encoding, that files can be rewritten in place, how to remove a file's overrides, that an empty JSON file is not a valid document, and replacing a YAML file in one operation. The hold's delay and bound stay in the internal comments and in the description of the earlier change. Every public override API, including the builder methods, the poll interval constants and the change detection modes, says that flag overrides are currently experimental and subject to change. The source is built on `OverrideFileLoader`, `FileDataReloader`, `FileDataPoller`, and `FileDataWatcher` from the earlier change. The existing file data source keeps its current behavior; this change does not touch its code paths. This PR depends on the override layer and the reload infrastructure changes and is based on the events branch (rlamb/overrides-java-override-events); retarget it to feat/overrides once that branch merges. ## Testing - `FileOverrideSourceTest`: configuration, merging, missing and malformed files, polling and watching reloads, the polling fallback, thread release on close, and at startup an empty YAML file with no entries and an empty JSON file (also with no extension) failing to load. - `FileOverrideSourceInPlaceRewriteTest`, end to end with real in-place rewrites (truncate, pause, write through the same stream): the source never applies a snapshot without the override, for JSON and YAML, watching (300 ms pause) and polling (1.2 s pause, longer than the poll interval); two quick rewrites while watching; the defaults (polling every second, 1 s retry) through the public builder with two rewrites about a second apart; a client with LaunchDarkly data serving `a -> b` and never the LaunchDarkly value, for JSON and YAML. - The in-place rewrite handling was reviewed in eight rounds as #248 (general and adversarial reviews, Bugbot). Mutation check with a clean build per mutant: 57 mutants, each failing at least one test. The override test classes ran 12 times in a row with no failure. The harness `flag overrides` suite passes against the contract test service at the top of the stack: 38 tests. [SDK-3246](https://launchdarkly.atlassian.net/browse/SDK-3246) <!-- TERMAG_PR_BODY_END --> <!-- termag: box=i-0575d1c54853058d7 project=java-core --> <sub>Opened from termag</sub> [SDK-3246]: https://launchdarkly.atlassian.net/browse/SDK-3246?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Adds **`FileOverrides.source()`** so operators can load flag and segment overrides from local JSON/YAML via `DataSystemBuilder.overrides(...)`, for incident-time control when LaunchDarkly is unreachable. > > The builder supports multiple files (ordered merge, duplicate-key FAIL/IGNORE), **polling** (default 1s) vs **watching** (with automatic fallback to polling if the watch service fails), and validates config at client build time (paths required, no watching on non-default file systems). > > **`FileOverrideSourceImpl`** performs a synchronous initial load, starts change detection before that load, keeps last-good overrides on parse/read failures, and uses the existing `OverrideFileLoader` / `FileDataReloader` stack—including hold-back during in-place rewrites so evaluations never briefly drop overrides. > > Docs and **`OverrideSource`** Javadoc now point at `FileOverrides`. Tests cover reload behavior, ConfigMap-style symlink updates, in-place rewrites end-to-end through `LDClient`, and client-side `allFlagsState` filtering for `flagValues` vs full `flags` with `clientSide`. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9689b40. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
…225) <!-- TERMAG_PR_BODY_BEGIN --> ## Update, 2026-12-01 - Rebased onto `feat/overrides`, which has `main` merged into it again. From `main` it gets the 7.19.0 to 7.19.2 releases, `java-sdk-internal` 1.14.0, and the FDv2 fix that leaves out an empty selector (#261). The v3.2.0-alpha.21 contract tests check that fix, so CI failed three FDv2 streaming tests without it. - Rebase conflicts with `main`'s contract test service changes: persistent store support, the `diagnostic-events` capability, and the port from the `PORT` environment variable. The service lists both capabilities, and this PR no longer changes the port handling, because `main` reads `PORT` itself. - Verified with the v3.2.0-alpha.21 harness that CI runs, with `common` 2.6.0 and `internal` 1.15.0 published locally from `feat/overrides`: - every PR in the stack compiles, with Javadoc, at its own head; - the server unit tests pass at the top (2348, with the 72 existing skips); - the full v3 contract tests pass at the top (6457 tests ran). That includes the flag overrides suite and both flag listener suites. ## Update, 2026-11-13 - Rebased onto `feat/overrides`, which now includes #218 and #219 and has `main` merged into it. From `main` it gets the 7.18.0 release, CI on the latest v3 contract tests, flag change listener support in the contract test service, and the `java-sdk-internal` 1.12.1 and 1.12.2 fixes. A common 2.6.0 and internal 1.13.0 release from this branch needs those fixes. - No changes of its own. With `main` merged into `feat/overrides`, the contract test service also has `main`'s flag change listener support. The flag overrides suite, both flag listener suites (including the override change notifications) and the full v3 suite pass against it at the top of the stack. See the verification below. - Verified at the top of the stack, with `common` and `internal` published locally from `feat/overrides`: - every PR in the stack compiles, with Javadoc, at its own head; - the server unit tests pass (2285, with the 72 existing skips); - the full v3 contract tests pass (6321 tests). That includes the flag overrides suite, with the deleted-entry tests of launchdarkly/sdk-test-harness#599, and both flag listener suites. ## Summary The contract test service now advertises the `flag-overrides` capability and accepts the `overrides` object in the SDK configuration, as the test harness service specification describes: `filePaths` (required), `duplicateKeysHandling` (`fail` or `ignore`), `changeDetection` (`polling` or `watching`), and `pollIntervalMs`. The block configures `FileOverrides.source()` on the data system builder. An `overrides` block without a `dataSystem` block is rejected, because the override source is an option of the FDv2 data system. The service also reads its listening port from the `PORT` environment variable when set, which the Makefile already passes, so several test services can run side by side on one machine. The default stays 8000. This PR depends on the file-based override source (rlamb/overrides-java-file-override-source) and is based on that branch; retarget it to feat/overrides once that branch merges. The existing file data source keeps its current behavior; this change does not touch its code paths. [SDK-3246](https://launchdarkly.atlassian.net/browse/SDK-3246) [SDK-3246]: https://launchdarkly.atlassian.net/browse/SDK-3246?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > The Java SDK contract test service now advertises **`flag-overrides`** and accepts an **`overrides`** block on SDK configuration so harness tests can drive file-based flag overrides. > > **`SdkConfigOverridesParams`** maps harness fields (`filePaths`, `duplicateKeysHandling`, `changeDetection`, `pollIntervalMs`) into **`FileOverrides.source()`** on the FDv2 data system builder. Configurations that include **`overrides`** without **`dataSystem`** are rejected with an explicit error, since override sources only apply when the data system is configured. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 40e6b43. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> <!-- TERMAG_PR_BODY_END --> <!-- termag: box=i-0575d1c54853058d7 project=java-core --> <sub>Opened from termag</sub>
…y it is listed under (#259) <!-- TERMAG_PR_BODY_BEGIN --> ## Update, 2026-12-03 - `launchdarkly-java-sdk-common` 2.6.0 and `launchdarkly-java-sdk-internal` 1.15.0 are released from `main` (#298, #299), and the pins are unchanged. - Verified against the Maven Central artifacts: every PR in the stack builds at its own head, with the contract test service, the server unit tests pass at the top (2348, with the 72 existing skips), and CI passes. ## Update, 2026-12-01 - Rebased onto `feat/overrides`, which has `main` merged into it again. From `main` it gets the 7.19.0 to 7.19.2 releases, `java-sdk-internal` 1.14.0, and the FDv2 fix that leaves out an empty selector (#261). The v3.2.0-alpha.21 contract tests check that fix, so CI failed three FDv2 streaming tests without it. - No changes of its own. It keeps #260, which merged into this branch: the file synchronizer pin tests wait for the failure status, so they hold on Windows. - Verified with the v3.2.0-alpha.21 harness that CI runs, with `common` 2.6.0 and `internal` 1.15.0 published locally from `feat/overrides`: - every PR in the stack compiles, with Javadoc, at its own head; - the server unit tests pass at the top (2348, with the 72 existing skips); - the full v3 contract tests pass at the top (6457 tests ran). That includes the flag overrides suite and both flag listener suites. ## Update, 2026-11-13 - Rebased onto `feat/overrides`, which now includes #218 and #219 and has `main` merged into it. From `main` it gets the 7.18.0 release, CI on the latest v3 contract tests, flag change listener support in the contract test service, and the `java-sdk-internal` 1.12.1 and 1.12.2 fixes. A common 2.6.0 and internal 1.13.0 release from this branch needs those fixes. - New commit, "fix: Key each override by the key it is listed under, and reject one listed under another key": - Evaluation reads an override entry by the key it is listed under, but the all-flags state and events report the definition's own key. The file source deserialized each `flags` and `segments` entry as it was, so an entry with no `key` property made `allFlagsState()` throw a `NullPointerException` to the application, and an entry pasted under a new key with its old `key` property was served under one key and reported under the other. I confirmed both with a probe against the stack. - Each entry now takes the key it's listed under, as the Node, Go and Python sources key it. A `key` property is optional, and `FileOverrides.source()` says so. - The override layer also rejects a snapshot that lists a flag or segment under a key other than its own, the same way as one with a deleted item: the sink logs it and the overrides in effect stay. Only a custom source can produce such a snapshot now. Python added the same check after keelerm84's review of its port (python-server-sdk#527). Go, Node, .NET and Ruby don't have it yet. - Tests: `OverrideFileLoaderTest.entryIsKeyedByTheKeyItIsListedUnder` (JSON and YAML, flags and segments), `LDClientOverridesTest.fileEntryIsServedAndReportedUnderTheKeyItIsListedUnder`, `OverrideLayerTest.replacementThatListsAnItemUnderAnotherKeyIsRejectedAndTheLayerIsUnchanged` (including a definition with no key), and `OverrideSinkImplTest.snapshotThatListsAFlagUnderAnotherKeyIsRejected`. Removing the keying fails the first two, and removing the layer check fails the other two. - Verified at the top of the stack, with `common` and `internal` published locally from `feat/overrides`: - every PR in the stack compiles, with Javadoc, at its own head; - the server unit tests pass (2285, with the 72 existing skips); - the full v3 contract tests pass (6321 tests). That includes the flag overrides suite, with the deleted-entry tests of launchdarkly/sdk-test-harness#599, and both flag listener suites. **Requirements** - [x] I have added test coverage for new or changed functionality - [x] I have followed the repository's [pull request submission guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests) - [ ] I have validated my changes against all supported platform versions **Related issues** Implements the "reject deleted entries" rule of the flag overrides spec, launchdarkly/sdk-specs#288 (Requirements 1.1.1.1, 1.2.8.1 and 1.3.6.2). This PR is stacked on #225 (`rlamb/overrides-java-contract-tests`) so that the PRs below it do not change. Retarget it when the stack merges. **Describe the solution you've provided** Before: a flag or segment entry with `"deleted": true` became a deleted placeholder. That was true both in an override file and in a snapshot from a custom source. The override layer stored it and the overlay served it, so the key looked absent: the LaunchDarkly definition was hidden from evaluation, from prerequisites and segment reads, and from the all-flags state, and the evaluation was not marked as override-affected. After: - **Sink (every source, including a custom one through `OverrideSink`).** The override layer never holds a deleted item. If a snapshot contains one, the SDK rejects the whole snapshot. The layer stays unchanged, no flag change listener is notified, and the SDK logs an Error naming the kind and the key, for example `Rejected an override snapshot because flag "f" is marked as deleted; the overrides in effect are unchanged`. A deleted item is either the placeholder that `DataKind.deserialize` produces or a model object marked as deleted. The check runs in `OverrideLayer.setAll` before the contents are swapped, and `OverrideSinkImpl` logs the rejection. The `OverrideSink` signature is unchanged and nothing is thrown to the source. - **File override source.** `OverrideFileLoader` fails the load when a file has a flag or segment entry marked as deleted, the same way it fails for a file that cannot be parsed. The overrides in effect stay, and the existing retry applies. The failure is logged like other load failures and names the file and the key: `Unable to load flags: file /path/overrides.json: flag "f" is marked as deleted; remove the entry to remove its override`. The check also fires when the duplicate keys handling would drop the entry, because the file still needs correcting. The source detects this while loading, before it calls the sink. - `"deleted": false` is an ordinary definition and still loads. - **Public docs.** `FileOverrides.source()` gains one sentence saying that a file with an entry marked as deleted fails to load and that an override is removed by removing its entry or deleting the file. `OverrideSink.setOverrides` gains one sentence saying that a snapshot with a deleted flag or segment is rejected. The experimental notice is unchanged on both. **The ordinary file data source is unchanged on purpose.** `FileDataSourceBase` and `FileDataSourceParsing` are not modified. Rejecting deleted entries there would be a breaking change, which is planned for a later major version. The check lives only in the override path (`OverrideFileLoader` and the override layer). A new test, `DataLoaderTest.entriesMarkedAsDeletedStillLoadAsDeletedItems`, pins the data source's current behavior: it still loads such entries as deleted items. **Tests** - `OverrideLayerTest`: `replacementThatContainsADeletedItemIsRejectedAndTheLayerIsUnchanged` replaces `deletedPlaceholderIsStoredAsIs`, which pinned the old behavior. It covers the deserialized placeholder and a model object marked as deleted, for both flags and segments. `definitionWithDeletedFalseIsStored` is new. - `OverrideSinkImplTest`: `snapshotWithADeletedFlagIsRejected`, `snapshotWithADeletedSegmentIsRejected` and `snapshotWithADeletedItemIsRejectedWhenNothingIsListening`. Each checks that the layer is unchanged, that no notification is sent, and that the Error is logged. - `OverrideFileLoaderTest`: `flagMarkedAsDeletedFailsTheLoad` and `segmentMarkedAsDeletedFailsTheLoad` cover JSON and YAML, with the exact message naming the file and the key. Also `entryMarkedAsDeletedFailsTheLoadEvenWhenItIsADroppedDuplicate` and `entriesWithDeletedFalseAreOrdinaryDefinitions`. - `FileOverrideSourceTest`: `flagMarkedAsDeletedFailsTheReloadAndKeepsTheOverrides` and `segmentMarkedAsDeletedFailsTheReloadAndKeepsTheOverrides`. In each, an in-place edit adds the deleted entry and changes another override. Nothing is supplied, the logged Error names the file and the key, and removing the entry recovers. `entriesWithDeletedFalseLoad` is also new. - `DataLoaderTest.entriesMarkedAsDeletedStillLoadAsDeletedItems`: the ordinary file data source behavior is pinned as unchanged. How I ran them, on JDK 17 (arm64): 1. Published the unreleased shared libraries locally from the monorepo. Common came from the #218 head (`b5deba0`) with `./gradlew publishToMavenLocal -Pversion=2.6.0 -PskipSigning=true` in `lib/shared/common`. Internal came from the #219 head (`0e7744f`) with `-Pversion=1.13.0` in `lib/shared/internal`. 2. In `lib/sdk/server`, ran the override and file data source classes with `./gradlew --max-workers=2 --no-daemon -Dorg.gradle.jvmargs=-Xmx2g test --tests '*Override*' --tests '*.integrations.File*' --tests '*.integrations.DataLoaderTest' --tests '*.integrations.FlagFileParser*' --tests '*.integrations.ClientWithFileDataSourceTest'`. Result: 343 tests in 29 classes, 0 failures. 3. Ran the full server `test` task (same Gradle options). Result: 2275 tests in 129 classes, 0 failures. The 72 skipped tests are the existing skips in `PersistentDataStoreWrapperTest`. 4. Ran `checkstyleMain checkstyleTest javadoc`: passed, with no new Javadoc warnings. 5. Checked that the new tests fail without the change. With the layer check and the loader check disabled, all 9 rejection tests fail, and the `deleted: false` tests and the data source pin still pass. With the sink's catch removed, the 3 sink tests fail. **Describe alternatives you've considered** - Checking only in the sink, with a separate pass over the snapshot. That pass would iterate the source's `Iterable` twice. Checking in `OverrideLayer.setAll` keeps it to one pass and makes the layer enforce its own invariant. - Dropping only the deleted entry. The spec requires rejecting the whole snapshot, so the layer is always exactly a snapshot that the source supplied. <!-- TERMAG_PR_BODY_END --> <!-- termag: box=i-0575d1c54853058d7 project=java-core --> <sub>Opened from termag</sub> [SDK-3578](https://launchdarkly.atlassian.net/browse/SDK-3578) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Strengthens **flag/segment override** handling so invalid snapshots are rejected instead of partially applied. > > **Override layer** (`OverrideLayer.setAll`) now refuses any replacement that includes a **deleted** flag/segment (placeholder or `deleted: true`) or a definition **listed under a different key** than its own `key`. The prior snapshot stays in place; new `DeletedItemException` / `MismatchedKeyException` types carry clear messages. > > **Override sink** catches those failures, logs an error, and **does not** notify flag-change listeners. > > **File override source** (`OverrideFileLoader`) treats `"deleted": true` entries as a **load failure** (like a parse error), forces each `flags`/`segments` entry’s `key` to match the map key it’s listed under via `keyedBy`, and updates public docs on `FileOverrides` and `OverrideSink`. Removing an override is done by deleting the entry or file—not by marking deleted. > > The **ordinary file data source** is intentionally unchanged; a new test pins that deleted entries still load there. > > Extensive unit/integration tests cover rejection, logging, key consistency in evaluation vs `allFlagsState`, and file reload behavior. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 7b2ebcf. 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
lib/shared takes main's version: main holds the released launchdarkly-java-sdk-common 2.6.0 and launchdarkly-java-sdk-internal 1.15.0. In EventSummarizerInterface, the method without the override marker stays abstract and the overload with the marker is the default.
There was a problem hiding this comment.
Risk: high.
Automated risk review (dry run): High
This PR would not be automatically approved. Human approval required.
Why: This adds experimental file-based flag overrides across the server SDK evaluation, data-system, and event-processor paths (including public APIs and existing file-data parsing/reload behavior), with a 64-file / 12k-line blast radius that is too large to treat as Low. 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.
Sent by Cursor Approval Agent: Dry-Run PR Approver
There was a problem hiding this comment.
Risk: high. SDK rules 1–3 are satisfied (not a release PR, allowed author, no workflow changes), and Bugbot completed with no findings, but the configured risk threshold allows only low-risk PRs. This adds experimental file-based flag overrides across evaluation, data-system, and event paths, so human review is needed and no reviewers were assigned.
Sent by Cursor Approval Agent: SDK - Pull Request Router and Approver


BEGIN_COMMIT_OVERRIDE
feat: Add experimental support for file-based flag overrides
fix: Keep flag file content out of the file data source's parse error messages
fix: Prevent YAML flag files that are parsed at the same time from returning each other's data
fix: Report a YAML flag file value that does not match its explicit tag as invalid data instead of an unexpected exception
END_COMMIT_OVERRIDE
Summary
Brings
feat/overridesintomain: experimental flag overrides for the server SDK on the FDv2 data system, with a file-based override source. The branch isfeat/overrideswithmainmerged into it;feat/overridesitself is unchanged. Every change was reviewed and merged through its own PR againstfeat/overrides: #220, #221, #222, #223, #224, #225 and #259. The shared library changes were released frommainaslaunchdarkly-java-sdk-common2.6.0 (#298) andlaunchdarkly-java-sdk-internal1.15.0 (#299), and the server pins those versions. This PR adds nothing of its own; its diff againstmainis the server SDK only.Technical design decisions
maintakesmain'slib/shared, which is the released code. Git mergedEventSummarizerInterfacewithout a conflict, but into the shape of feat: Count override-affected evaluations separately and send no individual events for them #219, which breaks summarizers outside the library; the merge keeps the shape of feat: Count override-affected evaluations separately and send no individual events for them #299.Needs your attention
@since 7.20.0. The open release PR chore(main): release launchdarkly-java-server-sdk 7.20.0 #296 (7.19.3) becomes 7.20.0 once this merges.Details
feat/overridesafter the stack merged passed too.AggregatedEventSummarizer,PerContextEventSummarizer,DefaultEventProcessorOutputTestandEventSummarizerTestinlib/shared/internal, all resolved tomain's version.SDK-3246
Opened from termag
Note
Overview
Adds experimental file-based flag overrides on the FDv2 data system: operators can configure
DataSystemBuilder.overrides(FileOverrides.source()...)so local JSON/YAML files supply flag and segment definitions that take precedence over LaunchDarkly data at read time, without affecting client initialization or data-source status.The implementation introduces an override layer (
OverrideLayer,OverrideOverlayStore,OverrideSinkImpl) wired fromFDv2DataSystem, a pluggableOverrideSource/OverrideSinkAPI, and a file override source with polling or filesystem watching, debounced reloads, duplicate-key handling, and safer JSON/YAML parsing (extension-based format choice, improved error messages, per-parse YAML, tag-mismatch handling).Evaluation and analytics behavior changes: flags/segments from overrides carry a transient marker; the evaluator propagates override-affected through prerequisites and segment reads;
EvalResult/EvaluationReasonexpose the marker; individual evaluation events are suppressed for override-affected results (while summaries can still account for them via the newEventProcessorparameter);allFlagsStateandisFlagKnowncan use overrides before the store is initialized. Dependency tracking now merges LaunchDarkly and override-layer edges so flag-change listeners fire when LD updates affect overridden definitions.Contract tests register the
flag-overridescapability and map override config inSdkClientEntity. Build pins bumplaunchdarklyJavaSdkCommon/Internalversions.Reviewed by Cursor Bugbot for commit 763827f. Bugbot is set up for automated code reviews on this repo. Configure here.