Skip to content

feat: FDv2 Cache Initializer#1147

Merged
kinyoklion merged 14 commits into
mainfrom
rlamb/sdk-1922/cache-initializer
Mar 5, 2026
Merged

feat: FDv2 Cache Initializer#1147
kinyoklion merged 14 commits into
mainfrom
rlamb/sdk-1922/cache-initializer

Conversation

@kinyoklion

@kinyoklion kinyoklion commented Mar 3, 2026

Copy link
Copy Markdown
Member

Note

Medium Risk
Touches persistence and FDv2 data-source plumbing by adding new cached-data paths and new storage keys, which could affect startup behavior and cache correctness across contexts. Changes are well-covered by new unit tests but still impact core flag loading/poll timing logic.

Overview
Adds an FDv2 CacheInitializer that loads cached flag evaluations from persistent storage (including legacy-key fallback), returns them as a changeSet without a selector, and supports early shutdown via close().

Introduces cache “freshness” metadata: FlagPersistence now writes/evicts {contextKey}_freshness records (timestamp + context hash), readFreshness validates them, and FDv2SourceResult.changeSet can carry an optional freshness value; also adds calculatePollDelay to derive the next poll delay from freshness.

Refactors/expands tests to cover the new cache initializer, freshness persistence/eviction, and updates existing storage tests for the additional storage writes; shared test helpers are centralized in flagManagerTestHelpers.ts.

Written by Cursor Bugbot for commit ccae06f. This will update automatically on new commits. Configure here.


Open with Devin

@github-actions

github-actions Bot commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 25566 bytes
Compressed size limit: 26000
Uncompressed size: 125383 bytes

@github-actions

github-actions Bot commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

@launchdarkly/browser size report
This is the brotli compressed size of the ESM build.
Compressed size: 172130 bytes
Compressed size limit: 200000
Uncompressed size: 800872 bytes

@github-actions

github-actions Bot commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

@launchdarkly/js-client-sdk size report
This is the brotli compressed size of the ESM build.
Compressed size: 24212 bytes
Compressed size limit: 25000
Uncompressed size: 83755 bytes

@github-actions

github-actions Bot commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

@launchdarkly/js-client-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 21281 bytes
Compressed size limit: 24000
Uncompressed size: 110213 bytes

}
},
initCached(context: Context, newFlags: { [key: string]: ItemDescriptor }) {
initCached(context: Context, newFlags: { [key: string]: ItemDescriptor }, _freshness?: number) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We aren't doing anything with this yet, but likely we will want to expose it from the flag manager.

@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

@@ -121,16 +136,22 @@ export default class FlagPersistence {
}

private async _storeCache(context: Context): Promise<void> {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

With this change we start recording freshness even in the FDv1 path.

@@ -56,47 +63,55 @@ export default class FlagPersistence {
* {@link FlagUpdater} this {@link FlagPersistence} was constructed with.
*/
async loadCached(context: Context): Promise<boolean> {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Once we remove V1 support this loading path will be removed.

@kinyoklion kinyoklion marked this pull request as ready for review March 4, 2026 23:52
@kinyoklion kinyoklion requested a review from a team as a code owner March 4, 2026 23:52
Comment thread packages/shared/sdk-client/src/flag-manager/FlagPersistence.ts
cursor[bot]

This comment was marked as resolved.

cursor[bot]

This comment was marked as resolved.

@kinyoklion kinyoklion requested a review from joker23 March 5, 2026 17:34
devin-ai-integration[bot]

This comment was marked as resolved.

@kinyoklion kinyoklion merged commit 7d6299f into main Mar 5, 2026
42 checks passed
@kinyoklion kinyoklion deleted the rlamb/sdk-1922/cache-initializer branch March 5, 2026 21:47
@github-actions github-actions Bot mentioned this pull request Mar 5, 2026
joker23 pushed a commit that referenced this pull request Mar 16, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>browser: 0.1.12</summary>

##
[0.1.12](browser-v0.1.11...browser-v0.1.12)
(2026-03-16)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-client-sdk bumped from 4.3.1 to 4.4.0
</details>

<details><summary>browser-telemetry: 1.0.28</summary>

##
[1.0.28](browser-telemetry-v1.0.27...browser-telemetry-v1.0.28)
(2026-03-16)


### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/js-client-sdk bumped from 4.3.1 to 4.4.0
</details>

<details><summary>jest: 1.0.7</summary>

##
[1.0.7](jest-v1.0.6...jest-v1.0.7)
(2026-03-16)


### Dependencies

* The following workspace dependencies were updated
  * dependencies
* @launchdarkly/react-native-client-sdk bumped from ~10.14.1 to ~10.15.0
</details>

<details><summary>js-client-sdk: 4.4.0</summary>

##
[4.4.0](js-client-sdk-v4.3.1...js-client-sdk-v4.4.0)
(2026-03-16)


### Features

* Add experimental FDv2 configuration (unused)
([#1169](#1169))
([c7130cc](c7130cc))
* create @launchdarkly/js-contract-test-utils package
([#1163](#1163))
([2de5c27](2de5c27))


### Bug Fixes

* Allow 0 status code to be handled by the streaming error filter.
([d96b46b](d96b46b))
* Improve error handling for FDv2 streaming
([d96b46b](d96b46b))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-client-sdk-common bumped from 1.21.0 to 1.22.0
</details>

<details><summary>js-client-sdk-common: 1.22.0</summary>

##
[1.22.0](js-client-sdk-common-v1.21.0...js-client-sdk-common-v1.22.0)
(2026-03-16)


### Features

* Add experimental FDv2 configuration (unused)
([#1169](#1169))
([c7130cc](c7130cc))
* Add explicit disableCache setting.
([6be89dd](6be89dd))
* Add FDv1 polling synchronizer for FDv2 fallback (SDK-1923)
([#1159](#1159))
([498216a](498216a))
* Add mode resolution table for FDv2.
([#1146](#1146))
([ab2436d](ab2436d))
* FDv2 Cache Initializer
([#1147](#1147))
([7d6299f](7d6299f))


### Bug Fixes

* Allow 0 status code to be handled by the streaming error filter.
([d96b46b](d96b46b))
* Fix the calculation of the basis parameter for FDv2 streaming. (Does
not affect FDv1).
([#1165](#1165))
([bbdd6c6](bbdd6c6))
* Improve error handling for FDv2 streaming
([d96b46b](d96b46b))
* Max cached context enforcement wasn't working for 0.
([6be89dd](6be89dd))
* rename FDv2 object kind from `flagEval` to `flag-eval`
([#1185](#1185))
([cd4b119](cd4b119))
</details>

<details><summary>react-native-client-sdk: 10.15.0</summary>

##
[10.15.0](react-native-client-sdk-v10.14.1...react-native-client-sdk-v10.15.0)
(2026-03-16)


### Features

* Add experimental FDv2 configuration (unused)
([#1169](#1169))
([c7130cc](c7130cc))
* create @launchdarkly/js-contract-test-utils package
([#1163](#1163))
([2de5c27](2de5c27))


### Dependencies

* The following workspace dependencies were updated
  * dependencies
    * @launchdarkly/js-client-sdk-common bumped from 1.21.0 to 1.22.0
</details>

<details><summary>server-sdk-ai: 0.16.6</summary>

##
[0.16.6](server-sdk-ai-v0.16.5...server-sdk-ai-v0.16.6)
(2026-03-16)


### Bug Fixes

* Make defaultValue optional with a disabled default
([#1144](#1144))
([e46769b](e46769b))
</details>

<details><summary>server-sdk-ai-langchain: 0.5.2</summary>

##
[0.5.2](server-sdk-ai-langchain-v0.5.1...server-sdk-ai-langchain-v0.5.2)
(2026-03-16)


### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/server-sdk-ai bumped from ^0.16.5 to ^0.16.6
  * peerDependencies
* @launchdarkly/server-sdk-ai bumped from ^0.15.0 || ^0.16.0 to ^0.16.6
</details>

<details><summary>server-sdk-ai-openai: 0.5.2</summary>

##
[0.5.2](server-sdk-ai-openai-v0.5.1...server-sdk-ai-openai-v0.5.2)
(2026-03-16)


### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/server-sdk-ai bumped from ^0.16.5 to ^0.16.6
  * peerDependencies
* @launchdarkly/server-sdk-ai bumped from ^0.15.0 || ^0.16.0 to ^0.16.6
</details>

<details><summary>server-sdk-ai-vercel: 0.5.2</summary>

##
[0.5.2](server-sdk-ai-vercel-v0.5.1...server-sdk-ai-vercel-v0.5.2)
(2026-03-16)


### Dependencies

* The following workspace dependencies were updated
  * devDependencies
    * @launchdarkly/server-sdk-ai bumped from ^0.16.5 to ^0.16.6
  * peerDependencies
* @launchdarkly/server-sdk-ai bumped from ^0.15.0 || ^0.16.0 to ^0.16.6
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Primarily automated release/version bumps and changelog updates across
multiple packages; no functional code changes beyond embedded SDK
version constants and dependency bumps.
> 
> **Overview**
> Publishes a new release across the monorepo by bumping versions in
`.release-please-manifest.json`, updating package `CHANGELOG.md`s, and
syncing `package.json` dependency ranges.
> 
> Notable bumps include `@launchdarkly/js-client-sdk` to `4.4.0` (and
`@launchdarkly/js-client-sdk-common` to `1.22.0`),
`@launchdarkly/react-native-client-sdk` to `10.15.0`,
`@launchdarkly/server-sdk-ai` to `0.16.6`, and corresponding
provider/aggregator packages (`server-sdk-ai-*`,
`@launchdarkly/browser`, `browser-telemetry`, `@launchdarkly/jest`).
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
a6d9634. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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