feat(experiments): configurable analysis baseline variant#18
Open
lordspline wants to merge 4 commits into
Open
feat(experiments): configurable analysis baseline variant#18lordspline wants to merge 4 commits into
lordspline wants to merge 4 commits into
Conversation
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Experiment analysis was hard-coded to compare every variant against a variant literally keyed
control(see PostHog#30796). Teams that want to compare against a different arm — or whose baseline should change mid-flight — had no way to do it. This change lets the analysis baseline be any existing variant, selectable at creation and switchable later, while keeping every legacy experiment on its currentcontrol-first behavior.The baseline is persisted as
stats_config.baseline_variant_key. There is no migration and no schema change — it rides the existingstats_configJSON field, and any experiment without the key resolves tocontrolexactly as before.Changes
Backend already read
baseline_variant_keythrough the query runner, validation, and result labels. This PR closes the remaining gaps:resolve_baseline_variant_key()resolves the configured baseline against the variants actually present (configured →control→ first variant) before splitting baseline/test. If the chosen baseline is later removed directly on the flag, analysis degrades instead of erroring. The experiment-update path still validates and rejects dangling baselines on the normal edit flow.control/first), so the baseline can be chosen up front rather than only after creation.resolveBaselineVariantKey()mirrors the backend so the distribution table and settings agree with what the query runner computes.stats_configdiff) and covered by a test.Frontend changes: the baseline switch visibly re-pivots the results scorecard so the selected variant becomes the reference row and the others are compared against it. (Screenshots captured in the authoring session; the distribution-table "Baseline" tag is gated behind the
EXPERIMENTS_EXCLUDED_VARIANTSflag.)How did you test this code?
I'm an agent (Captain Capy). I did not hand-test beyond an automated browser session. Automated checks actually run:
pytest):test_stats_config.pyresolver/split/runner-baseline cases,test_experiment_service.pybaseline validation + cross-state (draft/running/completed) update + duplication-preserves-baseline, and atest_presentation_api.pyactivity-log assertion — all green.jest):resolveBaselineVariantKeyunit cases — green.makemigrations --checkreports no changes (confirming the no-migration design).controltotest-1in settings, and confirmed the metrics scorecard re-pivoted sotest-1became the baseline/reference row.CI runs the full type-check, lint, and remaining suites.
Automatic notifications
Docs update
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Authored by Captain Capy. The approach was scoped deliberately to the backward-compatible "explicit baseline key" design: existing experiments default to
control, customer variant keys are never renamed, and historical results are never silently reinterpreted. Relaxing the mandatorycontrolvariant at flag-creation/MCP level (so a baseline could have a fully arbitrary name with nocontrolpresent) was intentionally deferred as a larger, cross-cutting follow-up — this PR keeps thecontrolconvention for flag creation and only makes the analysis baseline configurable. No serializer/MCP schema change was needed because the key flows through the existing untypedstats_configpassthrough. Reviewers should sanity-check the fallback ordering inresolve_baseline_variant_keyand the wizard placement of the creation-time picker.