Skip to content

Allow balanced assignment in ConditionAutoTransfer if multiple cohorts match#1014

Merged
rasmi merged 1 commit intoPAIR-code:mainfrom
rasmi:balance-auto-transfer
Feb 17, 2026
Merged

Allow balanced assignment in ConditionAutoTransfer if multiple cohorts match#1014
rasmi merged 1 commit intoPAIR-code:mainfrom
rasmi:balance-auto-transfer

Conversation

@rasmi
Copy link
Copy Markdown
Collaborator

@rasmi rasmi commented Feb 16, 2026

Added enableGroupBalancing option to ConditionAutoTransferConfig in the transfer stage. When enabled, participants matching multiple transfer groups with the same condition are balanced across target cohorts instead of always being assigned to the first matching group.

Motivation

In experiments with multiple cohort variants sharing the same eligibility condition (e.g., two cohorts with the same variable values, except in different order), the default first-match-wins behavior sends all participants to the first group. enableGroupBalancing distributes participants evenly by selecting the group whose target cohort has the fewest participants. This is sort of a hack, but useful nonetheless, as the default behavior may be undesirable in some cases.

Changes

utils/src/stages/transfer_stage.ts

  • Added enableGroupBalancing?: boolean to ConditionAutoTransferConfig interface (defaults to false)
  • Updated createConditionAutoTransferConfig factory to pass through the field

functions/src/participant.utils.ts

  • Modified handleConditionAutoTransfer group selection logic:
    • When enableGroupBalancing is false (default): unchanged first-match-wins behavior
    • When enableGroupBalancing is true: collects all ready groups, fetches target cohort sizes, and picks the group with the fewest participants (first match as tiebreaker)

functions/src/cohort_definitions.integration.test.ts

  • Added two integration tests:
    1. Balanced mode: 4 participants across 2 groups with identical conditions yields 2+2 distribution
    2. Default mode: same setup without flag yields 4+0 (all to first group)

@rasmi rasmi merged commit d870d82 into PAIR-code:main Feb 17, 2026
4 checks passed
@rasmi rasmi deleted the balance-auto-transfer branch February 17, 2026 14:21
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.

2 participants