Skip to content

feat(experiments): give a duplicated experiment consecutive variant keys - #226

Open
kyri-rc wants to merge 5 commits into
mainfrom
kyri/exp-716-duplicate-consecutive-keys
Open

kyri-rc wants to merge 5 commits into
mainfrom
kyri/exp-716-duplicate-consecutive-keys

Conversation

@kyri-rc

@kyri-rc kyri-rc commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Checklist

  • Tests added or updated, if applicable
  • go build ./..., go test ./..., and gofmt pass

Motivation

API v2 GET experiment returns the current iteration's variants. After a new iteration, their keys can come after d (for example a, b, d, e). Creating an experiment still takes only offering_a_id…offering_d_id, so rc experiments duplicate refused these experiments since #218. Part of EXP-716.

Description

  • duplicate sorts the source variants by key (shorter keys first, so aa follows z) and renames them to a, b, c, d before it builds the create body: a copy of a, b, d, e becomes a, b, c, d. Offerings, fallback offerings and placement offerings move with their variant. The dashboard's Duplicate does the same.
  • The copy does not depend on the order the API returns: a source listed as b, a still copies a into the control.
  • It refuses only a source with more than 4 variants, the limit of the create fields. An iteration enrolls at most 4 variants.
  • No API change.

Tests on a test project (built from this branch)

Each copy was read back with rc experiments show --json.

Source keys Copy keys Notes
a, c, d, e with placements a, b, c, d offerings, fallbacks and placement offerings moved with each variant
a, c a, b
a, d, e with audience a, b, c audience kept
a, b, f a, b, c
a, c, d, e (stopped, audience) a, b, c, d
a, b, c, d a, b, c, d no change
a, b with placements a, b no change
a, b, c (running) a, b, c copy is a draft
a, b with empty placement offerings a, b empty slots kept
a, b, c (draft) with placements a, b, c no change
a, b, c and d with deleted offerings a, b same as main
a only none "lacks configuration needed to duplicate it", nothing created

The 5-variant refusal is covered by a unit test only, because no test experiment has 5 variants.

🤖 Generated with Claude Code


Note

Medium Risk
Duplication now reorders and renames variants, which changes which offering lands in each slot if callers assumed literal key preservation—behavior is intentional but affects experiment configuration fidelity.

Overview
rc experiments duplicate no longer fails when the source iteration uses variant keys outside a–d (e.g. e after a new iteration). Before building the create payload, variants are sorted (shorter keys first, then lexicographic) and renamed to consecutive a, b, c, d via new helper withConsecutiveVariantKeys, so offerings, fallbacks, and placement mappings stay attached to the right variant. API response order no longer matters (e, a, b copies as control a plus treatments b and c).

The old hard error for keys after d is replaced by a cap of at most four variants. Tests were updated for remapping (including placements) and for the new “at most 4” rejection path.

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

kyri-rc and others added 3 commits November 27, 2026 14:01
API v2 returns the current iteration's variants, which can have keys after d
(for example a, b, d, e). Creating an experiment takes only the a–d fields, so
duplicate refused these experiments. It now renames the variants in order to
a, b, c, d, as the dashboard does, and refuses only more than 4 variants.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kyri-rc
kyri-rc requested a review from a team as a code owner November 27, 2026 13:09
kyri-rc and others added 2 commits November 27, 2026 14:23
The API returns variants in key order today, but that order is not part of
its contract. Without a sort, a source listed as b, a would copy b's offering
into the control.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.

1 participant