Skip to content

feat: say what a provider does when a number doesn't fit the accessor - #461

Open
cvas22 wants to merge 1 commit into
open-feature:mainfrom
cvas22:numeric-coercion
Open

cvas22 wants to merge 1 commit into
open-feature:mainfrom
cvas22:numeric-coercion

Conversation

@cvas22

@cvas22 cvas22 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

This PR

Takes option 1 from #430. For providers with separate integer and float accessors, a numeric value that can't be represented exactly in the requested type (a fraction asked for as an integer, or out of range) MUST come back as TYPE_MISMATCH, and a value that can (10.0 as an integer, 10 as a float) SHOULD be converted. That's the same rule as flagd's coercion ADR and the @numeric-coercion scenarios in the provider TCK.

I made the lossy half a MUST since silently returning 0 for 0.5 is the failure the issue is about, and kept the lossless half a SHOULD so a strict provider that rejects every cross-type request isn't non-conformant.

Related Issues

Fixes #430

Notes

I put it at the end of 2.2 as Condition 2.2.11 so nothing gets renumbered. I left the TCK README alone for now, it still says @numeric-coercion isn't backed by a requirement, happy to update that here or in a follow-up once the wording settles. #433 is the wider question for untyped backends and this doesn't try to answer it.

Adds Condition 2.2.11 for providers with separate integer and float
accessors. A value that can't be represented exactly in the requested
type must be reported as TYPE_MISMATCH instead of being rounded or
truncated, and a value that can (10.0 as an integer, 10 as a float)
should be converted.

Fixes open-feature#430

Signed-off-by: Srinivas Chippagiri <[email protected]>
@cvas22
cvas22 requested a review from a team as a code owner November 23, 2026 19:40
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The provider specification now defines conditional behavior for providers with separate integer and floating-point resolution methods. Inexact conversions require TYPE_MISMATCH; exact conversions should return the value in the requested type.

Changes: Numeric conversion contract

Layer / File(s) Summary
Specify numeric conversion behavior
specification.json, specification/sections/02-providers.md
Adds Condition 2.2.11. Providers with separate integer and floating-point resolution methods must report TYPE_MISMATCH when a value cannot be represented exactly in the requested type. For exact conversions, providers should return the value in that type.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Other · Severity of issue fixed: Medium

Possibly related issues

  • open-feature/spec issue 417: The new requirement defines behavior that the conformance suite tracks, but this change does not implement the suite.

Suggested reviewers: toddbaert, beeme1mr, kinyoklion

Merge Risk: Minimal · up to bd046

This change adds a specification rule for numeric values requested through a different typed accessor. Lossy conversions must return TYPE_MISMATCH, and exact conversions should be converted. It affects only the specification text, and no merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: it adds a rule for what a provider does when a numeric value does not fit the requested accessor type. The changeset adds Condition 2.2.11 to the provider spec, which …
Description check Passed The description states the change directly: lossy numeric conversions MUST return TYPE_MISMATCH, and lossless conversions SHOULD convert. It also links the change to issue #430 and explains why the tw…
Linked Issues check Passed Directly linked issue #430 asks the specification to state what a provider must do when a numeric value does not fit the requested accessor. It offers three options and leans toward option 1: lossless…
Out of Scope Changes check Passed The changes add Condition 2.2.11 with Conditional Requirements 2.2.11.1 and 2.2.11.2 to the provider specification. All of them implement the numeric-coercion objective of #430. The PR does not modify…
Full details: Title check

Explanation

The title names the main change: it adds a rule for what a provider does when a numeric value does not fit the requested accessor type. The changeset adds Condition 2.2.11 to the provider spec, which requires TYPE_MISMATCH for lossy numeric conversions and SHOULD-level conversion for exact ones. The title is specific and matches the diff.

Full details: Description check

Explanation

The description states the change directly: lossy numeric conversions MUST return TYPE_MISMATCH, and lossless conversions SHOULD convert. It also links the change to issue #430 and explains why the two requirement strengths differ. This matches the specification change.

Full details: Linked Issues check

Explanation

Directly linked issue #430 asks the specification to state what a provider must do when a numeric value does not fit the requested accessor. It offers three options and leans toward option 1: lossless coercion permitted, lossy coercion must return TYPE_MISMATCH. The reviewed head implements option 1 in specification/sections/02-providers.md. Condition 2.2.11 states that the provider defines separate integer and floating-point resolution methods. Conditional Requirement 2.2.11.1 (MUST) requires error code TYPE_MISMATCH when a resolved numeric value cannot be represented exactly. It covers a fractional value requested as an integer and a value outside the requested type's range. This matches the issue's concern about representability and accessor width, because the range rule covers width. Conditional Requirement 2.2.11.2 (SHOULD) requires conversion when the value is exactly representable, for example 10.0 as an integer. The examples for both requirements match the issue's 0.5 and 10.0 cases. Existing requirements 2.2.2.1, 2.2.7 and 1.3.2.1 are left unrenumbered, as the PR description states. The requirement is a specification text change, so no automated tests apply. Evidence limit: the diff tool could not read the changed blobs. The head file for 02-providers.md was read directly, which established the new text. The specification.json change (raw summary: +22 lines, a generated or mirrored artifact) was not inspected, so its consistency with the markdown is unverified.

Full details: Out of Scope Changes check

Explanation

The changes add Condition 2.2.11 with Conditional Requirements 2.2.11.1 and 2.2.11.2 to the provider specification. All of them implement the numeric-coercion objective of #430. The PR does not modify the TCK README, which the PR description states is intentionally deferred. The PR does not address the untyped-backend question in #433, which it names as separate scope. No unrelated changes were identified in the read content. The specification.json change was not readable through the diff tool, so that file was not verified for unrelated content. Its raw summary describes only the same new requirements.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4f043afc-5274-429f-b362-18a16c034fd7
Commits

Reviewing files that changed from the base of the PR and between b489ba9 and bd04635.

Files selected for processing: 2

  • specification.json
  • specification/sections/02-providers.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

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.

The provider contract does not say what to do when a numeric value does not fit the requested accessor

1 participant