Skip to content

fix: freeze ClientMetadata to satisfy spec req 4.2.2.1#273

Open
cristiangmarta wants to merge 1 commit intoopen-feature:mainfrom
cristiangmarta:fix/freeze-client-metadata
Open

fix: freeze ClientMetadata to satisfy spec req 4.2.2.1#273
cristiangmarta wants to merge 1 commit intoopen-feature:mainfrom
cristiangmarta:fix/freeze-client-metadata

Conversation

@cristiangmarta
Copy link
Copy Markdown

@cristiangmarta cristiangmarta commented Apr 17, 2026

Spec requirement 4.2.2.1 states that client_metadata in HookContext MUST be immutable.

ClientMetadata was an unfrozen Struct — any hook could mutate it, corrupting the client's @metadata for all subsequent evaluations since the same object is shared across hook invocations.

Adds .freeze at construction, consistent with how both built-in providers already handle ProviderMetadata.

Copilot AI review requested due to automatic review settings April 17, 2026 06:38
@cristiangmarta cristiangmarta requested a review from a team as a code owner April 17, 2026 06:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Ensures client_metadata exposed by OpenFeature::SDK::Client is immutable to satisfy OpenFeature spec requirement 4.2.2.1 and prevent hooks from mutating shared client metadata across evaluations.

Changes:

  • Freeze ClientMetadata when constructing a Client.
  • Add a spec asserting client.metadata is frozen.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
spec/open_feature/sdk/client_spec.rb Adds coverage asserting client metadata immutability via be_frozen.
lib/open_feature/sdk/client.rb Freezes the ClientMetadata instance at client initialization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/open_feature/sdk/client.rb Outdated
Comment thread spec/open_feature/sdk/client_spec.rb
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements immutability for client metadata by freezing the ClientMetadata object during initialization and adding a corresponding test case. The review feedback points out that while the metadata object itself is frozen, the underlying domain string remains mutable, which could violate the immutability requirements. It is recommended to freeze the domain string as well and update the test suite to verify this deeper level of immutability.

Comment thread lib/open_feature/sdk/client.rb Outdated
Comment thread spec/open_feature/sdk/client_spec.rb
Signed-off-by: Cristian Marta <cristian@caffe-lento.com>
@cristiangmarta cristiangmarta force-pushed the fix/freeze-client-metadata branch from 5d9886c to f13a181 Compare April 17, 2026 06:46
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