Skip to content

fix: Verify all-items reads for empty and single-item collections - #466

Merged
jsonbailey merged 1 commit into
v3from
jb/sdk-3174/collection-cardinality-v3
Sep 28, 2026
Merged

jsonbailey merged 1 commit into
v3from
jb/sdk-3174/collection-cardinality-v3

Conversation

@jsonbailey

@jsonbailey jsonbailey commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

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.


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.

Reviewed by Cursor Bugbot for commit e2bc08c. Bugbot is set up for automated code reviews on this repo. Configure here.

@jsonbailey jsonbailey changed the title test: Verify all-items reads for empty and single-item collections fix: Verify all-items reads for empty and single-item collections Sep 25, 2026
@jsonbailey
jsonbailey marked this pull request as ready for review September 25, 2026 21:32
@jsonbailey
jsonbailey requested a review from a team as a code owner September 25, 2026 21:32

@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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

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
jsonbailey force-pushed the jb/sdk-3174/collection-cardinality-v3 branch from d0251be to e2bc08c Compare September 28, 2026 18:48
@jsonbailey
jsonbailey merged commit 489a780 into v3 Sep 28, 2026
6 checks passed
@jsonbailey
jsonbailey deleted the jb/sdk-3174/collection-cardinality-v3 branch September 28, 2026 18:55
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>
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