Skip to content

feat(blocks): split one arm of an A/B test with a nested test (parent/child) - #837

Merged
thaisrocine merged 3 commits into
mainfrom
thaisrocine/multi-test-ab-plp
Nov 18, 2026
Merged

thaisrocine merged 3 commits into
mainfrom
thaisrocine/multi-test-ab-plp

Conversation

@thaisrocine

@thaisrocine thaisrocine commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Why

The plp-optimizer A/B test has to split our arm, not the traffic in thirds: 50% control (the store's PLP), and our 50% split into 25% internal test A and 25% internal test B. The analytics has to say both things cleanly: us against the control, and A against B.

v8's tests have two arms each, and a multi-way test is several tests. Two independent tests (plp-optimizer: 50, plp-optimizer-b: 50) give the right shares, but plp-optimizer-b is also on for a quarter of the control, who never see B. Anyone reading it without the right filter mixes control visitors into the A/B comparison, with no error anywhere.

What changes

  • A test within a test. A name written <parent>/<child>, where <parent> is a test of the same experiments block, is drawn only among <parent>'s visitors and is off outside it:
    { "__resolveType": "split-traffic", "plp-optimizer": 50, "plp-optimizer/b": 50 }
    • The child keeps its own roll (plp-optimizer/b:id), so ramping the parent to 80 gives 20/40/40 and keeps everyone already in A or B where they were.
    • The parent is the nearest /-prefix that is a test of the block (a/b/c falls back to a without a/b). A / in a name whose prefix is no test changes nothing, so existing names behave as before.
    • Given or not: a child switched on in a preview, or forged in an assignments map, stays off while its parent is off. A preview shows B with both switched on, A with the parent alone.
  • Where the rule lives: src/v8/nested.ts (internal), applied by assign (so the browser gives the same answer as the server), the built-in split-traffic (after the client's overrides) and the analytics client.
  • Analytics: startAnalytics({ experiments }) sends a child only while its parent is on. A control visitor's events carry { "plp-optimizer": "off" }; ours carry plp-optimizer and plp-optimizer/b. So plp-optimizer compares us with the control, and plp-optimizer/b compares B with A with no filter. Only client.ts changes, not runtime/ or shared/: the standalone tag's bundles are untouched, and no decocms/analytics PR is needed.
  • Nothing else moves: the content type is still Record<string, number>, so the Studio form, deco check, the x-deco-assignments header, assignmentsKey and the __test preview link carry the child as one more test.
  • Studio: the split-traffic description mentions parent/child; the examples' schema.gen.json are regenerated (one line each).
  • Docs in the repo: deco-variants (a "test within a test" section with the PLP slot's nested multivariate, and "Reading the results" updated for startAnalytics) and CLAUDE.md.

Tests

  • experiments.test.ts: over 100,000 ids, the split is 50/25/25; nobody outside the parent has the child; inside it, the child is its own roll; ramping the parent keeps A and B even and moves nobody between arms; nesting at any depth, to the nearest prefix that is a test; a / without a parent test changes nothing.
  • __conformance__/experiments.test.ts:
    • exp-14: one slot serves control, A and B, and what it shows always matches the map;
    • exp-15: a child given on stays off while its parent is off, given, decided or forged;
    • exp-16: a preview with both switched on shows B, the parent alone shows A.
  • analytics/client.test.ts: the exp of each of the three arms.

bun run check passes, and bun run test passes (3400 tests). The Biome warnings left are on main too.

Before merging

  • Docs site: the /next/* page on split-traffic needs the same rule, since exp-14 to exp-16 encode it. It also needs the PO's ok, since it extends "two arms per test".
  • Not here: a true N-arm test ("plp-optimizer": { "control": 50, "a": 25, "b": 25 } with one label per arm in exp). That would touch the assignments type, the header, the cache key, the bindings' parsing, the preview, the Studio form and deco check. More internal arms are possible here by chaining (plp-optimizer/b: 66, plp-optimizer/b/c: 50), not with siblings, which overlap.

🤖 Generated with Claude Code


Summary by cubic

Adds nested A/B tests: a test named <parent>/<child> is drawn only among <parent>'s visitors, so one test can split its own arm. { "plp-optimizer": 50, "plp-optimizer/b": 50 } gives 50% control, 25% A, 25% B; two independent tests previously put plp-optimizer-b on a quarter of the control too, mixing control visitors into the A/B comparison.

  • The child keeps its own roll, so ramping the parent to 80 gives 20/40/40 and keeps everyone already in A or B where they were; a preview switching on the parent alone shows the visitor's own arm of the child.
  • A child switched on in a preview, or forged in an assignments map, stays off while its parent is off. The parent is the nearest /-prefix that is a test of the same block; a / in a name whose prefix is no test changes nothing.
  • deco check warns on each name it reads as nested, so a name saved earlier with a / doesn't change meaning silently.
  • The rule lives in src/v8/nested.ts, applied by assign, the built-in split-traffic, and the analytics client, which sends a child only while its parent is on so plp-optimizer compares us with the control and plp-optimizer/b compares B with A without filtering.
  • The content type, header, cache key, and Studio form are unchanged; docs and generated schemas are updated, and conformance tests exp-14 to exp-19 cover the new behavior, including that __test preview links keep the child name's / on drafts and releases.

Written for commit 4362604. Summary will update on new commits.

View guided diff Turn on auto-fix

…/child)

A test named `<parent>/<child>`, where `<parent>` is a test of the same
`experiments` block, is drawn only among `<parent>`'s visitors and is off
outside it, given or not. `{ "plp-optimizer": 50, "plp-optimizer/b": 50 }`
is 50% control, 25% A, 25% B, and ramping the parent keeps its arm split.

`assign`, the built-in `split-traffic` and the analytics client apply the
rule (src/v8/nested.ts); the analytics client sends a child only while its
parent is on, so `plp-optimizer/b` compares B with A with no filter.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@thaisrocine
thaisrocine requested a review from a team November 18, 2026 12:50
tlgimenes
tlgimenes previously approved these changes Nov 18, 2026

@tlgimenes tlgimenes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the nested-test rule (nested.ts, assign, split-traffic, analytics armsOf): the 50/25/25 split and the ramp behavior hold, and CI is green. Two things to confirm before merge: existing test names containing / whose prefix becomes a test, and that / survives in the __test and __at preview params.

@thaisrocine

Copy link
Copy Markdown
Contributor Author

Verdict: BLOCK: this changes the meaning of content sites have already saved and gives no signal when it does. The PR's own merge gate (docs page and PO ok) is still open. (round 1)

Blocking

  • packages/blocks/src/v8/nested.ts:45-63, applied in experiments.ts:181 and builtins/experiments.ts:46. A running test gets reallocated with no content change and no warning. Until this release, split-traffic names were independent tests: the docs said so, deco check was silent about names like these, and references/experiments-and-campaigns.md:31 still says "two tests are independent of each other". Trigger: a site has { "checkout": 50, "checkout/v2": 50 } saved today and upgrades @decocms/blocks. checkout/v2 drops from 50% to 25% of traffic. Every visitor who was in checkout/v2 but not in checkout flips to off in the middle of the test. startAnalytics stops sending checkout/v2 in exp for those visitors, so the test's results are split across two populations. CLAUDE.md treats moving visitors who are already allocated as never acceptable ("Changing the hash ... moves every visitor already allocated"). This is that, done by a naming convention. The repo's own examples are safe (new-banner/next-season, promo-copy), but a site's content is out of reach from here. Fix here: make the reinterpretation visible before it reaches traffic. deco check should warn on every name it now reads as nested ("checkout/v2 is drawn within checkout since 8.x"), with a test. The release notes should name the change. Alternatively, use a marker that no saved name can already contain. Also correct line 31 of the skill reference, which this PR leaves contradicting the new section below it. → fix here
  • The house rule and the PR's own "Before merging" list. CLAUDE.md says "the spec is the docs site's /next/* pages; when the code and the docs disagree, the docs win" and "Conformance tests encode the docs' claims". exp-14 to exp-16 encode claims the /next/* page does not make yet, and the PR says the change "needs the PO's ok, since it extends two arms per test". Until both exist, this merges code that disagrees with the spec. → fix here (land the docs change and record the PO ok, then this item clears)

Worth fixing

  • builtins/experiments.ts:39-46. A given parent loses its child's roll when a visitor is present. assign nests using the raw rolls first, so a child whose parent rolled out is already false before the overrides are applied. Turning the parent on afterwards cannot bring the child back. The real preview path does pass a visitor: tanstack/src/worker/index.ts:411 calls readAssignments(cms, { visitor, ...draft.version }), and Next's decideAssignments does the same. With { plp: 50, "plp/b": 50 } live and __test=plp=on, take visitor X (rolled out of plp, into plp/b) and visitor Y (rolled into both). X sees A and Y sees B. The child is not "its own roll", and the PR's "the parent alone shows A" also fails for Y. exp-16 only covers a client with no visitor and 0%. Pick one meaning: either nest once after the overrides, from un-nested rolls, or treat a child as off whenever its parent was given but the child was not. Then add a conformance case that has a visitor. → file an issue (preview-only; the dark-test preview, which is the main use, behaves as documented)
  • analytics/client.ts:111-115. The branch where the tag booted first (setExperiment for each arm) has no nested-test case. client.test.ts only exercises the core-boot path. One it with __dqBooted set would fix that. → file an issue
  • tanstack/src/worker/assignments.ts:101-110 (liveAssignmentKeys). It still enumerates all 2^n subsets, including the ones nesting now makes impossible (child on, parent off). These are harmless extra purge keys today. If purge cost ever matters, prune them with parentTest. → file an issue
  • CI runs only tests/release.test.ts, never the vitest suite. I ran the affected files locally (experiments, conformance experiments, analytics client, builtins, site-cache, nextjs, tanstack): 37 files, 512 tests, all pass. This gap predates this PR. → file an issue

Checked, fine

  • nestTests ordering: sorting by code unit puts a parent before its children. Names like /lead, a//b and a/ are handled, and prototype names are safe through Object.hasOwn.
  • Next's 0%-stays-off path (withoutDarkTests, then assignedClient): the forged path x=plp/b with plp at 0% renders control.
  • Slashes survive every encoding: the x-deco-assignments header (encodeURIComponent), the Next assignments segment (base64url) and __test (decodeSwitch splits on the last =).
  • The worker and contentClient pass the full nested map back in as overrides. Running nestTests again on it changes nothing.
  • client.ts importing ../nested.ts adds nothing under analytics/runtime/ or shared/, so the standalone tag bundles are unchanged.

…ep its child's roll

- `deco check` warns on every test of `experiments` it reads as within
  another, so a name saved earlier with a `/` doesn't change meaning
  silently.
- `split-traffic` applies the client's overrides over each test's own roll
  before nesting: a preview switching on the parent alone shows the
  visitor's own arm of the child, wherever they rolled for the parent.
- Tests: the warning, exp-17 (a visitor's own arm under a previewed
  parent), the tag-booted-first path dropping a child of an off parent.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
tlgimenes
tlgimenes previously approved these changes Nov 18, 2026
@thaisrocine

Copy link
Copy Markdown
Contributor Author

Verdict: LGTM: no code finding still needs fixing here. The docs page and the PO's ok are a merge gate, already listed in the PR body, and the human who merges owns them. (round 2)

Previously raised

  • Saved names with a / change meaning silently. Fixed. cli/check/index.ts:1057-1072 warns on each test it reads as nested. The warning names the parent and says to rename the test if the two are separate. parentTest uses the same lookup the runtime uses, so the warning and the runtime always agree on what is nested. check.test.ts covers the nearest parent (checkout/v2/copy within checkout/v2), and checks that home/hero with no home test gets no warning. The skill's line 31 was corrected, and a bullet on names already saved with a / was added. Semantic-release builds the release notes from the feat commit's body, so no separate note file is needed.
  • Docs-site page and PO ok. Downgraded from blocking to a merge gate. Nothing in this diff can change either one: the docs site lives in another repo, and the PO's ok is a human decision. Both are listed in the PR body's "Before merging" section, with exp-14 to exp-17 named. CLAUDE.md treats the docs as the spec, so do not merge until the PO has approved and the /next/* page says the same thing. This is not a code finding, and the review loop doesn't need to stay open for it.
  • A previewed parent lost its child's roll. Fixed. I re-read the fix cold. splitTraffic now calls assign once per test, so each single-entry map is that test's own roll. It then applies the overrides and runs nestTests once at the end. With no overrides the result equals assign(allocations, visitor), so the browser and server still agree. Names that assign drops (non-finite values) stay out because of the hasOwn guard. The worker's map is forwarded to the page as the full set of overrides, and running the nesting on it again changes nothing. exp-17 uses real visitors with the parent at 0% and asserts the child's own roll, both A and B seen. The no-visitor case still shows A.
  • No test for the tag-booted-first path. Fixed: client.test.ts now asserts that setExperiment gets plp alone when the parent is off.
  • liveAssignmentKeys lists impossible subsets. Deferred, and it doesn't hold the PR.
  • CI doesn't run the test suite. This predates the PR and doesn't hold it. I ran the affected test files at db527570: check, experiments, conformance experiments and client, analytics client, builtins, site-cache, nextjs and tanstack. 39 files, 628 tests, all pass.

Worth fixing

  • Studio shows a child's percentage as if it were of all visitors. This is in decocms/studio, apps/web/src/layouts/main-panel-tabs/experiments-block-tab.tsx:370-373. Each row is labelled "{share}% of visitors" (i18n/en/sections-editor.ts:86) and drawn with a SplitDonut of that share. With { "plp-optimizer": 50, "plp-optimizer/b": 50 }, the plp-optimizer/b row reads "50% of visitors" when it is 25%. Someone ramping the test from that tab is misled about the traffic it receives. The author hasn't tried a / name in a running Studio, so whether Studio can create or edit one at all is also unverified. → file an issue (decocms/studio): label a nested row as a share of its parent, and try a / name end to end before the first site uses one.
  • deco check only warns on the saved experiments block. Code: cli/check/index.ts:1057. An inline { "__resolveType": "split-traffic", "a": 50, "a/b": 50 } elsewhere (for example in a section prop) nests at runtime but gets no warning. Inline split-traffic is rare, and the experiment rule reads only the saved block. → file an issue

Checked, fine

The per-test assign loop handles __proto__ safely (a computed key becomes an own property) and gives the same result whatever the iteration order, because nestTests sorts the names itself. The check warning is gated on the canonical type and skips __resolveType. exp-16 was renamed so its "parent on, child off" case is distinct from exp-17's "parent alone" case.

…h __at)

exp-18: parseVersion keeps `plp-optimizer/b` in `__test`, percent-encoded
or not, next to `__at`, on a draft pointer and on a release id. exp-19: the
same link inside a page URL's `__draft` reads the same and its client shows
both tests on.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@thaisrocine

Copy link
Copy Markdown
Contributor Author

Valeu, @tlgimenes! Os dois pontos:

1. Nomes com / cujo prefixo vira um teste

  • deco check agora avisa em cada teste do bloco experiments que ele lê como aninhado: diz quem é o pai e sugere renomear se forem testes separados. Ele encontra o pai do mesmo jeito que o runtime (parentTest em nested.ts), então o aviso e o comportamento real não divergem.
  • Um / cujo prefixo não é um teste continua como antes. Por exemplo, home/hero sem um teste home é um teste comum. Há teste cobrindo isso no experiments.test.ts.
  • Os exemplos do repo não têm nenhum caso assim. O conteúdo dos sites não dá para varrer daqui: o aviso do deco check é o que pega um caso real antes da release chegar ao site.

2. O / no __test e no __at
O __at é só a data (ISO com offset), sem nome de teste. O que precisa preservar o / é o __test. Fixei isso em dois testes novos de conformidade (4362604):

  • exp-18: parseVersion mantém plp-optimizer/b no __test, codificado (%2F) ou cru, junto com o __at. Vale para um draft (…drafts/x.json?v=2&__at=…&__test=…@v1) e para uma release antiga (<id>?__at=…&__test=…).
  • exp-19: o mesmo link dentro do __draft da URL da página é lido igual pelo readVersion, e o client resultante liga os dois testes.

O / também passa pelo header x-deco-assignments e pelo segmento de assignments do Next.js; o revisor conferiu isso na rodada 2.

Para o merge continuam faltando a página /next/* do split-traffic e o ok do PO.

@thaisrocine
thaisrocine merged commit 2fe118e into main Nov 18, 2026
5 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 8.22.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants