Skip to content

fix: use the flag version in FDv2 put-object events - #862

Merged
nieblara merged 3 commits into
cursor/fdv2-client-side-support-c95bfrom
cursor/fdv2-put-object-flag-version-b626
Oct 13, 2026
Merged

nieblara merged 3 commits into
cursor/fdv2-client-side-support-c95bfrom
cursor/fdv2-put-object-flag-version-b626

Conversation

@nieblara

@nieblara nieblara commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

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

Related issues

This PR goes into the branch of #764. It fixes a problem that I found when I tested #764 in a browser.

Describe the solution you've provided

A put-object event is the FDv2 event that sends one flag to an SDK. Each put-object event has a version field. The dev server put the project payload version in this field. Every override raises the payload version by 1.

The JS client SDK stores this field as the version of the flag (flagEvalUpdateToItemDescriptor). After a full transfer, the SDK compares the old flags and the new flags to find the changed flags. Every flag had a new version, so the SDK sent a change event for every flag. This occurred in polling mode and after a stream reconnect. The flag values were correct.

Example: I set an override on theme-config. The put-object version of max-items changed from 15 to 16. Its flagVersion and its value did not change. The FDv1 endpoint /sdk/evalx kept max-items at version 1.

This PR puts the version of the flag in the put-object event. The change is in makePutObjectEvent, which the server-side and client-side paths share. The flag version is the base version plus the override version. The SQLite store raises the override version by 1 each time that you set or remove the override. As a result, the flag version goes up each time that the flag changes, and it stays the same when the flag does not change.

Effect on each SDK:

  • JS client SDK: change events now list only the flags that changed. FDv2 partial updates do not have a version check in this SDK (applyChanges). Only its FDv1 patch and delete handlers check the version. If a later SDK version adds a version check, it will still accept each change, because the version goes up on each override action.
  • Go server SDK: no change in behavior. For a put, it reads the version from the flag JSON (ToStorableItems), not from the envelope. The envelope version now equals the version in the flag JSON. The SDK's FDv1 fallback uses the same rule (keyedItem.Item.Version in fdv1_polling_data_source.go).

Tests:

  • A new unit test builds two full transfers at different payload versions. It checks that an unchanged flag keeps its put-object version. It runs with the server encoder and with the client encoder.
  • A new test uses the real SQLite store. It sets an override, sets the same value again, removes the override, and sets it again. After each step, it checks that the streamed version goes up and equals the version in the next full transfer. It also checks that the other flag keeps its version.
  • The existing tests now expect the flag version in the put-object event. This includes the stream test for an override.
  • Both new tests fail without the fix. With the old fdv2.go, four tests in the sdk package fail.

Manual test in a browser

The test page runs @launchdarkly/js-client-sdk 4.11.2 in FDv2 mode against a local dev server. The dev server UI is on the right. The "Live flag changes received by the SDK" list shows each change event from the SDK.

Before the fix, one override on theme-config (at 06:27:02) gave a change event for all four flags:

Before the fix: one override reports four changed flags

After the fix, each override gives one change event, for the flag that changed. The video shows polling mode first. Each change arrives with the next poll. Then it shows streaming mode, where the SDK shows each on and off change at once:

pr862_fix_only_changed_flag_reported_polling_and_streaming.mp4

A curl check with the fixed server shows that only the changed flag gets a new put-object version, on set and on remove:

After an override on theme-config:
  payload version=22
  banner-text        version=8   flagVersion=8
  max-items          version=1   flagVersion=1
  show-new-checkout  version=9   flagVersion=9
  theme-config       version=13  flagVersion=13
After the override on theme-config is removed:
  payload version=23
  ...
  theme-config       version=14  flagVersion=14

An independent review checked the other paths that change flags: project update, sync from LaunchDarkly, import, restore, and startup overrides. If a value can change without a higher flag version on these paths, the dev server sends a full transfer. A full transfer replaces the flags in the SDK, so the SDK does not drop the change.

Describe alternatives you've considered

I did not change only the client-side encoder. The server-side path uses the same function. One rule for the field is easier to understand, and the Go server SDK already uses the flag version for this field in its FDv1 fallback.

Additional context

This changes the server-side FDv2 output in one field. The version field of each put-object event now has the flag version, not the payload version. The server-intent target and the payload-transferred selector still use the payload version, so the basis handling does not change.

go test ./... passes. On this test machine, cmd/flags TestArchive fails on main too when LD_PROJECT and the other LD_ environment variables are set. It passes when they are unset. golangci-lint is not installed on the test machine. go vet and staticcheck pass on the sdk package.

Open in Web Open in Cursor 

cursoragent and others added 3 commits October 13, 2026 06:36
Each put-object event had the project payload version. Every override
raises the payload version. SDKs store the event version as the version
of the flag, so after each full transfer all flags looked changed. The
JS client SDK then sent change events for flags that did not change.
This occurred in polling mode and after a stream reconnect.

The event version is now the version of the flag. The FDv1 endpoints
already use this version. The flag version goes up each time that its
override changes, so SDKs still accept each update.

Co-authored-by: Ramon Niebla <nieblara@users.noreply.github.com>
The Go server SDK reads the version from the flag JSON, not from the
put-object event. The JS client SDK does not drop FDv2 updates by
version. The comment now says only what client-side SDKs do. The new
text also follows the Simple English rules of the repository.

Co-authored-by: Ramon Niebla <nieblara@users.noreply.github.com>
The new test sets, sets again, removes, and sets an override on one
flag. After each step, it checks that the streamed version goes up and
equals the version in the next full transfer. It also checks that the
other flag keeps its version.

Co-authored-by: Ramon Niebla <nieblara@users.noreply.github.com>
@nieblara
nieblara marked this pull request as ready for review October 13, 2026 19:26
@nieblara
nieblara requested a review from a team as a code owner October 13, 2026 19:26
@nieblara
nieblara merged commit 3131663 into cursor/fdv2-client-side-support-c95b Oct 13, 2026
8 checks passed
@nieblara
nieblara deleted the cursor/fdv2-put-object-flag-version-b626 branch October 13, 2026 19:26
nieblara added a commit that referenced this pull request Oct 13, 2026
* feat: serve the FDv2 client-side protocol from the dev server

Client-side SDKs are moving to the FDv2 endpoints, which the dev server did
not serve at all: an SDK upgraded to an FDv2-capable version and pointed at
the dev server asked for routes that were not there.

Adds POST/REPORT /sdk/poll/eval, GET /sdk/poll/eval/{context},
POST/REPORT /sdk/stream/eval and GET /sdk/stream/eval/{context}. FDv2
unifies the browser and mobile endpoints, so this one pair of routes covers
what /eval/{envId}, /meval, /sdk/evalx/{envId} and /msdk/evalx did in FDv1.

The protocol event builders are parameterized over the put-object kind and
object shape rather than forked, so the two protocols differ only in that
client-side put-objects carry a pre-evaluated flag-eval result where
server-side ones carry the flag configuration.

Co-authored-by: Ramon Niebla <nieblara@users.noreply.github.com>

* test: cover the client-side FDv2 endpoints

Covers the flag-eval object shape, base64 context decoding across the
url-safe and standard variants, the credential and context matrices for
both the path and body forms, CORS preflight on all four routes, and an
end-to-end SSE stream carrying an initial transfer plus an override.

Co-authored-by: Ramon Niebla <nieblara@users.noreply.github.com>

* chore: revert unrelated go.sum churn from a local go mod download

Co-authored-by: Ramon Niebla <nieblara@users.noreply.github.com>

* refactor: share the initial-response setup between FDv2 poll and stream

The two handlers loaded the project, applied overrides, and built the
initial response identically.

Co-authored-by: Ramon Niebla <nieblara@users.noreply.github.com>

* fix: drop REPORT from the client-side FDv2 endpoints

The FDv2 client-side protocol takes the evaluation context in a POST body
or a GET path; REPORT is not part of it, and the JS SDK never sends it.
POST /sdk/poll/eval and POST /sdk/stream/eval now answer REPORT with 405,
and their CORS configuration no longer allows it.

The FDv1 client-side routes still accept REPORT.

Co-authored-by: Ramon Niebla <nieblara@users.noreply.github.com>

* refactor: only check that the client-side FDv2 context is valid JSON

The dev server serves the same flag values to everyone, so it never uses
the evaluation context. Parsing it as a full LaunchDarkly context only
added a way to reject a request the dev server could have served.

Requests are still rejected with 400 when the context is not base64 or not
well-formed JSON. A well-formed context missing fields such as key is now
accepted.

Co-authored-by: Ramon Niebla <nieblara@users.noreply.github.com>

* fix: use the flag version in FDv2 put-object events (#862)

* fix: use the flag version in FDv2 put-object events

Each put-object event had the project payload version. Every override
raises the payload version. SDKs store the event version as the version
of the flag, so after each full transfer all flags looked changed. The
JS client SDK then sent change events for flags that did not change.
This occurred in polling mode and after a stream reconnect.

The event version is now the version of the flag. The FDv1 endpoints
already use this version. The flag version goes up each time that its
override changes, so SDKs still accept each update.

Co-authored-by: Ramon Niebla <nieblara@users.noreply.github.com>

* docs: correct the comment about put-object versions

The Go server SDK reads the version from the flag JSON, not from the
put-object event. The JS client SDK does not drop FDv2 updates by
version. The comment now says only what client-side SDKs do. The new
text also follows the Simple English rules of the repository.

Co-authored-by: Ramon Niebla <nieblara@users.noreply.github.com>

* test: check put-object versions with the SQLite store

The new test sets, sets again, removes, and sets an override on one
flag. After each step, it checks that the streamed version goes up and
equals the version in the next full transfer. It also checks that the
other flag keeps its version.

Co-authored-by: Ramon Niebla <nieblara@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Ramon Niebla <nieblara@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Ramon Niebla <nieblara@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