Skip to content

fix(constraint): preserve AddData integer precision during JSON round-trip - #707

Merged
sozercan merged 5 commits into
masterfrom
codex/fix-precision-loss-in-inventory-data
Aug 7, 2026
Merged

fix(constraint): preserve AddData integer precision during JSON round-trip#707
sozercan merged 5 commits into
masterfrom
codex/fix-precision-loss-in-inventory-data

Conversation

@sozercan

@sozercan sozercan commented Apr 9, 2026

Copy link
Copy Markdown
Member

Motivation

  • Client.AddData previously round-tripped referential/inventory data using encoding/json Marshal/Unmarshal, which decodes numbers to float64 and can lose precision for integers > 2^53.
  • The local Rego driver disables in‑memory RoundTripOnWrite, so callers must preserve numeric precision when preparing data for driver storage to avoid policy-evaluation corruption.

Description

  • Replaced the encoding/json Marshal/Unmarshal round-trip in Client.AddData with OPA's util.RoundTrip to preserve numeric precision by decoding numbers as json.Number (UseNumber).
  • Removed the unused encoding/json import and added github.com/open-policy-agent/opa/v1/util to the imports in constraint/pkg/client/client.go.
  • The change is minimal and localized to the data round-trip step so untyped JSON coercion for drivers is preserved while avoiding float64 precision loss; the inmem.OptRoundTripOnWrite(false) performance behavior is unchanged.

Testing

  • Ran go test ./pkg/client -run TestClient_AddData -count=1 and the test passed (ok github.com/open-policy-agent/frameworks/constraint/pkg/client).
  • Built and ran the client package tests locally with go test ./pkg/client and observed successful completion for the modified unit test(s).

Codex Task

Copilot AI balanced review requested due to automatic review settings April 9, 2026 19:39

Copilot AI 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.

Pull request overview

This PR updates Client.AddData to avoid integer precision loss when round-tripping referential/inventory data through JSON before writing to driver storage.

Changes:

  • Replaced encoding/json marshal/unmarshal round-trip with opa/util.RoundTrip (UseNumber) to preserve numeric precision.
  • Removed the unused encoding/json import and added github.com/open-policy-agent/opa/v1/util.
Show a summary per file
File Description
constraint/pkg/client/client.go Uses OPA’s JSON round-trip helper to prevent large integer coercion to float64 during AddData processing.

Copilot's findings

Tip

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

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread constraint/pkg/client/client.go Outdated
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
@sozercan
sozercan force-pushed the codex/fix-precision-loss-in-inventory-data branch from bec3d84 to ffd640e Compare April 21, 2026 21:09
Copilot AI review requested due to automatic review settings August 7, 2026 17:52

Copilot AI 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.

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5ba5f11f24

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread constraint/pkg/client/client.go Outdated
Copilot AI review requested due to automatic review settings August 7, 2026 18:30

Copilot AI 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.

Pull request overview

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

Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Copilot AI review requested due to automatic review settings August 7, 2026 19:15
@sozercan

sozercan commented Aug 7, 2026

Copy link
Copy Markdown
Member Author

@codex review

Copilot AI 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.

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 1b2406aede

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@sozercan
sozercan merged commit 9a75fe2 into master Aug 7, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants