Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Local evaluation buckets percentage splits with the server key, so results differ from Flagsmith

オープン 初心者向け
#109 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
75/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
ruby
領域
backend

調査の方向性

lib/flagsmith.rb の Client#get_identity_model から始め、特に issue でリンクされている複合キーの構築を確認し、ローカル評価で環境 API キーがどのように利用可能になるかを追ってください。生成されたキーを、再現例で期待される client_key_account_two と比較してください。ローカルでの Percentage Splits 評価に関する対象を絞ったテストを更新して実行してください。SDK がダッシュボードの split 結果と一致すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

In local evaluation mode, the client builds the identity's composite key from the environment_key it was configured with:

https://github.com/Flagsmith/flagsmith-ruby-client/blob/f92f66df821b8a21565a412d5c2331c62e364b24/lib/flagsmith.rb#L343-L345

Local evaluation requires a server-side key, so environment_key is always ser.…. The composite key ends up as ser.<env key>_<identifier>, and that's what PERCENTAGE_SPLIT conditions hash, together with the segment ID.

Flagsmith itself appears to hash splits with the environment's client-side key, the api_key field of the environment document, giving <env key>_<identifier>. The two keys produce different percentages, so the SDK puts a different set of identities in every partial percentage split than the Flagsmith dashboard shows for the same identity and traits.

We found this when an identity that the dashboard showed in a 5% split segment evaluated as outside it in our app. Hashing <env key>_<identifier> gave 1.36 (in the percentage-based segment). Hashing ser.<env key>_<identifier>, what the SDK uses, gave 5.23 (outside the segment).

Reproduction
require "flagsmith"

document = {
  id: 1,
  api_key: "client_key",
  project: {
    id: 1, name: "Project", hide_disabled_flags: false,
    organisation: {id: 1, name: "Org", feature_analytics: false, stop_serving_flags: false, persist_trait_data: true},
    segments: [{
      id: 1, name: "60% rollout",
      rules: [{type: "ALL", rules: [], conditions: [{operator: "PERCENTAGE_SPLIT", value: "60", property_: "$.identity.key"}]}],
      feature_states: [{django_id: 2, featurestate_uuid: "segment-state", enabled: true, feature_state_value: nil,
                        feature: {id: 1, name: "rollout", type: "STANDARD"}, multivariate_feature_state_values: []}]
    }]
  },
  feature_states: [{django_id: 1, featurestate_uuid: "default-state", enabled: false, feature_state_value: nil,
                    feature: {id: 1, name: "rollout", type: "STANDARD"}, multivariate_feature_state_values: []}],
  identity_overrides: []
}

environment = Flagsmith::Engine::Environment.build(document)
handler = Object.new
handler.define_singleton_method(:environment) { environment }

client = Flagsmith::Client.new(
  environment_key: "ser.server_key",
  offline_mode: true,
  offline_handler: handler,
  enable_local_evaluation: true
)

client.get_identity_flags("account_two").is_feature_enabled("rollout")
# => false. Hashing "client_key_account_two" gives 57.05, which is inside the 60% split;
#    the SDK hashes "ser.server_key_account_two", which gives 62.53.
Expected

The SDK should match the dashboard and the other evaluation paths by building the composite key from environment.api_key.

Affected versions

4.1.1 and 4.3.0 (latest on RubyGems). It's also present in v5.0.0 and on main. In v5, Mappers::Identity.build_environment_context sets key: identity.composite_key, so the correct fallback in Segments::Evaluator.get_enriched_context, which builds "#{context[:environment][:key]}_#{identifier}" from the environment's api_key, never runs.

Suggested fix

In Client#get_identity_model, pass environment_api_key: environment.api_key instead of environment_key. We're running that change as a monkeypatch.

主要言語
Ruby
スター
12
フォーク
6
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Flagsmith/flagsmith-ruby-client のほかの issue

Flagsmith/flagsmith-ruby-client の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。