Initial example of ConditionAutoTransfer. #907
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.
This PR adds support for routing individual participants to pre-defined cohorts based on conditions. Unlike the existing transfer system (which waits for groups and creates new cohorts), this system can route participants immediately to cohorts defined in the experiment configuration.
Key Features
1. Cohort Definitions
CohortDefinitiontype onExperimentfor pre-defining cohorts with alias, name, and descriptiongeneratedCohortIdstored on definition for O(1) lookup during routing2. Cohort-Specific Static Variables
StaticVariableConfigwithcohortValuesfield for per-cohort variable values3. Condition-Based Routing with Group Composition
TransferGroupnow usescomposition: GroupComposition[]for flexible groupingGroupCompositionspecifies:condition,minCount,maxCounttargetCohortAliastoTransferGroupfor routing to existing cohortstargetCohortAliasis set, participants are routed directly to the specified cohort4. Direct Transfers following existing transfer behavior
handleConditionAutoTransferreturnsDirectTransferInstructionsinstead of executing in-transactionexecuteDirectTransfersexecutes transfers after the main transaction commitscompleteParticipantTransferhelper used by both frontend-initiated and backend-initiated transfersArchitecture
Files Changed
Utils Package
experiment.ts- AddedCohortDefinitiontype andcohortDefinitionsfieldcohort.ts- Addedaliasfield toCohortConfigvariables.ts- AddedcohortValuestoStaticVariableConfigvariables.utils.ts- UpdatedgenerateStaticVariablesto usecohortValuestransfer_stage.ts- AddedGroupCompositioninterface, updatedTransferGroupwithcompositionandtargetCohortAlias*.validation.ts- Added corresponding validation schemasFunctions Package
experiment.utils.ts- Eager cohort creation from definitionscohort.utils.ts- Added helpers for cohort creation and variable transformationvariables.utils.ts- Pass context to static variable generationparticipant.utils.ts- AddedexecuteDirectTransfers,completeParticipantTransfer, updatedhandleConditionAutoTransferparticipant.endpoints.ts- Execute direct transfers after transaction, refactoredacceptParticipantTransferTests
utils/src/variables.utils.test.ts- Added cohortValues tests forgenerateStaticVariablesfunctions/src/cohort.utils.test.ts- Unit tests fortransformCohortValuesKeysfunctions/src/cohort_definitions.integration.test.ts- Integration tests forcreateCohortInternal,findCohortByAlias, andexecuteDirectTransfersExample Usage