Skip to content

fix: Ignore nested kind attributes in multi-kind contexts - #39

Open
zigzagdev wants to merge 2 commits into
launchdarkly:mainfrom
zigzagdev:fix/multi-context-nested-kind
Open

zigzagdev wants to merge 2 commits into
launchdarkly:mainfrom
zigzagdev:fix/multi-context-nested-kind

Conversation

@zigzagdev

@zigzagdev zigzagdev commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

N/A

Describe the solution you've provided

In a multi-kind context, the top-level attribute name decides each context's kind.
However, buildSingleContext does not skip a nested kind attribute, so it falls through to LDContextBuilder::set(), which overwrites the context kind.

['kind' => 'multi', 'org' => ['key' => 'o', 'kind' => 'user'], 'user' => ['key' => 'u']]

In this example, both contexts become user. The multi-kind context is then invalid, and nothing is logged.

This PR skips kind alongside key and targetingKey.
This matches the behaviour of the Python provider.

Single contexts are unaffected.
As a result, a nested kind no longer overrides the top-level name. For example, 'org' => ['kind' => 'device'] now produces org instead of device.

Describe alternatives you've considered

Logging a warning when a nested kind differs from the top-level name. Happy to add this if you'd prefer.

vendor/bin/phpunit --filter NestedKind --testdox
PHPUnit 9.6.39 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.5.9
Configuration: `${directory}`/openfeature-php-server/phpunit.xml

Evaluation Context Converter (LaunchDarkly\Tests\EvaluationContextConverter)
 ✔ Multi context ignores nested kind attribute [9.40 ms]

Time: 00:00.012, Memory: 6.00 MB

Note

Overview
Fixes multi-kind OpenFeature → LaunchDarkly conversion when nested contexts include a kind field. In buildSingleContext, kind is now skipped during attribute iteration (with key and targetingKey) so it is not applied via the generic set() path, which would override the kind derived from the multi-context key name.

Adds regression tests for nested string, multi, and non-string kind values, plus a single-context case ensuring kind sets the context type without becoming a custom attribute.

Reviewed by Cursor Bugbot for commit dfe37aa. Bugbot is set up for automated code reviews on this repo. Configure here.

In a multi-kind context the top-level attribute name decides each
context's kind. A nested "kind" attribute fell through to the catch-all
LDContextBuilder::set(), which treats "kind" as the context kind and
replaced it. Two nested contexts could then end up with the same kind,
making the whole multi-kind context invalid with nothing logged.

Skip "kind" alongside "key" and "targetingKey" when copying attributes,
matching the Python provider. Single contexts are unaffected, since the
kind passed to the builder already comes from the same attribute.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@kinyoklion

Copy link
Copy Markdown
Member

Hello @zigzagdev,

Thank you for the contribution! We are adding a couple tests, and we will get this change propagated to other provider as well.

Thank you,
Ryan

kinyoklion added a commit to launchdarkly/openfeature-java-server that referenced this pull request Nov 18, 2026
**Requirements**

- [x] I have added test coverage for new or changed functionality
- [x] I have followed the repository's [pull request submission
guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests)
- [x] I have validated my changes against all supported platform
versions

**Related issues**

Same fix as launchdarkly/openfeature-php-server#39; the Python provider
already behaves this way.

**Describe the solution you've provided**

In a multi-kind evaluation context, the sub-context's kind comes from
its top-level attribute name (OFP Req 2.2.1 / 2.4.1).
`EvaluationContextConverter` skipped only `key`/`targetingKey` when
copying a sub-context's attributes, so a nested `kind` (e.g. `org: {
kind: "user", key: ... }`) overwrote the sub-context's kind and could
produce an invalid context. The converter now also skips `kind` there.

Tests cover a nested `kind` equal to another kind (`"user"`), `kind:
"multi"`, and a non-string `kind` (`42`). Each one checks that the
result is a valid two-kind context, that the `org` sub-context keeps
kind `org`, and that `kind` is not a custom attribute. The existing
single-context kind tests pass unchanged.

**Describe alternatives you've considered**

Logging a warning for a nested `kind`. Not done, to match the PHP and
Python providers.

**Additional context**

`./gradlew build` and `jacocoTestReport` pass locally (66 tests).

<!-- devin-bot-banner-begin -->
---

<p><picture><source
srcset="https://app.devin.ai/api/presigned_proxy?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjpudWxsLCJidWNrZXRfbmFtZSI6ImRldmluYXR0YWNobWVudHMiLCJidWNrZXRfa2V5IjoiYXR0YWNobWVudHNfcHJpdmF0ZS9vcmdfaGVBMWRpc2owVHVLd2VVSy83NTFkNTYyOC03NDkzLTRkMGItODdlZi05NjJlYzQ0MmYyYzkiLCJpYXQiOjE3OTQ5OTUwODUsIm9yZ19pZCI6Im9yZ19oZUExZGlzajBUdUt3ZVVLIiwiZmlsZW5hbWUiOiJib3QtYmFubmVyLnBuZyJ9.Zd1pKxyFYPQrECgilM1NaCBRegVltTL2BZehKDn1lqI"><img
height="63" alt="" align="left"></picture><strong><a
href="https://app.devin.ai/bots/649040a7a000452fbe03eca40165f725">OpenFeature
Maintainer</a> opened this PR for Ryan</strong><br>
Implemented in session <a
href="https://app.devin.ai/sessions/969bed84d8c94be39e7934812e681471">Ignore
nested kind in Java multi-context conversion</a><br>
<a
href="https://app.devin.ai/review/launchdarkly/openfeature-java-server/pull/72">Review&nbsp;with&nbsp;Devin</a>
· <a
href="https://app.devin.ai/desktop/session/969bed84d8c94be39e7934812e681471?variant=devin">Open&nbsp;in&nbsp;Devin&nbsp;Desktop</a></p>
<br clear="left">
<!-- devin-bot-banner-end -->

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Fixes **multi-kind** OpenFeature → LaunchDarkly conversion when a
sub-context (e.g. `org`) incorrectly includes a nested **`kind`**
attribute alongside `key`.
> 
> `EvaluationContextConverter.BuildSingleContext` already ignored `key`
and `targetingKey` when copying attributes; it now **also skips
`kind`**, since sub-context kind is defined by the **top-level attribute
name** in a `kind: multi` context. That prevents a nested `kind` (wrong
string, `"multi"`, or non-string) from corrupting the built `LDContext`
or landing in custom attributes.
> 
> A new test **`itIgnoresNestedKindInMultiKindContexts`** checks string
and non-string nested `kind` values and asserts a valid two-kind result
with `org` staying kind `org` and no `kind` custom attribute, with no
error logs.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
0a428fe. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
kinyoklion added a commit to launchdarkly/openfeature-dotnet-server that referenced this pull request Nov 18, 2026
**Requirements**

- [x] I have added test coverage for new or changed functionality
- [x] I have followed the repository's [pull request submission
guidelines](../blob/main/CONTRIBUTING.md#submitting-pull-requests)
- [ ] I have validated my changes against all supported platform
versions (net6.0/net8.0 tests run on Linux; net471 compiled only)

**Related issues**

OFP Req 2.2.1 and 2.4.1 (`sdk-specs`): in a multi-kind context the
top-level attribute name is the kind, and `kind` must not be copied as
an attribute. Matches the Python provider and
launchdarkly/openfeature-php-server#39.

**Describe the solution you've provided**

`EvalContextConverter.ProcessValue` skipped only `key`/`targetingKey`,
so a nested `kind` inside a sub-context structure overwrote that
sub-context's kind (e.g. `user: { kind: "org" }` next to `org: {...}`,
or `kind: "multi"`), producing an invalid context. It now also skips
`kind`; kind is determined outside attribute conversion, so single-kind
contexts with a top-level `kind` are unchanged. The nested value is
ignored silently, as in PHP.

Tests cover nested `kind` equal to another kind, `"multi"`, a number,
empty string and null (kinds/keys preserved, context valid, `kind`
absent from custom attributes, no log output), plus a single-context
`kind: "org"` regression. The collision and `"multi"` cases fail without
the fix.

**Describe alternatives you've considered**

Logging a warning for the ignored nested `kind`; not done to match the
PHP and Python behavior.

**Additional context**

None.

<!-- devin-bot-banner-begin -->
---

<p><picture><source
srcset="https://app.devin.ai/api/presigned_proxy?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjpudWxsLCJidWNrZXRfbmFtZSI6ImRldmluYXR0YWNobWVudHMiLCJidWNrZXRfa2V5IjoiYXR0YWNobWVudHNfcHJpdmF0ZS9vcmdfaGVBMWRpc2owVHVLd2VVSy8yYzEwNjhiOS0xZTQ0LTRhYzEtODUzZS0xNTc3Y2QyNTNmNzYiLCJpYXQiOjE3OTQ5OTUwMDEsIm9yZ19pZCI6Im9yZ19oZUExZGlzajBUdUt3ZVVLIiwiZmlsZW5hbWUiOiJib3QtYmFubmVyLnBuZyJ9.L9phxaOOCtDujoEJ1AdY3YiURUZ0SFOOB7C4BIblSCY"><img
height="63" alt="" align="left"></picture><strong><a
href="https://app.devin.ai/bots/649040a7a000452fbe03eca40165f725">OpenFeature
Maintainer</a> opened this PR for Ryan</strong><br>
Implemented in session <a
href="https://app.devin.ai/sessions/ef86cba726a147a0805937efbf276e79">Ignore
nested kind in .NET multi-context conversion</a><br>
<a
href="https://app.devin.ai/review/launchdarkly/openfeature-dotnet-server/pull/84">Review&nbsp;with&nbsp;Devin</a>
· <a
href="https://app.devin.ai/desktop/session/ef86cba726a147a0805937efbf276e79?variant=devin">Open&nbsp;in&nbsp;Devin&nbsp;Desktop</a></p>
<br clear="left">
<!-- devin-bot-banner-end -->

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> Fixes **multi-kind** OpenFeature → LaunchDarkly context conversion
when a sub-context structure includes a **`kind`** field (e.g. `user: {
kind: "org", ... }`). That value is no longer passed through attribute
mapping; **`kind`** is skipped in `ProcessValue` like **`key`** /
**`targetingKey`**, so each sub-context keeps the kind implied by its
top-level key and stays valid per OFP spec.
> 
> Adds tests for nested `kind` values (another kind, `"multi"`,
non-strings, empty, null)—contexts remain valid, **`kind`** is not a
custom attribute, and nothing is logged—and a regression test that a
top-level **`kind`** still sets the single-context kind.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
81e2af6. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@zigzagdev

Copy link
Copy Markdown
Contributor Author

@kinyoklion

Thank you for the reviewing and for taking care of the other providers!

Thank you for the contribution! We are adding a couple tests, and we will get this change propagated to other provider as well.

Ok.
So, let me know if there's anything else I can help with.

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.

2 participants