Repository navigation
fix: Verify all-items reads for empty and single-item collections - #466
Merged
Merged
Conversation
jsonbailey
marked this pull request as ready for review
September 25, 2026 21:32
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f076f7c. Configure here.
keelerm84
approved these changes
Sep 28, 2026
jsonbailey
force-pushed
the
jb/sdk-3174/collection-cardinality-v3
branch
from
September 28, 2026 16:58
f076f7c to
d0251be
Compare
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. The rest of the suite only reads collections of three or four items, so these cases cover the two sizes it never produces.
jsonbailey
force-pushed
the
jb/sdk-3174/collection-cardinality-v3
branch
from
September 28, 2026 18:48
d0251be to
e2bc08c
Compare
jsonbailey
added a commit
that referenced
this pull request
Sep 28, 2026
Ports the persistent-store tombstone-shape tests from `v2` (#438) to `v3`. Jira: SDK-3174. ## What the cases cover A tombstone is the record an SDK writes to a persistent store to mark an item deleted. Version-based conflict resolution needs it: with no record at all, a stale out-of-order update would bring the item back. The store already addresses the record by key -- the Redis hash field, the Consul key, or the DynamoDB sort key -- so the key inside the JSON body is redundant. Our SDKs write three different shapes anyway: | shape | written by | |---|---| | `{"version":N,"deleted":true}` (no key) | .NET, Java, Node (Redis upsert), Haskell | | `{"key":"<real key>","version":N,"deleted":true}` | Python, Ruby, C++, Erlang, Node (init) | | full object keyed `"$deleted"` | Go v5+, Relay Proxy, Rust | Any SDK can be pointed at a store a different SDK wrote, so a reader has to handle all three. Each shape gets two cases: 1. **flags** -- a tombstone sits alongside the live flags. The live flags must still be readable (one unrecognized record must not spoil the whole collection), the deleted flag must be absent from all-flags state, and asking for it by key must look identical to asking for a flag that was never there (`FLAG_NOT_FOUND`). 2. **segments** -- a flag matches the deleted segment. A deleted segment matches nothing, so the flag must serve `not-matched`. The full-object shape carries the evaluation context in `included`, so a reader that mistakes the tombstone for a live segment serves `matched` instead. 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("tombstones", ...)` next to `t.Run("read-write", ...)`, matching the placement of the sibling cardinality port in #466. Store mode governs the write path. With no data source there is nothing to write, so read mode is the only mode these cases need. That is also what `v2` got implicitly -- its `daemonModePersistence` set no store mode, and `v3` defaults `StoreMode` to `DataStoreModeRead`. All helpers the `v2` file depended on exist unchanged on `v3` (`runWithEmptyStore`, `initialFlags`, `defaultPrefix`, `WriteMap`, `EvalAllFlagsStateMap`, `makeFlagToCheckSegmentMatch`, `pollUntilFlagValueUpdated`). Only the import paths changed from `v2` to `v3`. ## Overlap with #466 `v2` named its store configurer `daemonModePersistence`, which does not fit `v3`'s vocabulary. This branch renames it to `uncachedReadModePersistence`, identical in name and body to the one #466 adds. **#466 has not merged yet, so both branches define it.** Whichever merges second must delete its copy -- the two helpers are byte-identical, so it is a delete, not a reconciliation. Because they live in different files it will surface as a duplicate-symbol build failure rather than a text conflict, so it is worth watching for. ## Red/green evidence A/B against the Ruby SDK, which had a store wrapper that keyed its all-items read off the key inside the record body. A keyless tombstone therefore lands under an empty key and corrupts the collection. **Before** (`items_out[item[:key].to_sym]`): ``` FAILED TESTS (2): * persistent data store/consul/tombstones/flags/body has no key * persistent data store/dynamodb/tombstones/flags/body has no key Test Summary: 66 total, 35 skipped, 31 ran ``` Both failures report the same thing -- all-flags came back as a failed read that served nothing, so the live flag was gone too: ``` result reason map key "flag-key" not found full value was: {"state":{"$flagsState":{},"$valid":false}} ``` **After** (`items_out[db_key[prefix.length..].to_sym]`): ``` All tests passed Test Summary: 66 total, 35 skipped, 31 ran ``` Redis passes on both sides. Full persistence suite on the fixed build, to confirm the new subtree does not disturb the existing ones: `141 total, 14 skipped, 127 ran`, all passed. The 14 skipped are the sibling top-level suites excluded by the `-run` filter; nothing inside `persistent data store` skipped. ## Two cases cannot fail for the keying bug Worth stating so nobody reads a green as a signal it is not: - **The whole segments sub-tree.** A flag matching a segment reads that one segment by key, so nothing in those cases triggers an all-segments read -- which is the only thing this bug class affects. Confirmed above: the buggy build passes all three segment cases and fails only the flags one. - **The `$deleted` full-object shape.** For a *deleted* item, a body-keyed store files it under `$deleted` and a store-keyed one files it under the real key. Either way the deleted-filter drops it, so the result is identical. Verified empirically against live Consul. They are included anyway, because they are cheap guards against parse failures and resurrection bugs, which are real and distinct defect classes. No assertion was added to try to make them detect the keying bug. `gofmt` and `go vet` clean. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Adds a **tombstones** subtree to the v3 server-side persistent store harness (alongside **collection cardinality**), ported from v2. The suite seeds Redis, Consul, and DynamoDB with each of the three cross-SDK tombstone JSON shapes—keyless `{"version", "deleted"}`, body key repeating the store key, and full objects whose inner key is `"$deleted"`—then runs with **no data source** and **uncached read mode** so reads come straight from the store. > > **Flag cases** assert a tombstone next to live flags does not break the collection, the deleted key is missing from all-flags state and metadata, and single-flag evaluation returns the default with **`FLAG_NOT_FOUND`**. **Segment cases** use a flag that would match if the tombstone were treated as live; evaluation must stay **not-matched**, including when the full-object shape embeds the context in `included`. > > Also adds `requireFlagAbsentFromAllFlags` to guard both flag values and `$flagsState` entries for deleted keys. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 832cdad. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
joker23
pushed a commit
that referenced
this pull request
Oct 8, 2026
🤖 I have created a release *beep* *boop* --- ## [3.2.0-alpha.11](v3.2.0-alpha.10...v3.2.0-alpha.11) (2026-10-08) ### Features * adding client side bootstrap tests ([#462](#462)) ([9c1810d](9c1810d)) * Port client-side prerequisite cycle detection tests to v3 ([#473](#473)) ([7e65a58](7e65a58)) * port client-side streaming retry contract tests to v3 ([#475](#475)) ([f968442](f968442)) ### Bug Fixes * Verify all-items reads for empty and single-item collections ([#466](#466)) ([489a780](489a780)) * Verify SDKs read all three persistent-store tombstone shapes ([#484](#484)) ([a9a0696](a9a0696)) --- 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] > **Overview** > **Release 3.2.0-alpha.11** — automated version bump only: `.release-please-manifest.json`, `versionString` in `main.go`, and a new `CHANGELOG.md` section. > > The changelog documents what ships in this alpha: **new contract coverage** for client-side bootstrap, prerequisite cycle detection (ported to v3), and streaming retry behavior; plus **harness fixes** for all-items reads on empty/single-item persistent-store collections and for all three persistent-store tombstone shapes. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1a2073d. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

Ports the persistent-store collection-cardinality tests from
v2(#463) tov3. 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:
{"version":N,"deleted":true}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
v3restructured this suite, so the wiring fromv2does not apply:t.Run("daemon mode", ...)store mode %s - no data source/- with data source, looped overdatabaseModesSetStore,SetCacheSetStoreMode(servicedef.DataStoreMode)v2hung these cases off thedaemon modesubtree. Onv3the equivalentconfiguration is "no data source": nothing but the store populates data. Rather
than reach into the
databaseModesloop, the cases sit in their own top-levelt.Run("collection cardinality", ...)next tot.Run("read-write", ...), whichis the existing
v3precedent for a subtree that owns its store-mode config.All helpers the
v2file depended on exist unchanged onv3(
runWithEmptyStore,initialFlags,defaultPrefix,WriteMap,EvalAllFlagsValueForKeyShouldEqual,pollUntilFlagValueUpdated);requireEmptyAllFlagsStateandrequireFlagNotFoundare defined in thecardinality 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
v2called the helperuncachedDaemonModePersistence().v3has no "daemonmode" in its vocabulary, so it is
uncachedReadModePersistence()here, namingwhat 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})):Failure messages:
After (
Diplomat::Kv.get_all):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 14skipped are the sibling top-level suites excluded by the
-runfilter; nothinginside
persistent data storeskipped.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.
gofmtandgo vetclean.Note
Overview
Ports collection-cardinality coverage into the v3 server-side persistent-store harness (from v2 #463, SDK-3174).
Adds a top-level
collection cardinalitysubtree 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, andrequireFlagNotFoundassert 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.Reviewed by Cursor Bugbot for commit e2bc08c. Bugbot is set up for automated code reviews on this repo. Configure here.