Skip to content

feat(analytics): hierarchical groups support - #106

Open
tylerjroach wants to merge 33 commits into
masterfrom
hierarchical-groups
Open

tylerjroach wants to merge 33 commits into
masterfrom
hierarchical-groups

Conversation

@tylerjroach

@tylerjroach tylerjroach commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Adds hierarchical groups (HG) support: a MixpanelIdentity carrying user and company ids, HG-aware profile updates, and company-bound group writes. HG behavior is gated on the SDK's hierarchical groups init flag; projects without it behave as before.

Draft, opened for an early automated review. Not ready to merge.

Source compatibility

MessageBuilder gains MixpanelIdentity overloads of event, importEvent, set, setOnce, delete, remove, union and unset. A call that passes a literal null id, such as event(null, "Server Started", props), no longer compiles, because null matches both the String and MixpanelIdentity overloads. Cast the literal to fix it: event((String) null, …).

Only a literal null in source is affected. A String variable that holds null still compiles and behaves as before, and already-compiled code is unaffected. We judged this an edge case and kept the identity overloads under the same names as the other SDKs.

Commits

  • feat(analytics): hierarchical groups support
  • feat(flags): resolve local assignment keys from context_value_template
  • feat(analytics): throw for unsupported groupMessage operations on hierarchical groups builders
  • feat(analytics): add company* profile methods to forCompany builders
  • chore(analytics): point the company-only identity error at the company profile API
  • revert(analytics): drop the company profile methods from for_company clients
  • feat(analytics): infer the company for $company_id group profile updates
  • feat(analytics): restore the company profile on for_company clients
  • feat(analytics): refuse a user from another company on a forCompany builder
  • feat(analytics): send a user without a company as given on hierarchical groups
  • fix(analytics): keep a user-only profile update within the bound company

🤖 Generated with Claude Code

tylerjroach and others added 10 commits November 2, 2026 09:58
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rarchical groups builders

$add, $append and $merge were logged and still built. They now throw
UnsupportedOperationException, like the people operations.

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

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

The company profile is updated through the existing group methods instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings back the company profile methods in place of inferring the company from $company_id
group writes.

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

A people message from a MessageBuilder bound with forCompany used the
identity's company and ignored the bound one, so a mismatched identity
silently built an update of the other company's user. It now throws
IllegalArgumentException.

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

An identity with a user id but no company or device id threw on every
call. It is valid to send, like a plain distinct id, so events now send
it as given. User profile updates still need the company and fail with
the existing company-required error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · No outstanding findings block merging the reviewed changes.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] No outstanding findings block merging the reviewed changes.

Reviews (19) · Last reviewed commit: "refactor: remove device_id from Mixpanel..." · Reviewed by Greptile

tylerjroach and others added 3 commits November 4, 2026 13:15
On a forCompany builder, a user profile update for a user-only identity
ignored the bound company: a $company_id modifier chose which company's
user profile was written, and without one it threw the company-required
error. The identity's company, then the bound company, now decides, and
either wins over a $company_id modifier. Without both, the modifier still
supplies the company. An empty or JSONObject.NULL $company_id modifier no
longer counts as a company.

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

A distinct_id, $user_id, $company_id or $device_id in the passed properties
no longer survives when the identity leaves that field unset, so an event
never carries a stale id alongside the identity's own.

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

The exposure check had started treating an empty distinct_id as missing on
every project, so a non-hierarchical-groups exposure with distinct_id ""
was dropped. Only a hierarchical groups provider now treats an empty value
as missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tylerjroach tylerjroach changed the title Hierarchical groups support feat(analytics): hierarchical groups support Nov 4, 2026
tylerjroach and others added 3 commits November 4, 2026 16:20
Exclude "{" from the placeholder capture so a template full of "{" can't
make matching slow (CodeQL polynomial regular expression).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and let identity win in FlagContext

- MixpanelIdentity.applyTo writes only the keys the identity sets; keys it
  leaves unset keep the caller's values.
- On hierarchical groups, people and group profile messages refuse any
  $-prefixed modifier key outside $set, $set_once, $unset, $union, $remove and
  $delete (non-operation keys such as $time and $company_id are allowed) with
  UnsupportedOperationException. Without hierarchical groups, modifiers are
  copied as before.
- FlagContext applies identity keys last, so identity() and the explicit id
  setters win over group() and customProperty() whatever the call order; among
  them the later call wins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tylerjroach and others added 7 commits November 9, 2026 12:46
…ity leaves unset

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

For a /groups update with $group_key "$company_id", the Mixpanel service
writes to the profile named by the top-level $company_id, not $group_id.
A forCompany("acme") builder sending groupSet("$company_id", "globex", ...)
would silently update acme's profile. On hierarchical groups builders,
buildGroupMessage now throws IllegalArgumentException when the group id
differs from the resolved company (bound company, else $company_id
modifier), compared as strings. HG off is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Item 4: a $company_id modifier on HG group/profile updates must be a
  string or an integer; an empty string still means no company, a numeric
  one is written as a string like a bound company.
- Item 6: on HG, event/importEvent/profile updates with a combined
  $company:<c>|$user:<u> distinct id refuse a $company_id or $user_id that
  names a different company or user. MixpanelIdentity calls are unchanged.
- Item 8: whitespace-only user/company ids are refused by the
  MixpanelIdentity builder, forCompany, combined distinct id parsing (HG)
  and a $company_id modifier (HG).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BaseFlagsProvider is a public abstract class, so restore master's
protected trackExposure(String distinctId, ...) alongside the new
context-based overload. Without hierarchical groups the context overload
routes through the String method, so subclass overrides still run and
the exposure payload matches master. Document that EventSender's
distinctId can be null on a hierarchical groups provider.

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

A $company:{company}|$user:{user} distinct id whose company or user is empty
was treated as not combined and sent as given, creating a junk user. On a
hierarchical groups builder, events (string and identity distinct ids),
imports and profile updates now throw IllegalArgumentException for an empty
or whitespace-only part, and flag exposures with such a distinct id are
dropped with a warning log instead of sent.

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

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

On a hierarchical groups builder, profile messages for an identity target its
distinct_id while events resolve to its $user_id/$company_id. A combined
distinct_id that disagrees with the identity's own user_id or company_id would
update or delete one user's profile while events go to another, so it is now
refused with IllegalArgumentException on both identity profile and event paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tylerjroach
tylerjroach marked this pull request as ready for review November 20, 2026 21:02
@tylerjroach
tylerjroach requested review from a team and tdumitrescu November 20, 2026 21:02
@ketanmixpanel

Copy link
Copy Markdown
Contributor

Hierarchical groups review

Reviewed alongside the PHP, Python, Ruby and Go HG PRs, which should behave the same way.

Should fix before merge

  1. Exposures with a conflicting combined id are sent (BaseFlagsProvider.java#L278)
    trackExposure(Map...) checks only for blank parts. The exposure event is built in createEventSender with a non-HG new MessageBuilder(token) (MixpanelAPI.java#L698), so event()'s combined-id check doesn't run either. Example: context {distinct_id: "$company:acme|$user:u1", $company_id: "globex"} sends an exposure attributed to the wrong company. Python and Ruby log and drop; Go refuses.
    Fix: add the conflict check (like Ruby's combined_id_conflict), log, and return.

  2. HG is turned on in two places that can disagree (MixpanelAPI.java#L698)
    new MessageBuilder(token, true) and the flags config's .hierarchicalGroups(true) are independent, and MixpanelAPI's exposure sender always uses a non-HG builder. The HG guide says HG is turned on once at initialization. Python, Ruby, Go and PHP take one client option and pass it to the flag providers. If the builder is HG but flags aren't, exposures for contexts with only $user_id/$company_id are dropped; the other way round, user events skip every HG check.
    Fix: have one owner for the HG flag (MixpanelAPI or a shared config), and build the exposure MessageBuilder and flag configs from it.

  3. A whitespace-only $company_id counts as present for exposures (BaseFlagsProvider.java#L223)
    isPresent only checks non-empty, so " " is sent as $company_id. Python and Ruby treat blank as missing.
    Fix: use MixpanelIdentity.isBlank there.

  4. Identity events skip the final combined distinct_id check (MessageBuilder.java#L202, also L221)
    withIdentity keeps a distinct_id from properties when the identity has none, and adds $user_id/$company_id without checking against it.
    Fix: run requireCombinedDistinctIdMatchesProperties on the merged properties. Go already refuses this.

Cross-SDK alignment

  1. Company from a $company_id modifier on an unbound builder, and $distinct_id modifier retargeting. Java matches Python on both. PHP and Go require forCompany, and Ruby ignores the $distinct_id param. Needs one rule across SDKs.

On a hierarchical groups provider, an exposure whose combined distinct_id
($company:<c>|$user:<u>) names a different company or user than the
context's $company_id or $user_id is now logged and not sent. A $company_id
or $user_id that is empty or only whitespace is treated as absent, so it is
not sent and no longer attributes the exposure on its own.

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

@rahul-mixpanel rahul-mixpanel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hierarchical groups review (round 2). HG off looks safe: every HG path is gated on the init flag, the public API only gains additions apart from the documented literal-null ambiguity, and payloads are unchanged. Local flags now fill context_value_template whether or not HG is on, which matches remote evaluation; worth a release note. With HG on, there are four correctness gaps against the backend (inline): a pipe character in ids, numeric ids in event properties, local test-user overrides, and template fill vs the server's guards. There are also three smaller items: the modifier allowlist, subclass bypass, and duplicated helpers with Javadoc gaps. The earlier review's point about two independent HG switches (MixpanelAPI's exposure builder is non-HG) and the unchecked merged properties are still open. 577 tests pass on the head, and also on the head merged with current master.

*
* @throws IllegalArgumentException if the id is empty or only whitespace
*/
public Builder userId(String userId) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 A | in userId/companyId isn't rejected, and the backend can't handle it.

/groups rejects a $group_id containing | (ingestion/api/verify/verify.go). That check is per record, so set(userId("a|b").companyId("c"), …) is dropped without an error. For events, ingestion builds $company:c|$user:a|b, and GetCompanyIDAndUserIDFromDistinctID splits on |, gets 3 parts and errors. The transformer discards that error. A | in the company id breaks the split the same way. fromCombinedDistinctId here splits on the first |$user:, which doesn't match the backend's split.

Can we throw IllegalArgumentException for | in userId, companyId and forCompany (and validate in FlagContext)? Is ingestion already planning to handle this? If not, could you file a ticket and follow up?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a1f8f55: a hierarchical groups MessageBuilder refuses | in user and company ids in the identity overloads, forCompany, a $company_id modifier, and the parts of a combined $company:{c}|$user:{u} distinct id. MixpanelIdentity itself and non-HG builders are unchanged, since non-HG ids may contain |. The ingestion side is not a client issue.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Mostly there. Two paths still let | through on HG builders:

  • Custom group ids. groupSet("department", "a|b") builds a record that verify.go drops without an error.
  • Flags. FlagContext ids reach exposures unchecked (BaseFlagsProvider.trackExposure), so $user_id: "a|b" breaks the backend's id split.

Could HG builders refuse | in any $group_id, and could HG exposures drop ids containing | (log and skip, as the blank-id check does)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

| is refused wherever the SDK takes a user or company id. /groups rejects | in any $group_id on every project, so custom group ids aren't specific to hierarchical groups, and flag-context ids are sent as given like other raw values.

if (combined == null || properties == null) {
return;
}
requireCombinedPartMatches(distinctId, "company", combined.getCompanyId(), "$company_id",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 On HG, numeric $company_id/$user_id in event properties are dropped by ingestion, but /groups gets them as strings.

Ingestion reads ids only when they are strings (ingestion/remap/types/event.go, $user_id/$company_id .(string)). So event("u1", {"$company_id": 42, "$user_id": "u1"}) lands on user u1 with no company. The same company id as a /groups modifier is stringified ("A numeric $company_id modifier is written as a string", MessageBuilder.java:1521), so that profile lands under company "42". Events and profiles split. testCombinedDistinctIdEventWithMatchingIdsIsSentUnchanged asserts the number is sent through as-is.

Could HG builders stringify numeric ids in event properties, as /groups does, or throw? Does ingestion plan to accept numeric ids? If not, could you file a ticket and follow up?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this: raw event properties are sent as given, and the SDK only stringifies ids that come from a MixpanelIdentity or forCompany. Ingestion reading numeric $user_id/$company_id is not a client issue.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 The SDK already treats integer company ids as valid. A $company_id modifier of 42 is written as "42" on /groups, and the combined-id check treats 42 and "42" as equal. A customer with integer company ids gets profiles under "42" and events with no company. That split comes from the SDK being inconsistent, not only from ingestion. A minimal option: on HG builders, throw for a non-string $company_id/$user_id in event properties, as the modifier check does for floats. Could you do that? If not, could you file a ticket with ingestion on accepting numeric ids?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declining: raw event properties are sent as given. Ids that come from a MixpanelIdentity are always sent as strings.

String distinctId = context.get("distinct_id") != null ? context.get("distinct_id").toString() : null;
// Overrides are keyed by distinct id, which is the resolved assignment key
// when the flag assigns on distinct_id.
String distinctId = "distinct_id".equals(contextProperty)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 On HG, local test-user overrides don't match the server for flags not assigned on distinct_id.

The server's getEvaluationContext sets distinct_id = $company:{c}|$user:{u} whenever $company_id is present (BuildHierarchicalContext). evaluateFlags then runs overrideResponseForFlagsWhereSubjectIsTestUser with that id for every flag. Here, a $company_id, device_id or custom-group flag falls back to the raw distinct_id, which FlagContext.identity(user+company) never sets. A QA tester gets their override from remote eval but not from local eval.

Could the override key be built the server's way when $company_id is present? Do flags already have work in progress here? If not, could you file a ticket and follow up?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a1f8f55: when the context has non-empty string $user_id and $company_id, local flags look test users up by $company:{c}|$user:{u} for every flag, as the server does.

StringBuffer out = new StringBuffer();
Matcher matcher = CONTEXT_PLACEHOLDER.matcher(template);
while (matcher.find()) {
Object value = context.get(matcher.group(1));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 The template fills from values the server ignores, so local and remote can bucket differently.

BuildHierarchicalContext uses the hierarchical key only when $company_id is a non-empty string, and a group value only when it is a string. Otherwise it keeps the raw value. This fills from any non-null value via toString(). For example, $company_id: "" buckets locally on $company:|$user:u, and $company_id: 42 on $company:42|$user:u, while the server buckets both on the raw distinct_id. FlagContext.companyId("") is accepted today.

Could this treat non-string or empty values as missing (fall back to raw), as the server does? Is the flags team aware? If not, could you file a ticket and follow up?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a1f8f55: a context_value_template placeholder fills only from a non-empty string; otherwise the raw context value is used, as on the server.

// Keys of a /engage or /groups message that are not operations
private static final Set<String> NON_OPERATION_KEYS = Collections.unmodifiableSet(new LinkedHashSet<>(
Arrays.asList("$token", "$distinct_id", "$group_key", "$group_id", "$company_id", "$time", "$ip",
"$ignore_time", "$ignore_alias", "$mp_metadata", "$latitude", "$longitude")));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 $ignore_alias and $distinct_id pass the HG modifier allowlist, but /groups rejects both.

verify.go refuses $distinct_id ("must not be specified for groups") and $ignore_alias ("not supported for group updates"). The identity profile path handles $distinct_id, but a $distinct_id or $ignore_alias modifier on groupSet and the other group* methods builds a record that is dropped silently. Could these throw on HG, as other unsupported modifiers do?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a1f8f55: on hierarchical groups builders, $ignore_alias throws on any profile write and $distinct_id throws on group and company writes.

public JSONObject event(MixpanelIdentity identity, String eventName, JSONObject properties) {
requireIdentityMatchesProject(identity);
requireIdentityDistinctIdAgrees(identity);
return buildEvent(identity.getDistinctId(), eventName, withIdentity(identity, properties));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Identity overloads skip subclass overrides.

MessageBuilder is public and non-final. event(MixpanelIdentity…), importEvent(MixpanelIdentity…) and profileMessage call the private buildEvent, buildImportEvent and peopleMessage(…, boolean), not the public methods. A subclass that adds super properties in event(String…) silently stops applying them once callers move to identities. Could they route through the public methods, or could the changelog say so?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The identity overloads are new entry points; routing them through the public String methods would change how the identity is applied. It'll go in the release notes.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A release note works for this. Please call it out next to the literal-null overload note.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't add release notes like this.

*
* @return {company, user}, or null if the id is not in that form
*/
private static String[] splitCombinedDistinctId(String distinctId) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Duplicated helpers that disagree, plus repeated magic strings.

  • splitCombinedDistinctId and the $company:/|$user: constants copy MixpanelIdentity.fromCombinedDistinctId (MixpanelIdentity.java:145).
  • isBlankOrEmpty copies MixpanelIdentity.isBlank (:132) with different semantics: isBlank("") is false, isBlankOrEmpty("") is true.
  • MessageBuilder declares USER_ID_GROUP_KEY/COMPANY_ID_GROUP_KEY (:31), yet the diff adds 36 raw "$company_id" literals, for example companySet and the other company methods.

Could the parsing and blank checks live in one package-private helper, and the constants be used throughout?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e6f57c3: MessageBuilder code uses USER_ID_GROUP_KEY/COMPANY_ID_GROUP_KEY. The parsing and blank helpers stay separate: the classes are in different packages, so one shared helper would have to be public API.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 The cross-package point makes sense for MixpanelIdentity. But LocalFlagsProvider and BaseFlagsProvider share a package, and this round adds a third hardcoded copy of the format ("$company:" + companyId + "|$user:" + userId in testUserOverrideKey). Could that reuse BaseFlagsProvider's COMBINED_* constants (make them package-private), so the flags side has one definition?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in dea759b: LocalFlagsProvider reuses BaseFlagsProvider's combined-id constants.

/**
* @see #set(MixpanelIdentity, JSONObject)
*/
public JSONObject set(MixpanelIdentity identity, JSONObject properties, JSONObject modifiers) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 The new public API doesn't follow the repo's Javadoc and naming conventions.

  • Identity overloads: these carry only @see, while their String siblings document every @param/@return (for example setOnce(String, JSONObject, JSONObject), MessageBuilder.java:464-473). mvn verify now emits at least 59 new javadoc warnings (javadoc stops at 100) from MessageBuilder, MixpanelIdentity and FlagContext.
  • ExperimentationFlag constructor: the new 11-arg one has no Javadoc, while the existing one documents each param (ExperimentationFlag.java:28).
  • FlagContext fields: they use the m prefix, but the featureflags package uses plain names (BaseFlagsConfig.java:12, SelectedVariant.java:19).
  • README: it documents flags and service accounts (README.md:83, :157) but has no HG section.

Could these be brought in line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e6f57c3: param and return Javadoc on the MixpanelIdentity profile overloads, Javadoc on the ExperimentationFlag constructor that takes a template, and no m prefix on FlagContext.Builder's fields. No README change: the public docs are the source of truth.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 The MessageBuilder overloads and the ExperimentationFlag constructor look good now. Javadoc still reports 15 warnings on MixpanelIdentity (Builder setters and getters) and 16 on FlagContext.Builder (distinctId, userId, companyId, build and so on). Could those get @param/@return too? I'm fine leaving the README to the public docs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in dea759b: MixpanelIdentity and FlagContext no longer produce javadoc warnings.

tylerjroach and others added 3 commits November 24, 2026 14:13
- Refuse '|' in user and company ids on a hierarchical groups MessageBuilder:
  identity overloads, forCompany, a $company_id modifier, and the parts of
  a combined $company:{c}|$user:{u} distinct id. MixpanelIdentity and
  non-hierarchical builders are unchanged.
- Local flags: a context_value_template placeholder fills only from a
  non-empty string context value; otherwise the raw context value is used.
- Local flags: look test users up by $company:{c}|$user:{u} for every flag
  when the context has non-empty string $user_id and $company_id.
- On hierarchical groups builders, refuse $ignore_alias on any profile write
  and $distinct_id on group and company writes, which /groups rejects.
- Clearer error when an identity is combined with a $distinct_id modifier:
  pass either an identity or a $distinct_id, not both.
- Document that MessageBuilder(token, hierarchicalGroups) and the flags
  config's hierarchicalGroups(...) must be set the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Use USER_ID_GROUP_KEY/COMPANY_ID_GROUP_KEY in MessageBuilder code.
- Add @param/@return Javadoc to the MixpanelIdentity profile overloads.
- Document the ExperimentationFlag constructor that takes a context value
  template.
- Drop the m prefix from FlagContext.Builder's private fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hierarchical groups review: forCompany is for writes that carry no
identity, the company's own profile and custom group profiles. Events and
user profiles should use an identity that names the company; events from a
bound client don't add the bound company.

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

Copy link
Copy Markdown
Contributor Author

Replies to the review summaries:

  • context_value_template with HG off: it'll go in the release notes.
  • Conflicting exposures (Ketan, 1): fixed in 25efeb6: an exposure whose combined distinct_id names a different company or user than the context is logged and not sent.
  • Two HG switches (Rahul's earlier point; Ketan, 2): HG is set on each object you create, as Java configuration always has been; a1f8f55 documents that MessageBuilder(token, hierarchicalGroups) and the flags config's hierarchicalGroups(...) must agree.
  • Whitespace-only $company_id (Ketan, 3): fixed in 25efeb6: an empty or whitespace-only $company_id or $user_id counts as absent.
  • Identity events and unchecked merged properties (Ketan, 4; Rahul): Intentional. The identity is the explicit target. Verified live 2026-11-23: the service attributes by $user_id/$company_id, so the identity wins and nothing is misattributed. Go's stricter check is an accepted difference.
  • Company from a modifier, $distinct_id retargeting (Ketan, 5): Java's behaviour is the reference. A $company_id modifier states the company explicitly, so it's accepted and nothing is misattributed; PHP and Go being stricter is an accepted difference. Ruby now matches on $distinct_id (mixpanel-ruby 408f477).

@rahul-mixpanel rahul-mixpanel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at 2a920cf. Thanks for the quick turnaround. Test-user overrides, template guards and the /groups modifier checks are fixed, and they match the flags and ingestion code. The fixes introduce no new bugs, and nothing changes with HG off. 591 tests pass. Still open, with replies inline: pipe characters in custom group ids and flag contexts; numeric ids in event properties (pushback, needs a decision); the duplicated combined-id format, which now has a third copy; and Javadoc on MixpanelIdentity and FlagContext. Release notes should also mention that local test-user overrides key off $user_id and $company_id even with HG off, as the server does.

tylerjroach and others added 3 commits November 25, 2026 10:30
Flag evaluation reads $user_id and $company_id only as non-blank strings,
so exposures now do the same: a numeric id is neither attached nor used to
attribute the exposure. A $user_id is attached only alongside a valid
$company_id.

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

LocalFlagsProvider now builds the test-user override key from BaseFlagsProvider's
COMBINED_* constants (now package-private), so the flags package defines the
combined-id format once. Add missing Javadoc to MixpanelIdentity and FlagContext.
No behaviour change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MixpanelIdentity now holds only distinct_id, user_id and company_id. A device
id is event metadata on a server, so it is sent as a $device_id event
property like any other, and flag contexts that bucket by device set
device_id directly. The identity no longer adds a device id to events or
flag contexts, and docs, examples and errors no longer mention it. The
profile branch it made reachable is removed.

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

This branch has not been deployed

No deployments
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.

4 participants