Skip to content

fix: freeze ClientMetadata to satisfy spec req 4.2.2.1 - #273

Closed
cristiangmarta wants to merge 1 commit into
open-feature:mainfrom
cristiangmarta:fix/freeze-client-metadata
Closed

cristiangmarta wants to merge 1 commit into
open-feature:mainfrom
cristiangmarta:fix/freeze-client-metadata

Conversation

@cristiangmarta

@cristiangmarta cristiangmarta commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 Resolved
Comment thread spec/open_feature/sdk/client_spec.rb Resolved

@gemini-code-assist gemini-code-assist Bot 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.

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 Resolved
Comment thread spec/open_feature/sdk/client_spec.rb Resolved
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

@josecolella josecolella left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, and sorry for the long wait. LGTM. This is part of the spec v0.9.0 push tracked in #300.

Under v0.9.0 numbering this fixes 1.2.2 and 4.2.2.2 (frozen client metadata). Nothing blocking, but the title still cites 4.2.2.1.

@josecolella

Copy link
Copy Markdown
Collaborator

This now lives in #355, together with #270, #271 and #273. Your commit is cherry-picked unchanged and keeps your authorship, and the squash commit will credit you as co-author. CI couldn't run on this fork branch, and it had fallen behind main, so carrying it on our branch was the quickest way to land it. I'll close this PR once #355 merges.

@josecolella

Copy link
Copy Markdown
Collaborator

Merged via #355 (d15bd84) with your authorship and co-author credit, and released in 0.7.1. Closing this one. Thanks for the fix.

@josecolella

Copy link
Copy Markdown
Collaborator

Follow-up: this PR's title cited 4.2.2.1 (hook hints), which the frozen ClientMetadata didn't cover. That requirement, the rest of hook-input immutability (4.1.3, 4.1.4.1, 4.2.2.3), and a spec test for this PR's 4.2.2.2 fix are now in #357.

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.

3 participants