Repository navigation
fix: Verify all-items reads for empty and single-item collections - #463
Merged
Merged
Conversation
The daemon-mode subtree also holds tests that cache, so the name has to say that this helper turns the cache off.
jsonbailey
marked this pull request as ready for review
September 24, 2026 17:12
kinyoklion
approved these changes
Sep 24, 2026
keelerm84
approved these changes
Sep 24, 2026
This was referenced Sep 28, 2026
jsonbailey
added a commit
that referenced
this pull request
Sep 28, 2026
Ports the persistent-store collection-cardinality tests from `v2` (#463) to `v3`. Jira: SDK-3174. ## What the cases cover Reading a whole collection is a different code path from reading one record by key, and its result changes shape with the number of records. A database client can return a lone matching record on its own instead of inside a list, and can report "nothing matched" with a sentinel instead of an empty list. A store wrapper that assumes a list fails the whole collection, so every flag falls back to its default. The rest of the persistence suite only ever reads collections of three or four items, so these cases cover the two sizes it never produces: 1. **one item** -- a collection holding a single live flag 2. **one item, a tombstone** -- a collection holding only `{"version":N,"deleted":true}` 3. **no items** -- a store the SDK has never used All-flags is the trigger for the collection read; a single by-key evaluation reads one record instead and does not exercise it. Case 1 also asserts the by-key read first, which keeps a collection-read failure distinct from a by-key failure. Each case runs for Redis, Consul and DynamoDB. ## Why this is a port and not a cherry-pick `v3` restructured this suite, so the wiring from `v2` does not apply: | | v2 | v3 | |---|---|---| | subtree | `t.Run("daemon mode", ...)` | does not exist | | instead | -- | `store mode %s - no data source` / `- with data source`, looped over `databaseModes` | | persistence API | `SetStore`, `SetCache` | also `SetStoreMode(servicedef.DataStoreMode)` | `v2` hung these cases off the `daemon mode` subtree. On `v3` the equivalent configuration is "no data source": nothing but the store populates data. Rather than reach into the `databaseModes` loop, the cases sit in their own top-level `t.Run("collection cardinality", ...)` next to `t.Run("read-write", ...)`, which is the existing `v3` precedent for a subtree that owns its store-mode config. All helpers the `v2` file depended on exist unchanged on `v3` (`runWithEmptyStore`, `initialFlags`, `defaultPrefix`, `WriteMap`, `EvalAllFlagsValueForKeyShouldEqual`, `pollUntilFlagValueUpdated`); `requireEmptyAllFlagsState` and `requireFlagNotFound` are defined in the cardinality file itself and come along with it. ## Store-mode decision: read only The cases run once, under `DataStoreModeRead`, not once per store mode. Store mode governs the write path -- whether data from initializers and synchronizers is written back to the store. With no data source there is nothing to write, so that path is dead and the collection-read path under test is identical in both modes. Running all three cases a second time would triple the case count (9 -> 18 across the three databases) for no additional signal. Read mode is also the mode a real read-only deployment uses, which is the configuration the original bug was found in. ## Helper naming `v2` called the helper `uncachedDaemonModePersistence()`. `v3` has no "daemon mode" in its vocabulary, so it is `uncachedReadModePersistence()` here, naming what it actually configures: read store mode, cache off. The "no data source" half is the caller's doing -- it passes this as the only configurer -- and is noted in the helper's comment. ## Red/green evidence A/B against the Ruby SDK's Consul store, whose collection read had exactly this bug. Same harness binary, same containers, service restarted between sides and port 9000 confirmed free in between. **Before** (Consul store reading the collection with `Diplomat::Kv.get(prefix, {recurse: true})`): ``` FAILED TESTS (2): * persistent data store/consul/collection cardinality/collection holds one flag * persistent data store/consul/collection cardinality/collection holds one flag and it is deleted Test Summary: 51 total, 35 skipped, 16 ran ``` Failure messages: ``` all-flags never served the only flag in the collection all-flags never reported a valid, empty state; expected {"$valid": true, "$flagsState": {}} ``` **After** (`Diplomat::Kv.get_all`): ``` All tests passed Test Summary: 51 total, 35 skipped, 16 ran ``` Redis and DynamoDB pass on both sides, as expected for a Consul-specific bug. Full persistence suite on the fixed build, to confirm the new subtree does not disturb the existing ones: `126 total, 14 skipped, 112 ran`, all passed. The 14 skipped are the sibling top-level suites excluded by the `-run` filter; nothing inside `persistent data store` skipped. Note that case 3 (empty collection) passes on **both** sides. The buggy Consul implementation already special-cased the empty result, so that case is not a regression detector for this particular bug -- it covers the complementary "sentinel instead of empty list" failure mode, which is a distinct risk for other store implementations. `gofmt` and `go vet` clean. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Ports **collection-cardinality** coverage into the v3 server-side persistent-store harness (from v2 #463, SDK-3174). > > Adds a top-level **`collection cardinality`** subtree that exercises **all-flags** (whole-collection reads) when the store has **one live flag**, **one tombstone only**, or **zero flags**—sizes the rest of the suite never hits because it usually seeds three or four items. Cases use **no data source**, **read-only store mode**, and **cache off** so reads go straight to the backing store (Redis, Consul, DynamoDB per capability). > > New helpers **`uncachedReadModePersistence`**, **`requireEmptyAllFlagsState`**, and **`requireFlagNotFound`** assert valid empty all-flags state (`$valid: true`) and flag-not-found evaluation, including a by-key check in the single-flag case to separate collection-read bugs from per-key reads. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e2bc08c. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BEGIN_COMMIT_OVERRIDE
fix: Verify all-items reads for empty and single-item collections
END_COMMIT_OVERRIDE
Adds three cases to the persistent-store suite that read an all-items collection holding one item or no items at all. SDK-3174.
The gaps
Reading a whole collection is a different code path from reading one record by key, and the shape of its result changes with the number of records. Two sizes are hazardous and neither is covered today.
A collection of exactly one item. A database client may return a single matching row on its own rather than inside a list. A store wrapper that assumes a list then fails the whole collection instead of one item, so every flag falls back to its default. This is a client-library behaviour, not a language one, so any SDK whose wrapper assumes a list is exposed. It is reachable whenever a data kind holds one record — a single-flag project, or a project where all but one flag is deleted.
An empty collection. A brand-new store holds no records for a kind. Clients signal "no match" in different ways — a 404, a sentinel value, an exception — so a wrapper has to ask for the behaviour it wants explicitly. Get it wrong and the first read of a fresh store raises instead of returning nothing.
Evidence the sizes are uncovered
The collection sizes the suite reads were measured by instrumenting an SDK's Consul store through a full
-run 'persistent data store'pass. The only sizes ever read were 3 (three times) and 4 (once). One and zero never occur, in this suite or in that SDK's own spec suite.What the cases assert
All three sit in the daemon-mode sub-tree, under
daemon mode/collection cardinality, and run for every store the harness supports (Redis, Consul, DynamoDB). Daemon mode is the right home: there is no data source, so everything the SDK serves comes out of the store, and the cache is off so every read reaches it. The all-flags call is the trigger for the collection read — a single flag evaluation reads one record by key and does not exercise it.collection holds one flagcollection holds one flag and it is deleted{"version":N,"deleted":true}{"$valid": true, "$flagsState": {}}, and the deleted key evaluates asFLAG_NOT_FOUNDcollection holds no flags$validcarries the weight in the two empty results: a read that failed reportsfalse, a read that succeeded and found nothing reportstrue. Without it, a store that raises looks the same as a store that correctly returned no flags.Results
Single-item case — red/green against a real defect. An SDK whose Consul store read the collection recursively through a client call that collapses to a bare value when exactly one key matches the prefix, so iterating the result raised on a type error.
Against the unfixed store:
The SDK log for the same run shows the cause, and shows the by-key read succeeding first, which is what separates a broken collection read from a broken record:
Against the fixed store, all nine cases (three stores x three cases) pass, and the full persistence suite is green:
101 total, 13 skipped, 88 ran. Redis and DynamoDB pass on both sides — the defect was specific to one client library, so they are the control.Empty-collection case — no failing SDK to point at. No shipped SDK is known to get this wrong, so there is no genuine red/green to show. Two things were confirmed instead.
The read really happens. Watching the Redis command stream during the case shows the harness emptying the store and the SDK then reading the whole collection:
The case is load-bearing. The Consul wrapper gets an empty list for a fresh store only because it passes an explicit "not found means return" argument to its client; the client's default raises instead. Restoring that default at run time (by patching the client, with no change to the SDK) leaves every pre-existing Consul persistence test green and fails only the new case:
That is a synthetic defect, not a shipped one, but it shows the case would catch the mistake it is written for and that nothing else in the suite would.
Notes
gofmt,go vet, andgolangci-lint(repo-pinned v2.11.1) are clean.Note
Overview
Adds a
daemon mode/collection cardinalitysub-suite to the server-side persistent-store harness, wired fromserver_side_persistence_base.goand implemented in a newserver_side_persistence_cardinality.go.The three cases exercise whole-collection reads (via evaluate-all-flags) for store sizes the rest of the suite never hits: one live flag, one tombstone-only entry, and an empty features map. Assertions pair per-key evaluation with all-flags behavior, including
$valid: trueand an empty$flagsStatewhen nothing is served, plusFLAG_NOT_FOUNDon single-flag reads where appropriate. Tests run uncached daemon mode so every read goes to the backing store (Redis, Consul, DynamoDB).Shared helpers
uncachedDaemonModePersistence,requireEmptyAllFlagsState, andrequireFlagNotFoundkeep the scenarios consistent and poll-friendly during SDK startup.Reviewed by Cursor Bugbot for commit dab4cbf. Bugbot is set up for automated code reviews on this repo. Configure here.