Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
64ec12b
feat: serve switchback experiments (R33 cluster-defined), matching ja…
Nov 18, 2026
20215f3
test: port the remaining java-sdk switchback tests; add payload, CHAN…
Nov 18, 2026
dab1afa
perf: take no extra clock reading on unit reads; kill the surviving s…
Nov 18, 2026
0d9e711
test: pin period retention by index and a failed load after a switchb…
Nov 18, 2026
3dd11ba
test: pin the assigner against java-sdk across 4-100 arms and UTF-8 k…
Nov 18, 2026
f683089
test: pin the hasSwitchbacks guard and one clock reading per switchba…
Nov 18, 2026
abb0b7e
test: keep the vendored switchback fixtures byte-identical on Windows…
Nov 18, 2026
cc3023c
fix: match native murmur3 before PHP 8.1, stamp exposures with the cl…
Nov 18, 2026
1ff568d
fix: stamp a switchback exposure with the exposing call's reading, as…
Nov 18, 2026
82fdfcc
fix: serve control for a switchback whose malformed name has no index…
Nov 18, 2026
72a68a0
test: keep the non-string-name test green when deprecations are reported
Nov 18, 2026
3412770
fix: hash a switchback's serving-unit draws with the platform murmur3…
Nov 18, 2026
3bdbdd0
fix: expose an assigned switchback the variable key reaches even if i…
Nov 18, 2026
bd112e6
test: pin assignUnit's tie at a cumulative bound
Nov 18, 2026
8b84cd6
test: trim comments that restated the assertions; drop a redundant nu…
Nov 18, 2026
798e225
fix: reject a nonnumeric switchback traffic weight as VariantAssigner…
Nov 18, 2026
522d377
test: pin null and boolean switchback traffic weights as rejected
Nov 18, 2026
f7e725d
docs: trim the four restating comments flagged in review round 4
Nov 18, 2026
20ea5e2
test: pin switchback revalidation, peek rule wins and source reuse
Nov 18, 2026
1fbd555
test: make the switchback-source reuse test catch an unstored rebuild
Nov 18, 2026
f12bdd6
docs: state the same-period cluster attribute rule as a caller constr…
Nov 20, 2026
90183a1
test: pin that a re-queue after a same-period cluster change keeps th…
Nov 20, 2026
431946c
fix: publish a switchback exposure with the units it was served with
Nov 20, 2026
635e915
fix: keep an absent switchback slot on the main batch; pin the early-…
Nov 20, 2026
708ab04
fix: guard in-flight flushes against re-entrant publish callbacks
Nov 20, 2026
87d7d9c
fix: plan early switchback batches per send instead of guarding re-entry
Nov 20, 2026
88ccafe
test: pin identity removal, the absent check and the reindex of early…
Nov 20, 2026
e7196cf
fix: stop the early-batch loop if a planned batch collects nothing
Nov 20, 2026
64a25c6
test: pin that an absent slot queued first does not hide a later earl…
Nov 20, 2026
108f3ae
perf: keep no-switchback cached reads at base cost
Nov 20, 2026
f676752
test: pin split-rule revalidation on a switchback's serving unit
Nov 20, 2026
8b8fa12
fix: keep a switchback slot's units from before cluster resolution; n…
Nov 21, 2026
ccca763
Merge origin/feat/holdouts into feat/switchbacks
Nov 21, 2026
4eb4a06
fix: the retained-event cap never drops an early switchback batch in …
Nov 21, 2026
dd7a586
test: pin the retained-event cap's reindex; correct the no-holdout CH…
Nov 21, 2026
a5eadcf
docs: state the measured cached-read cost of switchback support
Nov 21, 2026
f3f0a87
Merge origin/feat/holdouts into feat/switchbacks
Nov 21, 2026
aa56b4f
fix: keep nested close, the retry cap, closed reads and refreshed slo…
Nov 21, 2026
ad1837a
fix: keep a slot across an unchanged refresh during resolution; finis…
Nov 21, 2026
94a2c12
test: pin that a finished deferred close is not logged again by a lat…
Nov 21, 2026
9bc9a0f
Merge origin/feat/holdouts into feat/switchbacks
Nov 21, 2026
4f38f51
test: pin the removed-candidate skip after a hand-off to the switchba…
Nov 21, 2026
2d31844
fix: give switchback publishing one close-completion owner and preser…
Nov 21, 2026
5a5c821
test: pin historical switchback units at the HTTP boundary
Nov 21, 2026
92608a3
fix: bound a switchback publish to one extra pass; keep a failed clos…
Nov 21, 2026
d166b18
Merge remote-tracking branch 'origin/feat/holdouts' into feat/switchb…
Nov 22, 2026
a671eb4
test: pin the stripped-key skip on switchback data; note that close()…
Nov 22, 2026
f7cdf60
Merge origin/main and preserve PHP 1.2.0 contracts for switchbacks 1.3.0
Nov 27, 2026
a96772f
test: pin published PHP 1.2.0 consumer models and signatures
Nov 27, 2026
d976285
fix: bound callback batches and preserve switchback validation snapshots
Nov 27, 2026
fc17a82
fix: carry variable-walk state into the first-switchback hand-off
Nov 27, 2026
74e25b8
fix: hand off at the top of the walk and report publish failures via …
Nov 27, 2026
41e33c1
test: pin original-walk slicing and logger-only switchback failures
Nov 27, 2026
3e24ab8
perf: avoid a variable walk when an ordinary key has one candidate
Nov 27, 2026
8ad3d79
fix: defer nested early batches to the bounded outer publisher
Nov 27, 2026
f0fa146
perf: bypass ordinary shared-key walks when the first candidate wins
Nov 27, 2026
22a767b
fix: return defaults for out-of-range ordinary variable assignments
Nov 27, 2026
c0e61c5
test: pin switchback publish recovery after a throwing Error logger
Nov 28, 2026
a6f556b
test: cover a PHP Error thrown by the Error logger during switchback …
Nov 28, 2026
a918612
test: pin that a failed main batch keeps the next publish's extra pass
Nov 28, 2026
7be9512
fix: address the CodeRabbit review of the switchback paths
Nov 28, 2026
529a821
fix: complete a nested close when the handler refreshes in the first …
Nov 28, 2026
7ed7ac0
fix: retry a failed first-switchback send on the next publish, not at…
Nov 28, 2026
037e6c3
test: pin the stale switchbackPublishFailed reset; correct the 1.3.0 …
Nov 28, 2026
79c46be
fix: validate a nested switchback slot against the outer read's rule …
Nov 28, 2026
f55ef38
fix: let the outer switchback read take a nested slot built after a r…
Nov 28, 2026
a9de1fd
test: pin the nested-slot fallback and the new-generation exposures
Nov 28, 2026
8cf92c7
test: assert nested serializer reads after the outer read
Nov 28, 2026
474b8f6
test: make the new-generation test catch an overwrite of the refreshe…
Nov 28, 2026
25155d9
test: trim the new switchback test comments
Nov 28, 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
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/docs export-ignore

# Vendored platform fixtures are compared byte for byte (git blob and sha256): never convert line endings.
/tests/Fixtures/switchback/*.json -text
/tests/Fixtures/switchback-java/*.json -text
/vendor export-ignore
/composer.lock export-ignore
/build export-ignore
Expand Down
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
# Changelog

## 1.3.0

### Added

- **Switchback experiments** (R33, cluster-defined), as in released Java 1.10.0 and JavaScript 1.14.1. An
experiment with `randomizationType: "switchback"` is randomized over clusters and time: `Experiment` gains
`$randomizationType`, `$switchbackClusters` (unit type => attribute path, in the served order, which is kept), `$switchbackClusterValues`, `$switchbackStartAt`, `$switchbackPeriodMs`,
`$switchbackCarryoverDurationMs`, `$switchbackBurnInDurationMs`, `$switchbackBurnOutDurationMs`,
`$switchbackDesignType` and `$switchbackEstimand`, all optional. The first context unit, in the
declared order, whose attribute path gives a value serves the experiment, and that raw value (a non-empty string
as-is, an integer as its decimal text; floats such as `3.0`, booleans, objects, arrays, `""` and null give none) is
the cluster key of the platform's balanced-block draw for the period `floor((now - switchbackStartAt) /
switchbackPeriodMs)`. Units that disagree, a value outside `switchbackClusterValues` or a missing value give a
control that records no exposure; a pre-anchor read or an unservable schedule replaces only the period draw, after
overrides, rules, strict audiences and full-on, so otherwise also a silent control. Overrides, assignment rules, strict
audiences, full-on, traffic and custom assignments apply as for a unit experiment, with the serving unit's traffic
and split-rule draws hashed with the platform murmur3 on every runtime. Holdouts never apply to a switchback. The
serving unit and cluster key are read once per period, and each period exposes once, stamped with the clock reading
of the exposing call. `getVariableValue()` exposes the winning switchback when it is assigned, overridden or
rule-assigned, even when its arm lacks the key; a strict mismatch records nothing.
Callers must set cluster attributes before a period's first read and keep them unchanged through its exposure and
any re-queue: a change within a period is not supported, the cached variant is kept and the change takes effect
from the next period (the same constraint as every SDK's switchbacks). A switchback exposure queued before a unit
was added is published first, in its own batch with the units it was served with, since the collector resolves the
serving unit again from a publish's units; that `publish()` calls the event handler once per batch. Exposures and
the publish payload carry no new fields. Payloads without switchbacks keep the 1.2.0 read paths;
cached `getTreatment()`, `getVariableValue()` and `peekVariableValue()` measured within about 2% of 1.2.0 with
opcache in synthetic warmed benchmarks. See the README's *Switchback Experiments*.
Set cluster attributes as strings or integers: a float attribute is published as JSON (`3.0` as `3`), so the
collector, which resolves the cluster again from the published attributes, could key it where the SDK did not.

### Changed

- `X-Agent` changes from `absmartly-php-sdk/1.2.0` to `absmartly-php-sdk/1.3.0` for all callers, including
non-switchback contexts. Update exact-version agent filters in exports or dashboards if used.
- **Switchback experiments are served as switchbacks.** PHP 1.2.0 served `randomizationType: "switchback"`
as sticky unit experiments. PHP 1.3.0 assigns them by cluster and period, so running switchbacks can change
treatment and publish one exposure per period under the serving unit. Upgrade every SDK serving a switchback.
- With switchback data installed, publishing drains the current queue plus at most one pass of callback work.
A nested `close()` requests completion from the outer publish, including when the first switchback arrives
during that send (an outer `close()` then also finishes through the switchback publisher); callback work left
after the final pass remains queued and the context stays open. Check `isClosed()` and retry `close()` to finish. A failed top-level
`close()` followed by `publish()` does not close the context, as for unit data.
- Non-switchback PHP 1.2.0 runtime, public model API and serialization are retained, including holdouts,
assignment rules, shared variable lookup, and PHP 7.4 support.

## 1.2.0

### Added
Expand Down
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,62 @@ $contextData = new ContextData($payload->experiments, $payload->holdouts ?? []);
$context = $sdk->createContextWithData($contextConfig, $contextData);
```

### Switchback Experiments

A switchback experiment is randomized over clusters (for example, a store's region) and time: every unit in the same
cluster sees the same variant within a period, and the variant changes on a fixed time grid. Switchbacks arrive with
the context data (`randomizationType: "switchback"`); nothing needs configuring in the SDK except the units and the
attributes that hold the cluster values.

```php
$contextConfig = new ContextConfig();
$contextConfig->setUnit('store_id', 'store-42');
$context = $sdk->createContext($contextConfig);

// The experiment links store_id to the attribute path "geo/region".
$context->setAttributeValue('geo', ['region' => 'lisbon']);

$treatment = $context->getTreatment('exp_delivery_fee'); // this period's variant for the "lisbon" cluster
```

- `switchbackClusters` lists the linked unit types and, for each, the attribute path of its cluster value, in the
served order: the first unit in that order with a value serves the experiment. Paths use `/` (`geo/region`,
`items/0/city`); a quoted segment (`'a/b'`) is a literal key, and a path with a `.` is unreadable.
- A cluster value is a non-empty string, used as-is, or an integer, used as its decimal text. Floats (including
`3.0`), booleans, arrays, objects, `""` and null give no value. Set cluster attributes as strings or integers: a
float is published as JSON (`3.0` as `3`), which the collector, resolving the cluster from the published
attributes, could read as a value.
- With no value, units that disagree, or a value outside `switchbackClusterValues`, the unit gets control (variant 0)
and no exposure is sent. Before `switchbackStartAt`, or with an unservable schedule, only the period draw is
unavailable: an override, matching rule, strict audience mismatch or full-on still applies first; otherwise the unit
gets control with no exposure. Without a unit of a linked type, the experiment does not apply.
- Overrides, assignment rules, strict audiences, full-on, traffic and custom assignments apply as for a unit
experiment, and the exposure carries the same flags. Holdouts never apply to a switchback.
- `getTreatment()` sends one exposure per period, stamped with the time that chose the period. The serving unit and
cluster key are read once per period, so a `setAttribute()` later in the period takes effect from the next period.
`peekTreatment()` and `peekVariableValue()` send nothing.
- **Caller constraint:** set a context's cluster attributes before a period's first read (a peek, or any call) and
keep them unchanged through that period's exposure and any re-queue. Changing a cluster attribute within a period is
not supported: the SDK keeps the variant it cached at the first read, and the change takes effect from the next
period. This applies to every SDK's switchbacks (java-sdk included), since the collector resolves the cluster from
the published attributes at the exposure's time.
- `getVariableValue()` exposes the winning switchback when it is assigned, overridden or rule-assigned, even if
its arm lacks the key; a strict audience mismatch it passes over records nothing. Unit experiments retain the
PHP 1.2.0 shared-variable winner and holdout behavior described above.
- Attributes are published with their timestamps, as before: the collector resolves the cluster again from them.
- The collector also resolves the serving unit again from the published units. A switchback exposure queued before a
unit was added with `setUnit()` is published first, in its own batch with the units it was served with, so the new
unit cannot drop it or move it to another unit; the other events follow with the current units. That `publish()`
then calls the event handler, and logs `Publish`, once per batch. A `publish()` from inside the handler while such a
batch is being sent leaves that batch's exposures to it, so they are never sent twice. A `close()` from inside the
handler then requests closure but leaves the context open, since the batch being sent may still fail. The active
publisher drains accepted work, including work queued by callbacks during the last send, before closing; this also
holds when a unit-data send's callback refreshes in the context's first switchback. Work a
callback queues during that extra pass stays queued for the next `publish()` or `close()`, so a callback that queues
on every send cannot keep a publish running; a `close()` that leaves work queued returns with the context open. After
a failure, the next `publish()` or `close()` retries the drain. `Close` runs with the context sealed: it cannot queue
more work, and a throwing Close logger leaves the request retryable without resending accepted batches.

### Semantic Version Conditions

Audience and rule conditions can compare versions with `semver_eq`, `semver_gt`, `semver_gte`, `semver_lt` and
Expand Down
4 changes: 2 additions & 2 deletions src/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class Client implements AsyncClientInterface {
/** The SDK version, sent in the X-Agent header. Keep in step with the release tag (checked by the release workflow). */
public const SDK_VERSION = '1.2.0';
public const SDK_VERSION = '1.3.0';
public const SDK_NAME = 'absmartly-php-sdk';
/** @deprecated Use SDK_VERSION. */
protected const VERSION = self::SDK_VERSION;
Expand Down Expand Up @@ -73,7 +73,7 @@ private static function applicationVersionHeader(?string $applicationVersion): s
return $applicationVersion;
}

/** The value sent as the X-Agent header, "<name>/<version>", e.g. "absmartly-php-sdk/1.2.0". */
/** The value sent as the X-Agent header, "<name>/<version>", e.g. "absmartly-php-sdk/1.3.0". */
public function getAgent(): string {
return $this->headers['X-Agent'];
}
Expand Down
Loading
Loading