Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
f657252
feat(switchback): serve R33 cluster-defined switchback experiments (F…
Nov 18, 2026
0ea0924
test(switchback): port the java-sdk context suites and close mutation…
Nov 18, 2026
6876833
fix(switchback): never serve a unit assignment cached before the expe…
Nov 18, 2026
68168ff
test(switchback): port java-sdk's ContextSwitchbackClusterTest; compa…
Nov 18, 2026
dec9bed
fix(switchback): admit only scalar allow-list entries; indexed loop (…
Nov 18, 2026
32ff869
test(switchback): pin epoch slot cleanup and boolean allow-list entri…
Nov 18, 2026
c7f8f2f
fix(switchback): keep period slots apart from unit assignments; addre…
Nov 18, 2026
3a78022
fix(switchback): serve switchbacks named like Object members (FT-2537)
Nov 18, 2026
2cfdca0
fix(switchback): keep the period-less slot in the epoch record too (F…
Nov 18, 2026
1b07e09
fix(switchback): drop a pre-switchback unit assignment with the epoch…
Nov 18, 2026
c6be7f7
test(switchback): describe where switchback slots live in two test co…
Nov 18, 2026
4f054c4
fix(switchback): remove invalidated period indices on late unit insta…
Nov 18, 2026
808516a
test(switchback): pin the large-seed boundary result directly (FT-2537)
Nov 18, 2026
2dec9f6
fix(switchback): keep invalidated period indices retained, as Java do…
Nov 19, 2026
3fdeb0e
test(switchback): an override on an ineligible cluster is recorded un…
Nov 19, 2026
e7de3f2
docs(switchback): qualify the once-per-period cluster read with the r…
Nov 19, 2026
c24d828
test(switchback): use independent reference schedules as the parity o…
Nov 19, 2026
3c721bc
test(switchback): describe the parity suite's reference schedules (FT…
Nov 19, 2026
52448cf
docs(switchback): note that an override still applies to an ineligibl…
Nov 19, 2026
a3f5119
test(switchback): drop the repeated reference explanation from the pa…
Nov 19, 2026
9558ec5
fix(context): keep shared variable winner independent of switchback arm
Nov 23, 2026
3617447
fix(context): expose only the winning experiment for shared variable …
Nov 24, 2026
8135d2a
docs: document shared variable key winner and exposure rule
Nov 24, 2026
4e745c4
test,docs: pin a silent switchback winner; align docs with winner-onl…
Nov 24, 2026
e4f5d5c
fix(context): accept variables named like Object.prototype members
Nov 24, 2026
3800b66
test(context): cover empty and non-object configs with prototype-name…
Nov 24, 2026
bd0ba5a
perf(context): retain ordinary object layouts with safe own-key lookup
Nov 24, 2026
e60fe39
perf(context): restrict own-key checks to prototype-named variables
Nov 24, 2026
2aa9a2d
docs: qualify switchback-only unchanged-unit claim
Nov 24, 2026
1f1363f
perf(context): classify prototype-key configs at indexing time
Nov 24, 2026
8508df6
fix(context): queue every exposure of a variable read before user cal…
Nov 24, 2026
37be5be
fix(context): defer variable-read callbacks without per-read cost; re…
Nov 24, 2026
c4f73b8
perf(context): outline the deferred-callback replay; fix refresh and …
Nov 24, 2026
20cc4c7
refactor(context): skip the winner's second holdout walk; tidy shared…
Nov 24, 2026
91a3892
fix(context): replay deferred callbacks in queue order under one defe…
Nov 24, 2026
22dd636
test(context): pin single holdout walk, nested treatment() deferral a…
Nov 24, 2026
50e38b0
test(switchback): pin period-less slot reclassification; tidy docs
Nov 24, 2026
9e0dc3f
fix(context): bound observer feedback while retaining ordered replay
Nov 24, 2026
513ce45
fix(context): bound callback replay by rounds instead of dropping cal…
Nov 24, 2026
7ab3c8e
fix(context): keep replay exhaustion sticky until the outer replay ends
Nov 24, 2026
7b6bbbf
test(context): pin treatment() exhaustion and its reset; tighten docs
Nov 24, 2026
c7b4241
test(context): pin the iterator-free candidate walk; docs cleanup
Nov 24, 2026
aabe26c
fix(context): keep each call's exposure batch intact at the replay limit
Nov 24, 2026
65cb7a8
docs: describe the replay limit batch rule and held-out default
Nov 24, 2026
e546a77
fix(context): restore a refreshed arm's variables; pin post-limit del…
Nov 25, 2026
24658b5
fix(switchback): follow a refreshed arm in switchback slots; docs
Nov 25, 2026
aa09983
test(context): pin switchback slot arm-following, post-limit timer an…
Nov 25, 2026
acd0951
test(switchback): pin non-override period-less arm refresh
Nov 25, 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
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ js
lib
types
package-lock.json
# Vendored byte-for-byte from absmartly/abs; never reformat.
src/__tests__/fixtures/switchback
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

## 1.14.0 (unreleased)

Earlier release notes are on the [GitHub releases page](https://github.com/absmartly/javascript-sdk/releases); the [Migration Guide](README.md#migration-guide-113x--1140) lists the other changes in 1.14.0.

### Added

- Switchback experiments (R33, cluster-defined): an experiment with `randomizationType: "switchback"` is served by cluster and period through the existing `treatment()`, `peek()`, `variableValue()` and `peekVariableValue()`, matching the collector and java-sdk. `ExperimentData` gains the optional `randomizationType`, `switchbackClusters`, `switchbackClusterValues`, `switchbackStartAt`, `switchbackPeriodMs`, `switchbackCarryoverDurationMs`, `switchbackBurnInDurationMs`, `switchbackBurnOutDurationMs`, `switchbackDesignType` and `switchbackEstimand` fields. There is no new method or option. See [Switchback Experiments](README.md#switchback-experiments).
- Known limitation: JavaScript cannot tell `3.0` from `3`, so a cluster attribute set to an integral float is keyed like the integer (`"3"`), where other SDKs give a float no cluster value. A cluster map with two or more linked unit types, one named like an array index (`"1"`), cannot keep its declared order in JavaScript, so it is served as an ineligible control (variant 0, no exposure).

### Changed

- Shared variable keys pick and expose one experiment, as the Java SDK does. Before, `variableValue()` exposed every experiment it checked that had the key, including ones the unit was not in (for example a strict audience mismatch or a switchback that gives way), which recorded users in experiments they never saw; and when the first experiment's selected variant lacked the key, a later experiment's value was served and exposed, so which experiment a unit was counted in depended on its arm, biasing the result. Now candidates are the experiments defining the key in any variant, by experiment id ascending; the winner is the first one the unit is in (assigned, overridden or rule-assigned), whatever its arm, and returns its variant's value (`null`, `false`, `0` and `""` included) or the caller default if that variant lacks the key. With no winner, a held-out candidate supplies its control value, otherwise the caller default. Only the winner is exposed (an out-of-range overridden, custom or full-on winner is exposed with that variant; a silent switchback winner, before its schedule starts or with an ineligible cluster, returns control and records nothing); each checked candidate's applicable holdouts still fire, as in Java. `peekVariableValue()` exposes nothing. A `variableValue()` read queues all its exposures before its `exposure` and `error` callbacks run, and a `treatment()` with holdouts queues its exposures before their `exposure` callbacks (an audience `error` raised by `treatment()` itself is still reported first), so a callback that calls `finalize()` or `publish()` sends every one of them; such a callback now sees them already pending. Callbacks a callback raises are replayed after the ones already held, in queue order; once a replay has run a bounded number of rounds or callbacks, each later call delivers its own callbacks as soon as all of its exposures are queued, so runaway logger feedback stays bounded in stack and memory and each call still sends its whole batch. A cached `variableValue()` or `peekVariableValue()` (four experiments sharing a key) is about 3x faster than the previous unreleased build (about 21–26 vs 65 ns, versus about 155 ns in 1.13.4) and no longer allocates; `treatment()` and `peek()` are unchanged within noise (shared-host measurements, approximate). A cached assignment or switchback slot whose arm a refresh removes returns the caller default (1.13.4 kept serving the removed arm's value) and gets the arm's values back if a later refresh restores it. Keys no experiment defines return the default, including names like `toString` or `__proto__`; a variant config that defines such a key (`toString`, `constructor`, `__proto__`) no longer fails the context. Who moves: anyone with two or more running experiments sharing a variable key, and anyone counting exposures from `variableValue()` on an experiment the unit is not in (use `treatment()` to record those).
- Switchback experiments that are already running change assignment for this SDK: before, they were served as a sticky unit assignment on their `unitType` (or not at all), which did not follow the switchback schedule. Now each unit gets its cluster's scheduled variant for the current period unless an override, assignment rule, strict audience mismatch, full-on setting, a not-yet-started schedule (control, no exposure), a traffic miss or `customAssignment()` decides it first (see Switchback Experiments in the README for the exact order), and exposures are recorded once per period under the serving unit, while that period's assignment stays cached. Who moves: customers who run switchback experiments. The switchback support itself does not change unit experiments or context data without switchbacks; the separate shared-variable-key fix above can change their variable reads.
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,23 @@ const defaultButtonColor = "red";
const buttonColor = context.variableValue("button.color", defaultButtonColor);
```

#### Shared variable keys

When several experiments define the same variable key, the SDK checks them in
ascending experiment id and uses the first one the user is in (assigned,
overridden or assigned by a rule). Its variant's value is returned, or your
default if that variant does not define the key; later experiments are never
used instead. If the user is in none of them but one is held out by a holdout,
the first held-out experiment's control value is returned, or your default if
its control arm does not define the key (no other experiment is checked). Only
the winning experiment gets an exposure (plus any holdouts covering the
experiments checked); a held-out experiment that supplies its control value
records only its holdout's exposure. An experiment the user is not in, such as a
strict audience mismatch, gets none; call `treatment()` to record it. A
switchback that wins but is silent (before its schedule starts, or with an
ineligible cluster) returns its control value and records nothing, and later
experiments are still not used. `peekVariableValue()` never queues an exposure.

### Peek at Treatment Variants

Although generally not recommended, it is sometimes necessary to peek at a treatment without triggering an exposure. The A/B Smartly SDK provides a `peek()` method for that.
Expand Down Expand Up @@ -252,6 +269,29 @@ context.overrides({
});
```

### Switchback Experiments

A switchback experiment randomizes *clusters* over time instead of units. A cluster is a value of a context attribute, for example a store's region. Every unit in the same cluster sees the same variant during a period, and the variant changes on a fixed time grid. There is nothing new to call: `treatment()`, `peek()`, `variableValue()` and `peekVariableValue()` serve switchback experiments, and the A/B Smartly collector sends their configuration with the context data.

```javascript
context.units({ store_id: "store-1234" });
// The experiment links the store_id unit type to the attribute path "region".
context.attribute("region", "lisbon");

const variant = context.treatment("exp_delivery_fee"); // the "lisbon" cluster's variant for this period
```

How a switchback is served (the contract the A/B Smartly collector serves; java-sdk implements the same):

- **Cluster.** The experiment lists linked unit types, each with an attribute path, in a significant order. For each linked type the context has a unit of, in that order, the SDK reads the attribute at the path. The first unit that gives a value serves, and its value is the cluster key. If a later unit gives a different value, the cluster is ineligible.
- **Values.** A non-empty string is used as-is, and a whole number below `1e21` in magnitude as its decimal text (`17` and `"17"` are the same cluster). Numbers beyond `Number.MAX_SAFE_INTEGER` lose precision in JavaScript before the SDK sees them, so set large identifiers as strings. Fractions, booleans, objects, arrays, empty strings and `null` give no value. **JavaScript cannot tell `3.0` from `3`**, so a number written as `3.0` is the cluster `"3"`, like the integer; other SDKs give a float no value. Set cluster attributes as strings or integers. A cluster map whose unit type names look like array indexes (`"1"`, `"2"`) cannot keep its order in JavaScript, so with two or more linked types such an experiment is served as an ineligible control.
- **Paths.** `/` separates segments (`profile/region`, `items/0/region`), a quoted segment is a literal key (`'a/b'`), and an unquoted number indexes an array. An index must be non-negative and sit between two key segments (`items/0` and `items/0/1/region` are unreadable). A `.` anywhere makes the path unreadable: nest with `/`. The first segment names an attribute set with `attribute()`; the value read is the latest one set at or before the call.
- **No linked unit:** the experiment does not apply (variant 0, nothing recorded; a variable lookup returns its default), though an `override()` still applies and is recorded. **Ineligible cluster** (no value, units disagree, or a value outside the experiment's allowed values): variant 0 and no exposure, unless an `override()` is set, which still applies and is recorded under the first linked unit present. **Unreadable cluster map** (missing, empty or with an unreadable path): an ineligible control when the context has a unit of the experiment's `unitType`, otherwise the experiment does not apply.
- **Precedence** for an eligible cluster: `override()`, then assignment rules (a `split` rule randomizes over the serving unit), a strict audience mismatch (variant 0, recorded), full-on, then the schedule. Before the schedule starts, or when it cannot be served, the result is variant 0 with no exposure. Then traffic (on the serving unit; a miss is recorded as not eligible), `customAssignment()`, and the schedule draw over the cluster key. **Holdouts never apply to switchback experiments.**
- **Exposures.** One exposure per experiment and period while that period's assignment stays cached, under the serving unit's type, with the same fields as any other exposure. As for other experiments, an assignment that is resolved again within the period (after a refresh or an attribute change alters its outcome, or a clock moved back past the two retained periods) records another exposure. Its `exposedAt` is the time at which the call chose the period. While the period's assignment stays cached, the cluster is read once: a later `attribute()` in the same period does not move the unit to another cluster, and the next period reads the attributes afresh. A clock moved back past the two retained periods reads the cluster afresh too, and can select a different cluster. Attributes are published as usual; the collector reads the cluster from them. On a variable key shared with other experiments, a switchback follows the same rule as unit experiments (see [Shared variable keys](#shared-variable-keys)): only the winner is exposed, so a strict-mismatched switchback checked before the winner records nothing.

The schedule follows the device clock (`Date.now()`), so a device whose clock is wrong is served another period's variant.

## Advanced

### Context Attributes
Expand Down Expand Up @@ -360,6 +400,15 @@ The data parameter depends on the type of event. Currently, the SDK logs the fol
| `"goal"` | `track()` method succeeds | Goal data enqueued for publishing |
| `"finalize"` | `finalize()` method succeeds the first time | undefined |

`"exposure"` and `"error"` events raised by one `variableValue()` call (and the
`"exposure"` events of one `treatment()` call) are delivered after all of that
call's exposures are queued, in the order they were raised, so a logger that
calls `publish()` or `finalize()` sends every one of them. `"exposure"` and
`"error"` events a logger triggers itself are delivered after the ones already
waiting (other events, such as a `"goal"` from `track()`, are delivered
immediately); after a bounded number of rounds or callbacks, each later call delivers its own
events together, once all of that call's exposures are queued.

### HTTP Request Timeout

It is possible to set a timeout per individual HTTP request, overriding the global timeout set for all requests when instantiating the SDK object.
Expand Down Expand Up @@ -554,6 +603,18 @@ An audience filter that throws while being evaluated is treated as a mismatch, s

**This changes assignment for running experiments.** In an experiment with Audience enforced (`audienceStrict`) and an `environment` or `application` condition, a unit whose context does not set that attribute itself currently gets variant 0, even when the configured name matches the condition and even when the experiment is full-on. After upgrading, such a unit is randomised normally (or gets the full-on variant) when the configured name matches. Those units are misassigned today; this release fixes them, but their exposures will change. An attribute your context sets itself still overrides the configured name, so its matching does not change. This protection is per attribute: if an audience uses both `application` and `environment` and the context sets only one of them, the configured name for the other can still change the result. An audience or rule on `app_version` no longer matches unless you set `app_version` yourself.

### Switchback experiments are served

**Before:** this SDK ignored the switchback fields the collector sends. A switchback experiment was served as a sticky unit assignment on its `unitType` (or not at all without one), so its exposures did not follow the switchback schedule.

**After:** switchback experiments are served by cluster and period, as described in [Switchback Experiments](#switchback-experiments). **This changes assignment for switchback experiments that are already running**: their units move from the sticky unit assignment to the cluster's schedule, and exposures are recorded once per period (while the period's assignment stays cached) under the serving unit. The switchback support itself does not change unit experiments or context data without switchbacks; see [Shared variable keys](#shared-variable-keys-pick-and-expose-one-experiment) below for the separate variable-read fix.

### Shared variable keys pick and expose one experiment

**Before:** when several experiments defined the same variable key, `variableValue()` exposed every experiment it checked, including ones the user was not in (for example a strict audience mismatch), and when the first experiment's variant lacked the key it served and exposed a later experiment's value instead.

**After:** the first experiment by id that the user is in (assigned, overridden or rule-assigned) wins whatever its variant, as in the Java SDK; its variant's value is returned, or your default if that variant lacks the key. Only that experiment is exposed, unless it is a silent switchback (before its schedule starts, or with an ineligible cluster), which returns control and records nothing (see [Shared variable keys](#shared-variable-keys)). **This changes served values and exposures** for users whose winning experiment's variant lacks the key, and removes exposures that `variableValue()` used to record for experiments the user is not in; call `treatment()` if you need those recorded.

## About A/B Smartly

**A/B Smartly** is the leading provider of state-of-the-art, on-premises, full-stack experimentation platforms for engineering and product teams that want to confidently deploy features as fast as they can develop them. A/B Smartly's real-time analytics helps engineering and product teams ensure that new features will improve the customer experience without breaking or degrading performance and/or business metrics.
Expand Down
Loading
Loading