Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
395e44a
fix: only the winning experiment is exposed for a shared variable key
Nov 23, 2026
0243793
fix: a raising hook does not stop the shared-key walk; pin the loser …
Nov 23, 2026
538930d
perf: skip a shared-key candidate's holdouts once all are exposed; pi…
Nov 24, 2026
d0a8aec
test: pin the shared-key holdout flag across a failed close, the pre-…
Nov 24, 2026
582c110
fix: offer a shared-key winner's holdouts once per read; document lon…
Nov 24, 2026
bb98367
test: pin that a hook-path variable read leaves the winner's holdouts…
Nov 24, 2026
4eeddbb
docs: distinguish experiment exposures from candidate holdout exposures
Nov 24, 2026
f67458f
fix: make shared-key selection safe across lifecycle races
Nov 26, 2026
996671c
style: format shared-key lifecycle changes
Nov 26, 2026
a4e5cc9
fix: fire holdouts when no shared-key candidate wins; trim the warm r…
Nov 26, 2026
7024e32
fix: catch a unit added at any point of a shared-key walk; pin the ho…
Nov 27, 2026
5bcd83d
test: pin that re-setting a unit does not re-walk a shared key; clari…
Nov 27, 2026
4a9b0de
refactor: share native holdout acceptance and exposure logging; tidy …
Nov 27, 2026
78511c0
fix: re-walk a shared key after a refresh or unit change, peek includ…
Nov 27, 2026
e289ccc
fix: recompute an override placeholder once its experiment appears; c…
Nov 27, 2026
8db380e
fix: keep an exposed override across a refresh that removes its exper…
Nov 27, 2026
fce6d23
fix: keep an exposed override when a refresh changes its experiment's id
Nov 27, 2026
2f3023e
fix: give a kept override its experiment's variables once the experim…
Nov 27, 2026
6d6f70c
fix: fill a kept override's variables only for the same experiment; p…
Nov 27, 2026
80d68ec
test: pin that a kept override takes a variant a refresh adds to the …
Nov 27, 2026
261281d
fix: coherent final shared-key walk, per-read holdout offers, shared …
Nov 27, 2026
edb405d
fix: default when the last attempt's winner is retired; offer set onl…
Nov 27, 2026
91dd039
fix: judge a queue_exposure override by the assignment's state, not i…
Nov 27, 2026
df79187
fix: never hand a queue_exposure override an assignment set_unit alre…
Nov 27, 2026
17207ae
docs: note the warm variable-read cost of the lifecycle checks
Nov 27, 2026
4d5e509
fix: track offered holdout arms by object; qualify the changelog's no…
Nov 27, 2026
7ddd5dd
test: say the offered-arm test pins storage, not a reachable race
Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
- Holdouts, evaluated like the JS SDK. Context data may carry `holdouts` (each with `id`, `name`, `iteration`, `seedHi`, `seedLo` and `split`), and an experiment lists the holdouts covering it in `holdoutIds`. Each covering holdout places the unit in an arm, drawn from the holdout's `split` and seeds with the covered experiment's unit, and kept for the context while the holdout's `iteration` is unchanged. Arm 0 holds the unit out of the experiment; in a holdout with three arms, arm 1 holds the unit out only of experiments that are not full-on. A unit held out by any of its holdouts gets the control variant (`assigned` false), and audience, full-on, traffic and custom assignments do not apply. A variable read returns the held-out experiment's control value only when no assigned or overridden experiment defining the same key wins it. The held-out experiment publishes no exposure of its own, unless an override or a matching assignment rule chose its variant: both still win over the holdout. The first treatment or variable read of a covered experiment queues each holdout's exposure, named after the holdout, with the arm as its variant. That happens once per holdout, unit type and holdout iteration, however many reads or covered experiments follow; a new iteration is a new exposure. While the covered experiment's unit is not set, a holdout neither holds the unit out nor publishes. `peek_treatment` and `peek_variable_value` publish nothing. Payloads without holdouts are assigned and published exactly as before.
- `ContextData.holdouts`, `Experiment.holdoutIds` and `Experiment.holdoutType` (all default `None`) and `sdk.json.holdout.Holdout`. Holdout entries may be the dicts the default deserializer produces, any `Mapping`, or objects with the same attributes; entries without a non-empty `split`, malformed entries (for example ids, seeds or split values that are not JSON numbers) and unknown fields are ignored.

### Fixed
- Shared variable keys: only the winning experiment is exposed. When two or more running experiments define the same variable key, `get_variable_value` queued an exposure for every experiment it checked on the way to the value, including ones the unit was not in (a strict audience mismatch, or a unit type that is not set for an experiment that is not full-on), so those users were recorded in experiments they never saw. And when the first experiment the unit was in had given it a variant without the key, the read fell through to the next experiment, so which experiment supplied the value (and was exposed) depended on the arm the unit got, biasing both experiments. Anyone with two or more running experiments sharing a variable key is affected; their exposure counts for the losing experiments drop after upgrading. So is anyone reading a key that only one experiment defines when the unit is not in it: a strict audience mismatch or a unit type that is not set used to be exposed by `get_variable_value` (a strict mismatch with `audienceMismatch` true) and now nothing wins the key, so no experiment exposure is published. A visited candidate can still publish its holdouts’ exposures when its unit is set. `get_treatment` still exposes such an experiment. The rule now applied, as in the Java SDK: the candidates are the experiments defining the key in any variant, in id order; the first one the unit is assigned to, overridden in or rule-assigned to wins; if the winner's variant lacks the key the default is returned; only the winner is exposed. When no candidate wins, the first held-out candidate supplies its control value, else the default is returned with no exposure. `peek_variable_value` resolves the same winner and exposes nothing. Holdout exposures are unchanged in kind: each candidate checked still publishes its holdouts' exposures, now before the winner's own exposure. An overridden or rule-assigned held-out experiment now wins the key like any other override or rule, so its variant lacking the key returns the default instead of a later experiment's value.

### Changed
- Exposure counts change for experiments read with `get_variable_value`: an experiment the unit is not in (a strict audience mismatch, or a unit type that is not set for an experiment that is not full-on) is no longer exposed by a variable read, even when it is the only experiment defining the key, and an experiment that is checked for a shared key but does not win it is no longer exposed, and a winner whose variant lacks the key returns the default instead of a later experiment's value. See Fixed. This includes an override to a variant number the experiment does not have: the overridden experiment wins the key and is exposed, and the default is returned (0.3.0 skipped it and used the next experiment).
- A variable read stays consistent across the context lifecycle: when `set_unit` adds a unit while the read is checking the key's experiments, the read checks the key again before exposing the winner, and if it never sees one consistent state within its attempts it returns the default without exposing any winner (holdout exposures of experiments it had already checked may already have been published, once each); an experiment a concurrent `refresh` removed never wins the key (a refresh during the read makes it check the key again, `peek_variable_value` included); and the built-in queue accepts the winner together with its holdouts, so a concurrent close publishes both or neither.
- An override set for an experiment the context data does not have yet is exposed again with the experiment's real id once a refresh adds that experiment (0.3.0 kept the first exposure, queued with id 0). An override already exposed for a present experiment is still not exposed again when a refresh removes and restores it, or changes its id, as long as the cached override stays valid (a refresh that changes the experiment's holdouts or their iteration rebuilds it, which publishes a new exposure as for any rebuilt assignment).
- A warm `get_variable_value` is slightly slower (about 7% for a single candidate in a CPython microbenchmark, about 0.4 µs) because each read now checks for a concurrent refresh or `set_unit` before exposing anything. `get_treatment` is unchanged.
- A `queue_exposure` override that returns `False` (declines) is called once per read again, as in 0.3.0, and the read still returns the variant's value; a retry happens only when `set_unit` actually retired the experiment.
- A `queue_exposure` override that raises while being offered a holdout exposure no longer stops the remaining holdout exposures of that read (from `get_treatment` or `get_variable_value`): every one is offered and the first error is raised afterwards, as in the Java SDK.
- Payloads with `holdouts` change assignment for held-out units. 0.3.0 ignored holdouts, so a unit the backend holds out still got its experiment's variant and an experiment exposure. From 0.4.0 that unit gets the control variant, and the holdout's exposure replaces the experiment's. Units that are not held out keep their variants, but their reads of covered experiments now also publish the holdout exposures. Payloads without holdouts are unaffected.
- The `X-Agent` header and `sdk_version` report `0.4.0`.

Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ else:
button_color = context.get_variable_value("button.color", "red")
```

#### Shared Variable Keys

When several experiments define the same variable key (in any of their variants), `get_variable_value` and `peek_variable_value` check them in experiment id order and use the first one the unit is in: assigned (including a unit outside traffic, which gets control), overridden with `set_override`, or chosen by an assignment rule. That experiment wins the key:

- The value comes from the winner's variant. If that variant does not define the key, the default you passed is returned; later experiments are not consulted, so which arm the unit got never changes which experiment is used.
- Only the winner is exposed. Experiments that were checked and lost (for example a strict audience mismatch, or a unit type that is not set for an experiment that needs it for traffic assignment) get no exposure. A full-on experiment does not need its unit, so it can win and be exposed with the unit unset.
- This also applies when only one experiment defines the key: if the unit is not in it (a strict audience mismatch, or a unit type that is not set for an experiment that is not full-on), nothing wins, the default is returned and no experiment exposure is published. A non-suppressing holdout can still publish its exposure when the candidate’s unit is set. `get_treatment` still exposes that experiment.
- If no experiment wins, a held-out experiment defining the key supplies its control value (see [Holdouts](#holdouts)); otherwise the default is returned and no experiment exposure is published (the checked experiments' holdouts can still publish theirs).
- `peek_variable_value` resolves the same winner and exposes nothing.

#### Listing Variable Keys

`get_variable_keys()` maps each variable key to the name of one experiment that defines it, keeping the v0.2.4 shape. When several experiments define the same key, it returns the lowest-id experiment (the first one variable lookups visit). Use `get_variable_keys_all()` to get every experiment defining each key, in experiment id order, matching the JavaScript SDK's `variableKeys()`.
Expand Down Expand Up @@ -297,7 +307,7 @@ treatment = context.get_treatment("exp_covered_by_holdout") # 0 when held out
color = context.get_variable_value("button.color", "red") # control value when held out
```

Unless an override or a matching assignment rule chose its variant, the held-out experiment publishes no exposure of its own. The first read of a covered experiment (`get_treatment`, `get_variable_value`) instead publishes each holdout's exposure, named after the holdout, with the unit's arm as its variant. Each holdout is published once per unit type and holdout iteration, however many covered experiments are read; a new iteration publishes again. A holdout needs the covered experiment's unit: while that unit is not set, the holdout neither holds the unit out nor publishes. `peek_treatment` and `peek_variable_value` publish nothing.
Unless an override or a matching assignment rule chose its variant, the held-out experiment publishes no exposure of its own. The first read of a covered experiment (`get_treatment`, `get_variable_value`) instead publishes each holdout's exposure, named after the holdout, with the unit's arm as its variant. Each holdout is published once per unit type and holdout iteration, however many covered experiments are read; a new iteration publishes again. A variable read checks every experiment defining the key up to the winner (see [Shared Variable Keys](#shared-variable-keys)), and each one it checks publishes its holdouts' exposures, even when it does not win; its own exposure is published only if it wins. A holdout needs the covered experiment's unit: while that unit is not set, the holdout neither holds the unit out nor publishes. `peek_treatment` and `peek_variable_value` publish nothing.

An override (`set_override`) or a matching assignment rule still decides the variant of a held-out unit, and the holdout exposures are still published. Custom assignments, audiences, full-on variants and traffic do not apply to a held-out unit.

Expand Down
Loading
Loading