← Back to Pull requests

fix: preserve integer precision in kube-applier JSON (un)marshalling #7071

Open
tmstff opened this pull request with 130 lines diff across 16 files
View on GitHub
tmstff tmstff commented on Sep 22, 2026 11:11 UTC
Author

Jira: ARO-29803

What

Route the kube-applier desired-object JSON (un)marshalling through
k8s.io/apimachinery/pkg/util/json (whose Unmarshal decodes whole numbers as
int64, exact to 2^63) instead of encoding/json (which decodes numbers into
interface{} as float64, losing precision beyond 2^53).

Two parts:

1. NeedsUpdate RawExtension comparison — compare runtime.RawExtension
payloads by round-tripping both through util/json (Unmarshal + Marshal) and
comparing the resulting bytes. Exact integer comparison < 2^63; still
format-invariant (3 == 3.0, 1e3 == 1000) and key-order-insensitive, so
numerically-equal payloads don't trigger spurious no-op write-backs. Added
unit coverage for large-integer distinguishability, numeric-format invariance,
malformed/trailing-garbage input.

2. Whole kube-applier (un)marshal surface — for consistency, every
marshal/unmarshal on the kube-applier data path is switched (not only the
strictly-necessary generic decodes):
- backend desire builders/helpers and read-desire comparison (jsonBytesEqual)
- shared Cosmos serialization used by kube-applier: cosmosstorageutils CRUD
and iterators, corecosmosstorage transaction, informer changefeed/snapshot
- kube-applier read_desire controller observed-object marshal

Why

controllerutils.NeedsUpdate and the kube-applier desire lifecycle compare and
round-trip runtime.RawExtension / Cosmos document payloads via JSON. Decoding
JSON numbers into float64 collapses integers beyond float64's exact range
(2^53) onto the nearest representable value — two distinct large integers compare
equal, masking real changes and suppressing needed write-backs.

util/json.Marshal is a passthrough to encoding/json (no behaviour change); its
Unmarshal is additionally case-sensitive, which is safe here because every
decoded payload is canonical JSON we produced (lowercase Cosmos tags / k8s
objects). corecosmosstorage/transaction.go keeps encoding/json for
json.RawMessage and aliases util/json as k8sjson.

Scope was deliberately limited to the kube-applier data path; the frontend ARM
request/response parsers (coreapi/coreapihelpers) and cluster-service dispatch
(ocm) were left on encoding/json to avoid changing ARM case-insensitivity
semantics.

Testing

All affected modules build, vet and lint clean; unit tests pass under the
repo-pinned toolchain (GOTOOLCHAIN=go1.25.7).

🤖 Generated with Claude Code

Diff: 130 lines (+99 / -31) across 16 files Reviewer: tmstff Review duration: 25804m
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.96) × (1 − Review Confidence (0.82)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.96 · 130 lines diff across 16 files
0.96
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.86 · 5 substantive comment(s)
0.86
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
81%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.292
Self Review self_review
0.140
Sensitive Paths sensitive_paths
0.096
Mass File Touch mass_file_touch
0.080
Real PR Conversation Timeline
62 items
openshift-merge-bot[bot] openshift-merge-bot[bot] commented on Sep 22, 2026 11:11 UTC
Bot

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: automatic mode

Copilot Copilot commented on code on Sep 22, 2026 11:15 UTC
Code Review
internal/controllerutils/needs_update.go:1
@@ -88,31 +90,86 @@ var needsUpdateEqualities = func() conversion.Equalities {
 			if bytes.Equal(aBytes, bBytes) {
 				return true
 			}
-			// Normalize both to canonical JSON (sorted keys) so that
-			// key-ordering differences don't produce false positives.
-			var aObj, bObj any
-			if err := json.Unmarshal(aBytes, &aObj); err != nil {
-				return false
-			}
-			if err := json.Unmarshal(bBytes, &bObj); err != nil {
-				return false
-			}
-			aNorm, err := json.Marshal(aObj)
+			// Fall back to a structural comparison so that key-ordering and
+			// numeric-formatting differences (3 vs 3.0, 1e6 vs 1000000) don't
+			// produce false positives, while keeping full integer precision so
+			// that numbers beyond float64's 2^53 range stay distinguishable.
+			aObj, err := decodeJSONPreservingNumbers(aBytes)
 			if err != nil {
 				return false
 			}
-			bNorm, err := json.Marshal(bObj)
+			bObj, err := decodeJSONPreservingNumbers(bBytes)
 			if err != nil {
 				return false
 			}
-			return bytes.Equal(aNorm, bNorm)
+			return jsonValuesEqual(aObj, bObj)
 		},
 	); err != nil {
 		panic(err)
 	}
 	return e
 }()
 
+// decodeJSONPreservingNumbers unmarshals JSON into a generic tree, keeping
+// numbers as json.Number so that large integers retain full precision instead
+// of collapsing onto the nearest float64.
+func decodeJSONPreservingNumbers(data []byte) (any, error) {
+	d := json.NewDecoder(bytes.NewReader(data))
+	d.UseNumber()
+	var v any
+	if err := d.Decode(&v); err != nil {
+		return nil, err
+	}
+	return v, nil
+}

Decoder.Decode accepts a valid JSON prefix and ignores trailing tokens. Because RawExtension.MarshalJSON can return its Raw bytes without validating them, a payload such as {"n":1} garbage can now compare equal and suppress a write-back, whereas the removed json.Unmarshal path rejected it. Keep the strict whole-input validation before doing the number-preserving decode.

Copilot Copilot commented on code on Sep 22, 2026 11:15 UTC
Code Review
Makefile:1
@@ -15,6 +15,13 @@ TOPOLOGY_FILE ?= topology.yaml
 export AZURE_TOKEN_CREDENTIALS ?= dev
 BUILD_SERVICES_OPTS ?= -j7
 
+# Pin the Go toolchain to the version declared in go.work so make targets are
+# reproducible and match CI even on machines with a newer Go installed. With the
+# default GOTOOLCHAIN=auto, a newer local toolchain is used as-is (auto only
+# upgrades, never downgrades), which drifts test output (e.g. flate/gzip bytes,
+# encoding/json error text) from CI. Override with `make GOTOOLCHAIN=...` if needed.
+export GOTOOLCHAIN ?= $(shell awk '/^go /{print "go"$$2; exit}' go.work)

The PR is described and titled as a RawExtension precision fix, but this adds a repository-wide Go toolchain policy change; combined with the unrelated swift-recorder and Helm-test changes, it mixes multiple tasks and makes the review scope unclear. Please split these changes into focused PRs or explain why they are required by this fix.

copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 22, 2026 11:15 UTC
Reviewer

<!-- ccr-overview-v2 -->

Copilot review overview

🟡 Changes recommended

Strict whole-input JSON validation must be restored before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> · 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.png" alt="Low severity" width="62" height="18" align="texttop"></picture>

<details open>
<summary><strong>Open (2)</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Reject trailing JSON tokens before number-preserving decode](#discussion_r4070985439) · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.png" alt="Low severity" width="62" height="18" align="texttop"></picture> [Split unrelated toolchain, recorder, and Helm changes from this fix](#discussion_r4070985500) · New

  • </details>

    <details>
    <summary><strong>What changed in this PR</strong></summary>

    Updates NeedsUpdate to preserve large-integer precision while remaining numeric-format invariant. The PR also includes unrelated portability and toolchain changes. Review identified a JSON trailing-input validation issue and scope concerns.

    Changes:

  • Adds arbitrary-precision structural JSON comparison.

  • Expands numeric comparison tests.

  • Adjusts toolchain and platform-specific test behavior.

  • Uses portable temporary-directory helpers.
  • | File | Description |
    |---|---|
    | tooling/​helmtest/​testrunner/​system_reserved_test.go | Skips GNU-specific tests outside Linux. |
    | swift-recorder/​pkg/​testutil/​testutil.go | Adds a resolved temporary-directory helper. |
    | swift-recorder/​pkg/​recorder/​recorder_test.go | Uses portable temporary directories. |
    | swift-recorder/​cmd/​cmd_test.go | Uses the shared temporary-directory helper. |
    | Makefile | Pins Make-invoked Go commands to the configured toolchain. |
    | internal/​controllerutils/​needs_update.go | Implements precision-preserving JSON comparison. |
    | internal/​controllerutils/​needs_update_test.go | Adds large-integer and numeric-format test coverage. |
    </details>

    ---

    💡 Configure MCP servers for context-aware, tailored reviews. <a href="https://docs.github.com/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review?tool=webui#mcp-servers-and-agent-skills" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn more in the docs.</a>

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 22, 2026 11:25 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    Copilot review overview

    🔵 Needs a closer look

    Validate the entire JSON payload before treating comparisons as equal.

    Review effort: Lite
    Findings: 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture>

    <details open>
    <summary><strong>Open (1)</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Reject trailing JSON tokens before number-preserving decode](#discussion_r4070985439)

  • </details>

    <details>
    <summary><strong>Resolved since last review (1)</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.png" alt="Low severity" width="62" height="18" align="texttop"></picture> [Split unrelated toolchain, recorder, and Helm changes from this fix](#discussion_r4070985500)

  • </details>

    tmstff tmstff commented on code on Sep 22, 2026 11:26 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,31 +90,86 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    -			var aObj, bObj any
    -			if err := json.Unmarshal(aBytes, &aObj); err != nil {
    -				return false
    -			}
    -			if err := json.Unmarshal(bBytes, &bObj); err != nil {
    -				return false
    -			}
    -			aNorm, err := json.Marshal(aObj)
    +			// Fall back to a structural comparison so that key-ordering and
    +			// numeric-formatting differences (3 vs 3.0, 1e6 vs 1000000) don't
    +			// produce false positives, while keeping full integer precision so
    +			// that numbers beyond float64's 2^53 range stay distinguishable.
    +			aObj, err := decodeJSONPreservingNumbers(aBytes)
     			if err != nil {
     				return false
     			}
    -			bNorm, err := json.Marshal(bObj)
    +			bObj, err := decodeJSONPreservingNumbers(bBytes)
     			if err != nil {
     				return false
     			}
    -			return bytes.Equal(aNorm, bNorm)
    +			return jsonValuesEqual(aObj, bObj)
     		},
     	); err != nil {
     		panic(err)
     	}
     	return e
     }()
     
    +// decodeJSONPreservingNumbers unmarshals JSON into a generic tree, keeping
    +// numbers as json.Number so that large integers retain full precision instead
    +// of collapsing onto the nearest float64.
    +func decodeJSONPreservingNumbers(data []byte) (any, error) {
    +	d := json.NewDecoder(bytes.NewReader(data))
    +	d.UseNumber()
    +	var v any
    +	if err := d.Decode(&v); err != nil {
    +		return nil, err
    +	}
    +	return v, nil
    +}

    done

    Copilot Copilot commented on code on Sep 22, 2026 11:28 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,31 +91,93 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    -			var aObj, bObj any
    -			if err := json.Unmarshal(aBytes, &aObj); err != nil {
    -				return false
    -			}
    -			if err := json.Unmarshal(bBytes, &bObj); err != nil {
    -				return false
    -			}
    -			aNorm, err := json.Marshal(aObj)
    +			// Fall back to a structural comparison so that key-ordering and
    +			// numeric-formatting differences (3 vs 3.0, 1e6 vs 1000000) don't
    +			// produce false positives, while keeping full integer precision so
    +			// that numbers beyond float64's 2^53 range stay distinguishable.
    +			aObj, err := decodeJSONPreservingNumbers(aBytes)
     			if err != nil {
     				return false
     			}
    -			bNorm, err := json.Marshal(bObj)
    +			bObj, err := decodeJSONPreservingNumbers(bBytes)
     			if err != nil {
     				return false
     			}
    -			return bytes.Equal(aNorm, bNorm)
    +			return jsonValuesEqual(aObj, bObj)
     		},
     	); err != nil {
     		panic(err)
     	}
     	return e
     }()
     
    +// decodeJSONPreservingNumbers unmarshals JSON into a generic tree, keeping
    +// numbers as json.Number so that large integers retain full precision instead
    +// of collapsing onto the nearest float64.
    +func decodeJSONPreservingNumbers(data []byte) (any, error) {
    +	// json.Decoder.Decode accepts a valid JSON prefix and ignores trailing
    +	// tokens, whereas json.Unmarshal validates the whole input. Guard with
    +	// json.Valid so that malformed payloads (e.g. `{"n":1} garbage`) are
    +	// rejected instead of silently comparing equal and suppressing a write-back.
    +	if !json.Valid(data) {
    +		return nil, fmt.Errorf("invalid JSON")
    +	}
    +	d := json.NewDecoder(bytes.NewReader(data))
    +	d.UseNumber()
    +	var v any
    +	if err := d.Decode(&v); err != nil {
    +		return nil, err
    +	}
    +	return v, nil
    +}
    +
    +// jsonValuesEqual compares two decoded JSON trees for semantic equality.
    +// Numbers are compared by numeric value with arbitrary precision (so 3, 3.0 and
    +// 3e0 are equal, while 2^54 and 2^54+1 are not); objects are compared
    +// irrespective of key order.
    +func jsonValuesEqual(a, b any) bool {
    +	switch av := a.(type) {
    +	case json.Number:
    +		bv, ok := b.(json.Number)
    +		if !ok {
    +			return false
    +		}
    +		ar, aok := new(big.Rat).SetString(av.String())
    +		br, bok := new(big.Rat).SetString(bv.String())

    big.Rat.SetString expands exponent notation into an arbitrary-precision rational. Because RawExtension can carry arbitrary Kubernetes JSON, a short valid value such as 1e1000000000 can make this reconcile-path comparison allocate an enormous integer (and two differently formatted large-exponent values reach this path), risking controller OOM/CPU exhaustion. Bound the exponent/expansion before calling SetString, or compare normalized decimal representations without materializing powers of ten.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 22, 2026 11:28 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    Copilot review overview

    🟡 Changes recommended

    Unbounded exponent expansion may cause excessive memory or CPU usage during reconciliation.

    Get a fresh assessment by requesting another Copilot review.

    Review effort: Lite
    Findings: 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture>

    <details open>
    <summary><strong>Open (1)</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> [Bound big.Rat exponent expansion to prevent reconcile-path resource exhaustion](#discussion_r4071088239) · New

  • </details>

    <details>
    <summary><strong>Resolved since last review (1)</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Reject trailing JSON tokens before number-preserving decode](#discussion_r4070985439)

  • </details>

    openshift-merge-bot[bot] openshift-merge-bot[bot] commented on Sep 22, 2026 11:50 UTC
    Bot

    Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
    /test e2e-parallel

    tmstff tmstff commented on code on Sep 22, 2026 13:17 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,31 +91,93 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    -			var aObj, bObj any
    -			if err := json.Unmarshal(aBytes, &aObj); err != nil {
    -				return false
    -			}
    -			if err := json.Unmarshal(bBytes, &bObj); err != nil {
    -				return false
    -			}
    -			aNorm, err := json.Marshal(aObj)
    +			// Fall back to a structural comparison so that key-ordering and
    +			// numeric-formatting differences (3 vs 3.0, 1e6 vs 1000000) don't
    +			// produce false positives, while keeping full integer precision so
    +			// that numbers beyond float64's 2^53 range stay distinguishable.
    +			aObj, err := decodeJSONPreservingNumbers(aBytes)
     			if err != nil {
     				return false
     			}
    -			bNorm, err := json.Marshal(bObj)
    +			bObj, err := decodeJSONPreservingNumbers(bBytes)
     			if err != nil {
     				return false
     			}
    -			return bytes.Equal(aNorm, bNorm)
    +			return jsonValuesEqual(aObj, bObj)
     		},
     	); err != nil {
     		panic(err)
     	}
     	return e
     }()
     
    +// decodeJSONPreservingNumbers unmarshals JSON into a generic tree, keeping
    +// numbers as json.Number so that large integers retain full precision instead
    +// of collapsing onto the nearest float64.
    +func decodeJSONPreservingNumbers(data []byte) (any, error) {
    +	// json.Decoder.Decode accepts a valid JSON prefix and ignores trailing
    +	// tokens, whereas json.Unmarshal validates the whole input. Guard with
    +	// json.Valid so that malformed payloads (e.g. `{"n":1} garbage`) are
    +	// rejected instead of silently comparing equal and suppressing a write-back.
    +	if !json.Valid(data) {
    +		return nil, fmt.Errorf("invalid JSON")
    +	}
    +	d := json.NewDecoder(bytes.NewReader(data))
    +	d.UseNumber()
    +	var v any
    +	if err := d.Decode(&v); err != nil {
    +		return nil, err
    +	}
    +	return v, nil
    +}
    +
    +// jsonValuesEqual compares two decoded JSON trees for semantic equality.
    +// Numbers are compared by numeric value with arbitrary precision (so 3, 3.0 and
    +// 3e0 are equal, while 2^54 and 2^54+1 are not); objects are compared
    +// irrespective of key order.
    +func jsonValuesEqual(a, b any) bool {
    +	switch av := a.(type) {
    +	case json.Number:
    +		bv, ok := b.(json.Number)
    +		if !ok {
    +			return false
    +		}
    +		ar, aok := new(big.Rat).SetString(av.String())
    +		br, bok := new(big.Rat).SetString(bv.String())

    done

    Copilot Copilot commented on code on Sep 22, 2026 13:29 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,31 +92,137 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    -			var aObj, bObj any
    -			if err := json.Unmarshal(aBytes, &aObj); err != nil {
    -				return false
    -			}
    -			if err := json.Unmarshal(bBytes, &bObj); err != nil {
    -				return false
    -			}
    -			aNorm, err := json.Marshal(aObj)
    +			// Fall back to a structural comparison so that key-ordering and
    +			// numeric-formatting differences (3 vs 3.0, 1e6 vs 1000000) don't
    +			// produce false positives, while keeping full integer precision so
    +			// that numbers beyond float64's 2^53 range stay distinguishable.
    +			aObj, err := decodeJSONPreservingNumbers(aBytes)
     			if err != nil {
     				return false
     			}
    -			bNorm, err := json.Marshal(bObj)
    +			bObj, err := decodeJSONPreservingNumbers(bBytes)
     			if err != nil {
     				return false
     			}
    -			return bytes.Equal(aNorm, bNorm)
    +			return jsonValuesEqual(aObj, bObj)
     		},
     	); err != nil {
     		panic(err)
     	}
     	return e
     }()
     
    +// decodeJSONPreservingNumbers unmarshals JSON into a generic tree, keeping
    +// numbers as json.Number so that large integers retain full precision instead
    +// of collapsing onto the nearest float64.
    +func decodeJSONPreservingNumbers(data []byte) (any, error) {
    +	// json.Decoder.Decode accepts a valid JSON prefix and ignores trailing
    +	// tokens, whereas json.Unmarshal validates the whole input. Guard with
    +	// json.Valid so that malformed payloads (e.g. `{"n":1} garbage`) are
    +	// rejected instead of silently comparing equal and suppressing a write-back.
    +	if !json.Valid(data) {
    +		return nil, fmt.Errorf("invalid JSON")
    +	}
    +	d := json.NewDecoder(bytes.NewReader(data))
    +	d.UseNumber()
    +	var v any
    +	if err := d.Decode(&v); err != nil {
    +		return nil, err
    +	}
    +	return v, nil
    +}
    +
    +// jsonValuesEqual compares two decoded JSON trees for semantic equality.
    +// Numbers are compared by numeric value with arbitrary precision (so 3, 3.0 and
    +// 3e0 are equal, while 2^54 and 2^54+1 are not); objects are compared
    +// irrespective of key order.
    +func jsonValuesEqual(a, b any) bool {
    +	switch av := a.(type) {
    +	case json.Number:
    +		bv, ok := b.(json.Number)
    +		if !ok {
    +			return false
    +		}
    +		return jsonNumbersEqual(av, bv)
    +	case map[string]any:
    +		bv, ok := b.(map[string]any)
    +		if !ok || len(av) != len(bv) {
    +			return false
    +		}
    +		for k, avVal := range av {
    +			bvVal, ok := bv[k]
    +			if !ok || !jsonValuesEqual(avVal, bvVal) {
    +				return false
    +			}
    +		}
    +		return true
    +	case []any:
    +		bv, ok := b.([]any)
    +		if !ok || len(av) != len(bv) {
    +			return false
    +		}
    +		for i := range av {
    +			if !jsonValuesEqual(av[i], bv[i]) {
    +				return false
    +			}
    +		}
    +		return true
    +	default:
    +		// Strings, bools, nil.
    +		return reflect.DeepEqual(a, b)
    +	}
    +}
    +
    +// maxJSONNumberExponent bounds the base-10 exponent magnitude we are willing to
    +// feed to big.Rat.SetString. A short but astronomically-scaled literal such as
    +// "1e1000000000" would otherwise make big.Rat materialize an enormous power of
    +// ten, risking OOM/CPU exhaustion on this reconcile-path comparison. Legitimate
    +// Kubernetes JSON numbers never approach this magnitude; anything beyond it is
    +// compared by exact text instead (a rare, safe false-positive at worst).
    +const maxJSONNumberExponent = 1000
    +
    +// jsonNumbersEqual reports whether two JSON number literals represent the same
    +// numeric value, comparing by value (so 3, 3.0 and 3e0 are equal) with arbitrary
    +// precision for the integer part (so 2^54 and 2^54+1 stay distinct). Literals
    +// whose exponent exceeds maxJSONNumberExponent are compared by exact text to
    +// avoid pathological big.Rat expansion.
    +func jsonNumbersEqual(a, b json.Number) bool {
    +	as, bs := a.String(), b.String()
    +	if as == bs {
    +		return true
    +	}
    +	if !boundedExponent(as) || !boundedExponent(bs) {
    +		// Known unequal as text; refuse to expand a pathological exponent.
    +		return false
    +	}
    +	ar, aok := new(big.Rat).SetString(as)
    +	br, bok := new(big.Rat).SetString(bs)
    +	if !aok || !bok {
    +		// Unparseable number literal: fall back to exact text comparison.
    +		return false
    +	}
    +	return ar.Cmp(br) == 0
    +}
    +
    +// boundedExponent reports whether the base-10 exponent of a JSON number literal
    +// (the part after 'e'/'E', if any) is within maxJSONNumberExponent in magnitude.
    +// A missing or unparseable exponent is treated as out of range only when it is
    +// present but invalid; literals without an exponent are always in range.
    +func boundedExponent(s string) bool {
    +	i := strings.IndexAny(s, "eE")
    +	if i < 0 {
    +		return true
    +	}
    +	exp, err := strconv.Atoi(s[i+1:])
    +	if err != nil {
    +		return false
    +	}
    +	if exp < 0 {
    +		exp = -exp
    +	}
    +	return exp <= maxJSONNumberExponent

    boundedExponent does not actually bound the minimum signed exponent: strconv.Atoi accepts the minimum int value, and negating it overflows so exp remains negative and passes exp <= maxJSONNumberExponent. A valid literal such as 1e-9223372036854775808 can therefore still reach big.Rat.SetString despite the expansion guard; compare both signed bounds before taking an absolute value.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 22, 2026 13:29 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    Copilot review overview

    🟡 Changes recommended

    Fix the exponent-bound check overflow at the minimum signed integer value.

    Get a fresh assessment by requesting another Copilot review.

    Review effort: Lite
    Findings: 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture>

    <details open>
    <summary><strong>Open (1)</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> [Prevent signed exponent overflow bypassing magnitude guard](#discussion_r4072168798) · New

  • </details>

    <details>
    <summary><strong>Resolved since last review (1)</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> [Bound big.Rat exponent expansion to prevent reconcile-path resource exhaustion](#discussion_r4071088239)

  • </details>

    openshift-merge-bot[bot] openshift-merge-bot[bot] commented on Sep 22, 2026 13:38 UTC
    Bot

    Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
    /test e2e-parallel

    tmstff tmstff commented on code on Sep 22, 2026 13:55 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,31 +92,137 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    -			var aObj, bObj any
    -			if err := json.Unmarshal(aBytes, &aObj); err != nil {
    -				return false
    -			}
    -			if err := json.Unmarshal(bBytes, &bObj); err != nil {
    -				return false
    -			}
    -			aNorm, err := json.Marshal(aObj)
    +			// Fall back to a structural comparison so that key-ordering and
    +			// numeric-formatting differences (3 vs 3.0, 1e6 vs 1000000) don't
    +			// produce false positives, while keeping full integer precision so
    +			// that numbers beyond float64's 2^53 range stay distinguishable.
    +			aObj, err := decodeJSONPreservingNumbers(aBytes)
     			if err != nil {
     				return false
     			}
    -			bNorm, err := json.Marshal(bObj)
    +			bObj, err := decodeJSONPreservingNumbers(bBytes)
     			if err != nil {
     				return false
     			}
    -			return bytes.Equal(aNorm, bNorm)
    +			return jsonValuesEqual(aObj, bObj)
     		},
     	); err != nil {
     		panic(err)
     	}
     	return e
     }()
     
    +// decodeJSONPreservingNumbers unmarshals JSON into a generic tree, keeping
    +// numbers as json.Number so that large integers retain full precision instead
    +// of collapsing onto the nearest float64.
    +func decodeJSONPreservingNumbers(data []byte) (any, error) {
    +	// json.Decoder.Decode accepts a valid JSON prefix and ignores trailing
    +	// tokens, whereas json.Unmarshal validates the whole input. Guard with
    +	// json.Valid so that malformed payloads (e.g. `{"n":1} garbage`) are
    +	// rejected instead of silently comparing equal and suppressing a write-back.
    +	if !json.Valid(data) {
    +		return nil, fmt.Errorf("invalid JSON")
    +	}
    +	d := json.NewDecoder(bytes.NewReader(data))
    +	d.UseNumber()
    +	var v any
    +	if err := d.Decode(&v); err != nil {
    +		return nil, err
    +	}
    +	return v, nil
    +}
    +
    +// jsonValuesEqual compares two decoded JSON trees for semantic equality.
    +// Numbers are compared by numeric value with arbitrary precision (so 3, 3.0 and
    +// 3e0 are equal, while 2^54 and 2^54+1 are not); objects are compared
    +// irrespective of key order.
    +func jsonValuesEqual(a, b any) bool {
    +	switch av := a.(type) {
    +	case json.Number:
    +		bv, ok := b.(json.Number)
    +		if !ok {
    +			return false
    +		}
    +		return jsonNumbersEqual(av, bv)
    +	case map[string]any:
    +		bv, ok := b.(map[string]any)
    +		if !ok || len(av) != len(bv) {
    +			return false
    +		}
    +		for k, avVal := range av {
    +			bvVal, ok := bv[k]
    +			if !ok || !jsonValuesEqual(avVal, bvVal) {
    +				return false
    +			}
    +		}
    +		return true
    +	case []any:
    +		bv, ok := b.([]any)
    +		if !ok || len(av) != len(bv) {
    +			return false
    +		}
    +		for i := range av {
    +			if !jsonValuesEqual(av[i], bv[i]) {
    +				return false
    +			}
    +		}
    +		return true
    +	default:
    +		// Strings, bools, nil.
    +		return reflect.DeepEqual(a, b)
    +	}
    +}
    +
    +// maxJSONNumberExponent bounds the base-10 exponent magnitude we are willing to
    +// feed to big.Rat.SetString. A short but astronomically-scaled literal such as
    +// "1e1000000000" would otherwise make big.Rat materialize an enormous power of
    +// ten, risking OOM/CPU exhaustion on this reconcile-path comparison. Legitimate
    +// Kubernetes JSON numbers never approach this magnitude; anything beyond it is
    +// compared by exact text instead (a rare, safe false-positive at worst).
    +const maxJSONNumberExponent = 1000
    +
    +// jsonNumbersEqual reports whether two JSON number literals represent the same
    +// numeric value, comparing by value (so 3, 3.0 and 3e0 are equal) with arbitrary
    +// precision for the integer part (so 2^54 and 2^54+1 stay distinct). Literals
    +// whose exponent exceeds maxJSONNumberExponent are compared by exact text to
    +// avoid pathological big.Rat expansion.
    +func jsonNumbersEqual(a, b json.Number) bool {
    +	as, bs := a.String(), b.String()
    +	if as == bs {
    +		return true
    +	}
    +	if !boundedExponent(as) || !boundedExponent(bs) {
    +		// Known unequal as text; refuse to expand a pathological exponent.
    +		return false
    +	}
    +	ar, aok := new(big.Rat).SetString(as)
    +	br, bok := new(big.Rat).SetString(bs)
    +	if !aok || !bok {
    +		// Unparseable number literal: fall back to exact text comparison.
    +		return false
    +	}
    +	return ar.Cmp(br) == 0
    +}
    +
    +// boundedExponent reports whether the base-10 exponent of a JSON number literal
    +// (the part after 'e'/'E', if any) is within maxJSONNumberExponent in magnitude.
    +// A missing or unparseable exponent is treated as out of range only when it is
    +// present but invalid; literals without an exponent are always in range.
    +func boundedExponent(s string) bool {
    +	i := strings.IndexAny(s, "eE")
    +	if i < 0 {
    +		return true
    +	}
    +	exp, err := strconv.Atoi(s[i+1:])
    +	if err != nil {
    +		return false
    +	}
    +	if exp < 0 {
    +		exp = -exp
    +	}
    +	return exp <= maxJSONNumberExponent

    done

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 22, 2026 14:00 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    Copilot review overview

    🔵 Needs a closer look

    An unresolved numeric-comparison issue can cause recurring no-op writes.

    Review effort: Lite
    Findings: None

    <details>
    <summary><strong>Resolved since last review (1)</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> [Prevent signed exponent overflow bypassing magnitude guard](#discussion_r4072168798)

  • </details>

    openshift-merge-bot[bot] openshift-merge-bot[bot] commented on Sep 22, 2026 14:16 UTC
    Bot

    Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
    /test e2e-parallel

    tmstff tmstff commented on Sep 24, 2026 07:33 UTC
    Author
    adalrsjr1 adalrsjr1 commented on code on Sep 24, 2026 20:08 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,31 +92,137 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    -			var aObj, bObj any
    -			if err := json.Unmarshal(aBytes, &aObj); err != nil {
    -				return false
    -			}
    -			if err := json.Unmarshal(bBytes, &bObj); err != nil {
    -				return false
    -			}
    -			aNorm, err := json.Marshal(aObj)
    +			// Fall back to a structural comparison so that key-ordering and
    +			// numeric-formatting differences (3 vs 3.0, 1e6 vs 1000000) don't
    +			// produce false positives, while keeping full integer precision so
    +			// that numbers beyond float64's 2^53 range stay distinguishable.
    +			aObj, err := decodeJSONPreservingNumbers(aBytes)
     			if err != nil {
     				return false
     			}
    -			bNorm, err := json.Marshal(bObj)
    +			bObj, err := decodeJSONPreservingNumbers(bBytes)
     			if err != nil {
     				return false
     			}
    -			return bytes.Equal(aNorm, bNorm)
    +			return jsonValuesEqual(aObj, bObj)
     		},
     	); err != nil {
     		panic(err)
     	}
     	return e
     }()
     
    +// decodeJSONPreservingNumbers unmarshals JSON into a generic tree, keeping
    +// numbers as json.Number so that large integers retain full precision instead
    +// of collapsing onto the nearest float64.
    +func decodeJSONPreservingNumbers(data []byte) (any, error) {

    could you confirm if the problem you are solving here is somehow similar to the one in the link? https://redhat.atlassian.net/browse/ARO-27909

    If so, I would suggest your decoding implementation be similar to the one in the linked ticket, so we have an unified decoding mechanism throughout the project.

    tmstff tmstff commented on Sep 25, 2026 07:09 UTC
    Author

    /hold rethinking solution

    Copilot Copilot commented on code on Sep 25, 2026 08:26 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,31 +90,109 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    -			var aObj, bObj any
    -			if err := json.Unmarshal(aBytes, &aObj); err != nil {
    -				return false
    -			}
    -			if err := json.Unmarshal(bBytes, &bObj); err != nil {
    -				return false
    -			}
    -			aNorm, err := json.Marshal(aObj)
    +			// Fall back to a structural comparison so that key-ordering and
    +			// numeric-formatting differences (3 vs 3.0, 1e6 vs 1000000) don't
    +			// produce false positives, while keeping full integer precision so
    +			// that numbers beyond float64's 2^53 range stay distinguishable.
    +			aObj, err := decodeJSONPreservingNumbers(aBytes)
     			if err != nil {
     				return false
     			}
    -			bNorm, err := json.Marshal(bObj)
    +			bObj, err := decodeJSONPreservingNumbers(bBytes)
     			if err != nil {
     				return false
     			}
    -			return bytes.Equal(aNorm, bNorm)
    +			return jsonValuesEqual(aObj, bObj)
     		},
     	); err != nil {
     		panic(err)
     	}
     	return e
     }()
     
    +// decodeJSONPreservingNumbers unmarshals JSON into a generic tree, keeping
    +// numbers as json.Number so that large integers retain full precision instead
    +// of collapsing onto the nearest float64.
    +func decodeJSONPreservingNumbers(data []byte) (any, error) {
    +	// json.Decoder.Decode accepts a valid JSON prefix and ignores trailing
    +	// tokens, whereas json.Unmarshal validates the whole input. Guard with
    +	// json.Valid so that malformed payloads (e.g. `{"n":1} garbage`) are
    +	// rejected instead of silently comparing equal and suppressing a write-back.
    +	if !json.Valid(data) {
    +		return nil, fmt.Errorf("invalid JSON")
    +	}
    +	d := json.NewDecoder(bytes.NewReader(data))
    +	d.UseNumber()
    +	var v any
    +	if err := d.Decode(&v); err != nil {
    +		return nil, err
    +	}
    +	return v, nil
    +}
    +
    +// jsonValuesEqual compares two decoded JSON trees for semantic equality.
    +// Numbers are compared by numeric value (so 3, 3.0 and 3e0 are equal) while
    +// integers keep full int64 precision (so 2^54 and 2^54+1 stay distinct);
    +// objects are compared irrespective of key order.
    +func jsonValuesEqual(a, b any) bool {
    +	switch av := a.(type) {
    +	case json.Number:
    +		bv, ok := b.(json.Number)
    +		if !ok {
    +			return false
    +		}
    +		return jsonNumbersEqual(av, bv)
    +	case map[string]any:
    +		bv, ok := b.(map[string]any)
    +		if !ok || len(av) != len(bv) {
    +			return false
    +		}
    +		for k, avVal := range av {
    +			bvVal, ok := bv[k]
    +			if !ok || !jsonValuesEqual(avVal, bvVal) {
    +				return false
    +			}
    +		}
    +		return true
    +	case []any:
    +		bv, ok := b.([]any)
    +		if !ok || len(av) != len(bv) {
    +			return false
    +		}
    +		for i := range av {
    +			if !jsonValuesEqual(av[i], bv[i]) {
    +				return false
    +			}
    +		}
    +		return true
    +	default:
    +		// Strings, bools, nil.
    +		return reflect.DeepEqual(a, b)
    +	}
    +}
    +
    +// jsonNumbersEqual reports whether two JSON number literals represent the same
    +// numeric value. When both are integers they are compared as int64 so that
    +// values beyond float64's exact 2^53 range stay distinct (e.g. 2^54 vs 2^54+1);
    +// otherwise they are compared as float64 so that differently-formatted equal
    +// values match (3 == 3.0, 1e6 == 1000000). float64 parsing also neutralises
    +// pathological exponents such as 1e1000000000, which overflow to a parse error
    +// and fall back to an exact text comparison instead of allocating huge values.
    +func jsonNumbersEqual(a, b json.Number) bool {
    +	if ai, aerr := a.Int64(); aerr == nil {
    +		if bi, berr := b.Int64(); berr == nil {
    +			return ai == bi
    +		}
    +	}
    +	af, aerr := a.Float64()
    +	bf, berr := b.Float64()
    +	if aerr != nil || berr != nil {
    +		// Unparseable or out-of-range literal: fall back to exact text.
    +		return a.String() == b.String()
    +	}
    +	return af == bf

    Float64() is still lossy for valid JSON numbers outside binary64 precision, so this does not preserve full numeric precision. For example, 9223372036854775807 vs 9223372036854775808 and 9007199254740992.1 vs 9007199254740992.2 round to the same float and suppress a required write-back; underflowed distinct values can also collapse to zero, while the exact-text fallback makes equivalent overflowed forms such as 1e1000 and 10e999 compare unequal. Compare json.Number values using an exact representation with a bounded exponent instead of Float64().

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 25, 2026 08:26 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    Copilot review overview

    🟡 Changes recommended

    Float64() can collapse distinct valid JSON numbers and suppress required write-backs.

    Get a fresh assessment by requesting another Copilot review.

    Review effort: Lite
    Findings: 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture>

    <details open>
    <summary><strong>Open (1)</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> [Avoid lossy Float64 comparison for exact JSON number changes](#discussion_r4102672519) · New

  • </details>

    tmstff tmstff commented on code on Sep 25, 2026 08:31 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,31 +90,109 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    -			var aObj, bObj any
    -			if err := json.Unmarshal(aBytes, &aObj); err != nil {
    -				return false
    -			}
    -			if err := json.Unmarshal(bBytes, &bObj); err != nil {
    -				return false
    -			}
    -			aNorm, err := json.Marshal(aObj)
    +			// Fall back to a structural comparison so that key-ordering and
    +			// numeric-formatting differences (3 vs 3.0, 1e6 vs 1000000) don't
    +			// produce false positives, while keeping full integer precision so
    +			// that numbers beyond float64's 2^53 range stay distinguishable.
    +			aObj, err := decodeJSONPreservingNumbers(aBytes)
     			if err != nil {
     				return false
     			}
    -			bNorm, err := json.Marshal(bObj)
    +			bObj, err := decodeJSONPreservingNumbers(bBytes)
     			if err != nil {
     				return false
     			}
    -			return bytes.Equal(aNorm, bNorm)
    +			return jsonValuesEqual(aObj, bObj)
     		},
     	); err != nil {
     		panic(err)
     	}
     	return e
     }()
     
    +// decodeJSONPreservingNumbers unmarshals JSON into a generic tree, keeping
    +// numbers as json.Number so that large integers retain full precision instead
    +// of collapsing onto the nearest float64.
    +func decodeJSONPreservingNumbers(data []byte) (any, error) {
    +	// json.Decoder.Decode accepts a valid JSON prefix and ignores trailing
    +	// tokens, whereas json.Unmarshal validates the whole input. Guard with
    +	// json.Valid so that malformed payloads (e.g. `{"n":1} garbage`) are
    +	// rejected instead of silently comparing equal and suppressing a write-back.
    +	if !json.Valid(data) {
    +		return nil, fmt.Errorf("invalid JSON")
    +	}
    +	d := json.NewDecoder(bytes.NewReader(data))
    +	d.UseNumber()
    +	var v any
    +	if err := d.Decode(&v); err != nil {
    +		return nil, err
    +	}
    +	return v, nil
    +}
    +
    +// jsonValuesEqual compares two decoded JSON trees for semantic equality.
    +// Numbers are compared by numeric value (so 3, 3.0 and 3e0 are equal) while
    +// integers keep full int64 precision (so 2^54 and 2^54+1 stay distinct);
    +// objects are compared irrespective of key order.
    +func jsonValuesEqual(a, b any) bool {
    +	switch av := a.(type) {
    +	case json.Number:
    +		bv, ok := b.(json.Number)
    +		if !ok {
    +			return false
    +		}
    +		return jsonNumbersEqual(av, bv)
    +	case map[string]any:
    +		bv, ok := b.(map[string]any)
    +		if !ok || len(av) != len(bv) {
    +			return false
    +		}
    +		for k, avVal := range av {
    +			bvVal, ok := bv[k]
    +			if !ok || !jsonValuesEqual(avVal, bvVal) {
    +				return false
    +			}
    +		}
    +		return true
    +	case []any:
    +		bv, ok := b.([]any)
    +		if !ok || len(av) != len(bv) {
    +			return false
    +		}
    +		for i := range av {
    +			if !jsonValuesEqual(av[i], bv[i]) {
    +				return false
    +			}
    +		}
    +		return true
    +	default:
    +		// Strings, bools, nil.
    +		return reflect.DeepEqual(a, b)
    +	}
    +}
    +
    +// jsonNumbersEqual reports whether two JSON number literals represent the same
    +// numeric value. When both are integers they are compared as int64 so that
    +// values beyond float64's exact 2^53 range stay distinct (e.g. 2^54 vs 2^54+1);
    +// otherwise they are compared as float64 so that differently-formatted equal
    +// values match (3 == 3.0, 1e6 == 1000000). float64 parsing also neutralises
    +// pathological exponents such as 1e1000000000, which overflow to a parse error
    +// and fall back to an exact text comparison instead of allocating huge values.
    +func jsonNumbersEqual(a, b json.Number) bool {
    +	if ai, aerr := a.Int64(); aerr == nil {
    +		if bi, berr := b.Int64(); berr == nil {
    +			return ai == bi
    +		}
    +	}
    +	af, aerr := a.Float64()
    +	bf, berr := b.Float64()
    +	if aerr != nil || berr != nil {
    +		// Unparseable or out-of-range literal: fall back to exact text.
    +		return a.String() == b.String()
    +	}
    +	return af == bf

    fine for our use case.

    tmstff tmstff commented on code on Sep 25, 2026 08:33 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,31 +92,137 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    -			var aObj, bObj any
    -			if err := json.Unmarshal(aBytes, &aObj); err != nil {
    -				return false
    -			}
    -			if err := json.Unmarshal(bBytes, &bObj); err != nil {
    -				return false
    -			}
    -			aNorm, err := json.Marshal(aObj)
    +			// Fall back to a structural comparison so that key-ordering and
    +			// numeric-formatting differences (3 vs 3.0, 1e6 vs 1000000) don't
    +			// produce false positives, while keeping full integer precision so
    +			// that numbers beyond float64's 2^53 range stay distinguishable.
    +			aObj, err := decodeJSONPreservingNumbers(aBytes)
     			if err != nil {
     				return false
     			}
    -			bNorm, err := json.Marshal(bObj)
    +			bObj, err := decodeJSONPreservingNumbers(bBytes)
     			if err != nil {
     				return false
     			}
    -			return bytes.Equal(aNorm, bNorm)
    +			return jsonValuesEqual(aObj, bObj)
     		},
     	); err != nil {
     		panic(err)
     	}
     	return e
     }()
     
    +// decodeJSONPreservingNumbers unmarshals JSON into a generic tree, keeping
    +// numbers as json.Number so that large integers retain full precision instead
    +// of collapsing onto the nearest float64.
    +func decodeJSONPreservingNumbers(data []byte) (any, error) {

    good point. Simplifies the implementation and still gives enough precision (integer precision up to 2^63). Also conformity is a valid point! 👍

    tmstff tmstff commented on Sep 25, 2026 08:36 UTC
    Author

    /unhold

    openshift-merge-bot[bot] openshift-merge-bot[bot] commented on Sep 25, 2026 09:07 UTC
    Bot

    Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
    /test e2e-parallel

    adalrsjr1 adalrsjr1 commented on code on Sep 25, 2026 14:23 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,31 +90,109 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    -			var aObj, bObj any
    -			if err := json.Unmarshal(aBytes, &aObj); err != nil {
    -				return false
    -			}
    -			if err := json.Unmarshal(bBytes, &bObj); err != nil {
    -				return false
    -			}
    -			aNorm, err := json.Marshal(aObj)
    +			// Fall back to a structural comparison so that key-ordering and
    +			// numeric-formatting differences (3 vs 3.0, 1e6 vs 1000000) don't
    +			// produce false positives, while keeping full integer precision so
    +			// that numbers beyond float64's 2^53 range stay distinguishable.
    +			aObj, err := decodeJSONPreservingNumbers(aBytes)
     			if err != nil {
     				return false
     			}
    -			bNorm, err := json.Marshal(bObj)
    +			bObj, err := decodeJSONPreservingNumbers(bBytes)
     			if err != nil {
     				return false
     			}
    -			return bytes.Equal(aNorm, bNorm)
    +			return jsonValuesEqual(aObj, bObj)
     		},
     	); err != nil {
     		panic(err)
     	}
     	return e
     }()
     
    +// decodeJSONPreservingNumbers unmarshals JSON into a generic tree, keeping
    +// numbers as json.Number so that large integers retain full precision instead
    +// of collapsing onto the nearest float64.
    +func decodeJSONPreservingNumbers(data []byte) (any, error) {
    +	// json.Decoder.Decode accepts a valid JSON prefix and ignores trailing
    +	// tokens, whereas json.Unmarshal validates the whole input. Guard with
    +	// json.Valid so that malformed payloads (e.g. `{"n":1} garbage`) are
    +	// rejected instead of silently comparing equal and suppressing a write-back.
    +	if !json.Valid(data) {
    +		return nil, fmt.Errorf("invalid JSON")
    +	}

    why the first validation? It's unnecessary. Consider d.Decode as an optimistic validator. If it decodes the json is valid, otherwise invalid. This code will be executed in many controllers doing this decoding many times, doing this validation twice just add more latency to the overall system. Add an unit test with an invalid json to catch any regression.

    tmstff tmstff commented on code on Sep 28, 2026 07:38 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,31 +90,86 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    -			var aObj, bObj any
    -			if err := json.Unmarshal(aBytes, &aObj); err != nil {
    -				return false
    -			}
    -			if err := json.Unmarshal(bBytes, &bObj); err != nil {
    -				return false
    -			}
    -			aNorm, err := json.Marshal(aObj)
    +			// Fall back to a structural comparison so that key-ordering and
    +			// numeric-formatting differences (3 vs 3.0, 1e6 vs 1000000) don't
    +			// produce false positives, while keeping full integer precision so
    +			// that numbers beyond float64's 2^53 range stay distinguishable.
    +			aObj, err := decodeJSONPreservingNumbers(aBytes)
     			if err != nil {
     				return false
     			}
    -			bNorm, err := json.Marshal(bObj)
    +			bObj, err := decodeJSONPreservingNumbers(bBytes)
     			if err != nil {
     				return false
     			}
    -			return bytes.Equal(aNorm, bNorm)
    +			return jsonValuesEqual(aObj, bObj)
     		},
     	); err != nil {
     		panic(err)
     	}
     	return e
     }()
     
    +// decodeJSONPreservingNumbers unmarshals JSON into a generic tree, keeping
    +// numbers as json.Number so that large integers retain full precision instead
    +// of collapsing onto the nearest float64.
    +func decodeJSONPreservingNumbers(data []byte) (any, error) {
    +	d := json.NewDecoder(bytes.NewReader(data))
    +	d.UseNumber()
    +	var v any
    +	if err := d.Decode(&v); err != nil {
    +		return nil, err
    +	}
    +	return v, nil
    +}

    Fixed. The comparison no longer relies on Decode alone: after decoding the first value, decodeJSONPreservingNumbers requires d.Token() to return io.EOF, rejecting trailing tokens like {"n":1} garbage. This uses the same decoder buffer (no separate full-input pass). Covered by the trailing garbage after a valid JSON value must trigger an update test.

    tmstff tmstff commented on code on Sep 28, 2026 07:38 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,31 +91,93 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    -			var aObj, bObj any
    -			if err := json.Unmarshal(aBytes, &aObj); err != nil {
    -				return false
    -			}
    -			if err := json.Unmarshal(bBytes, &bObj); err != nil {
    -				return false
    -			}
    -			aNorm, err := json.Marshal(aObj)
    +			// Fall back to a structural comparison so that key-ordering and
    +			// numeric-formatting differences (3 vs 3.0, 1e6 vs 1000000) don't
    +			// produce false positives, while keeping full integer precision so
    +			// that numbers beyond float64's 2^53 range stay distinguishable.
    +			aObj, err := decodeJSONPreservingNumbers(aBytes)
     			if err != nil {
     				return false
     			}
    -			bNorm, err := json.Marshal(bObj)
    +			bObj, err := decodeJSONPreservingNumbers(bBytes)
     			if err != nil {
     				return false
     			}
    -			return bytes.Equal(aNorm, bNorm)
    +			return jsonValuesEqual(aObj, bObj)
     		},
     	); err != nil {
     		panic(err)
     	}
     	return e
     }()
     
    +// decodeJSONPreservingNumbers unmarshals JSON into a generic tree, keeping
    +// numbers as json.Number so that large integers retain full precision instead
    +// of collapsing onto the nearest float64.
    +func decodeJSONPreservingNumbers(data []byte) (any, error) {
    +	// json.Decoder.Decode accepts a valid JSON prefix and ignores trailing
    +	// tokens, whereas json.Unmarshal validates the whole input. Guard with
    +	// json.Valid so that malformed payloads (e.g. `{"n":1} garbage`) are
    +	// rejected instead of silently comparing equal and suppressing a write-back.
    +	if !json.Valid(data) {
    +		return nil, fmt.Errorf("invalid JSON")
    +	}
    +	d := json.NewDecoder(bytes.NewReader(data))
    +	d.UseNumber()
    +	var v any
    +	if err := d.Decode(&v); err != nil {
    +		return nil, err
    +	}
    +	return v, nil
    +}
    +
    +// jsonValuesEqual compares two decoded JSON trees for semantic equality.
    +// Numbers are compared by numeric value with arbitrary precision (so 3, 3.0 and
    +// 3e0 are equal, while 2^54 and 2^54+1 are not); objects are compared
    +// irrespective of key order.
    +func jsonValuesEqual(a, b any) bool {
    +	switch av := a.(type) {
    +	case json.Number:
    +		bv, ok := b.(json.Number)
    +		if !ok {
    +			return false
    +		}
    +		ar, aok := new(big.Rat).SetString(av.String())
    +		br, bok := new(big.Rat).SetString(bv.String())

    Resolved by dropping big.Rat entirely. Numbers are now compared as int64 when both are integral (keeps 2^54 precision) and otherwise as float64. A pathological literal like 1e1000000000 overflows Float64() to a parse error and falls back to an exact text comparison, so no enormous value is ever materialised on this path.

    tmstff tmstff commented on code on Sep 28, 2026 07:38 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,31 +92,137 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    -			var aObj, bObj any
    -			if err := json.Unmarshal(aBytes, &aObj); err != nil {
    -				return false
    -			}
    -			if err := json.Unmarshal(bBytes, &bObj); err != nil {
    -				return false
    -			}
    -			aNorm, err := json.Marshal(aObj)
    +			// Fall back to a structural comparison so that key-ordering and
    +			// numeric-formatting differences (3 vs 3.0, 1e6 vs 1000000) don't
    +			// produce false positives, while keeping full integer precision so
    +			// that numbers beyond float64's 2^53 range stay distinguishable.
    +			aObj, err := decodeJSONPreservingNumbers(aBytes)
     			if err != nil {
     				return false
     			}
    -			bNorm, err := json.Marshal(bObj)
    +			bObj, err := decodeJSONPreservingNumbers(bBytes)
     			if err != nil {
     				return false
     			}
    -			return bytes.Equal(aNorm, bNorm)
    +			return jsonValuesEqual(aObj, bObj)
     		},
     	); err != nil {
     		panic(err)
     	}
     	return e
     }()
     
    +// decodeJSONPreservingNumbers unmarshals JSON into a generic tree, keeping
    +// numbers as json.Number so that large integers retain full precision instead
    +// of collapsing onto the nearest float64.
    +func decodeJSONPreservingNumbers(data []byte) (any, error) {
    +	// json.Decoder.Decode accepts a valid JSON prefix and ignores trailing
    +	// tokens, whereas json.Unmarshal validates the whole input. Guard with
    +	// json.Valid so that malformed payloads (e.g. `{"n":1} garbage`) are
    +	// rejected instead of silently comparing equal and suppressing a write-back.
    +	if !json.Valid(data) {
    +		return nil, fmt.Errorf("invalid JSON")
    +	}
    +	d := json.NewDecoder(bytes.NewReader(data))
    +	d.UseNumber()
    +	var v any
    +	if err := d.Decode(&v); err != nil {
    +		return nil, err
    +	}
    +	return v, nil
    +}
    +
    +// jsonValuesEqual compares two decoded JSON trees for semantic equality.
    +// Numbers are compared by numeric value with arbitrary precision (so 3, 3.0 and
    +// 3e0 are equal, while 2^54 and 2^54+1 are not); objects are compared
    +// irrespective of key order.
    +func jsonValuesEqual(a, b any) bool {
    +	switch av := a.(type) {
    +	case json.Number:
    +		bv, ok := b.(json.Number)
    +		if !ok {
    +			return false
    +		}
    +		return jsonNumbersEqual(av, bv)
    +	case map[string]any:
    +		bv, ok := b.(map[string]any)
    +		if !ok || len(av) != len(bv) {
    +			return false
    +		}
    +		for k, avVal := range av {
    +			bvVal, ok := bv[k]
    +			if !ok || !jsonValuesEqual(avVal, bvVal) {
    +				return false
    +			}
    +		}
    +		return true
    +	case []any:
    +		bv, ok := b.([]any)
    +		if !ok || len(av) != len(bv) {
    +			return false
    +		}
    +		for i := range av {
    +			if !jsonValuesEqual(av[i], bv[i]) {
    +				return false
    +			}
    +		}
    +		return true
    +	default:
    +		// Strings, bools, nil.
    +		return reflect.DeepEqual(a, b)
    +	}
    +}
    +
    +// maxJSONNumberExponent bounds the base-10 exponent magnitude we are willing to
    +// feed to big.Rat.SetString. A short but astronomically-scaled literal such as
    +// "1e1000000000" would otherwise make big.Rat materialize an enormous power of
    +// ten, risking OOM/CPU exhaustion on this reconcile-path comparison. Legitimate
    +// Kubernetes JSON numbers never approach this magnitude; anything beyond it is
    +// compared by exact text instead (a rare, safe false-positive at worst).
    +const maxJSONNumberExponent = 1000
    +
    +// jsonNumbersEqual reports whether two JSON number literals represent the same
    +// numeric value, comparing by value (so 3, 3.0 and 3e0 are equal) with arbitrary
    +// precision for the integer part (so 2^54 and 2^54+1 stay distinct). Literals
    +// whose exponent exceeds maxJSONNumberExponent are compared by exact text to
    +// avoid pathological big.Rat expansion.
    +func jsonNumbersEqual(a, b json.Number) bool {
    +	as, bs := a.String(), b.String()
    +	if as == bs {
    +		return true
    +	}
    +	if !boundedExponent(as) || !boundedExponent(bs) {
    +		// Known unequal as text; refuse to expand a pathological exponent.
    +		return false
    +	}
    +	ar, aok := new(big.Rat).SetString(as)
    +	br, bok := new(big.Rat).SetString(bs)
    +	if !aok || !bok {
    +		// Unparseable number literal: fall back to exact text comparison.
    +		return false
    +	}
    +	return ar.Cmp(br) == 0
    +}
    +
    +// boundedExponent reports whether the base-10 exponent of a JSON number literal
    +// (the part after 'e'/'E', if any) is within maxJSONNumberExponent in magnitude.
    +// A missing or unparseable exponent is treated as out of range only when it is
    +// present but invalid; literals without an exponent are always in range.
    +func boundedExponent(s string) bool {
    +	i := strings.IndexAny(s, "eE")
    +	if i < 0 {
    +		return true
    +	}
    +	exp, err := strconv.Atoi(s[i+1:])
    +	if err != nil {
    +		return false
    +	}
    +	if exp < 0 {
    +		exp = -exp
    +	}
    +	return exp <= maxJSONNumberExponent

    Obsolete after the simplification: the exponent guard (and the strconv.Atoi negation) were removed. float64 parsing now handles out-of-range exponents safely (parse error → exact text compare), so the signed-overflow path no longer exists.

    tmstff tmstff commented on code on Sep 28, 2026 07:38 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,31 +90,109 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    -			var aObj, bObj any
    -			if err := json.Unmarshal(aBytes, &aObj); err != nil {
    -				return false
    -			}
    -			if err := json.Unmarshal(bBytes, &bObj); err != nil {
    -				return false
    -			}
    -			aNorm, err := json.Marshal(aObj)
    +			// Fall back to a structural comparison so that key-ordering and
    +			// numeric-formatting differences (3 vs 3.0, 1e6 vs 1000000) don't
    +			// produce false positives, while keeping full integer precision so
    +			// that numbers beyond float64's 2^53 range stay distinguishable.
    +			aObj, err := decodeJSONPreservingNumbers(aBytes)
     			if err != nil {
     				return false
     			}
    -			bNorm, err := json.Marshal(bObj)
    +			bObj, err := decodeJSONPreservingNumbers(bBytes)
     			if err != nil {
     				return false
     			}
    -			return bytes.Equal(aNorm, bNorm)
    +			return jsonValuesEqual(aObj, bObj)
     		},
     	); err != nil {
     		panic(err)
     	}
     	return e
     }()
     
    +// decodeJSONPreservingNumbers unmarshals JSON into a generic tree, keeping
    +// numbers as json.Number so that large integers retain full precision instead
    +// of collapsing onto the nearest float64.
    +func decodeJSONPreservingNumbers(data []byte) (any, error) {
    +	// json.Decoder.Decode accepts a valid JSON prefix and ignores trailing
    +	// tokens, whereas json.Unmarshal validates the whole input. Guard with
    +	// json.Valid so that malformed payloads (e.g. `{"n":1} garbage`) are
    +	// rejected instead of silently comparing equal and suppressing a write-back.
    +	if !json.Valid(data) {
    +		return nil, fmt.Errorf("invalid JSON")
    +	}

    Done. Removed the json.Valid pre-pass. Validation now piggybacks on the single decode: Decode the first value, then require d.Token() == io.EOF to reject trailing data — same decoder buffer, no second full parse. Bare Decode alone was insufficient because it silently ignores trailing tokens (e.g. {"n":1} garbage). Added a malformed-JSON unit test ({"n":}) alongside the trailing-garbage one to catch regressions.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 28, 2026 07:40 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    Copilot review overview

    🔵 Needs a closer look

    Decimal or exponent representations of integral values can still lose precision and suppress required updates.

    Review effort: Lite
    Findings: None

    <details>
    <summary><strong>Resolved since last review (1)</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> [Avoid lossy Float64 comparison for exact JSON number changes](#discussion_r4102672519)

  • </details>

    openshift-merge-bot[bot] openshift-merge-bot[bot] commented on Sep 28, 2026 08:12 UTC
    Bot

    Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
    /test e2e-parallel

    adalrsjr1 adalrsjr1 commented on Sep 28, 2026 13:26 UTC
    Contributor

    /lgtm

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 29, 2026 07:30 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    Copilot review overview

    🔵 Needs a closer look

    Normalize negative zero values before marshaling to avoid false updates.

    Review effort: Lite
    Findings: None

    Copilot Copilot commented on code on Sep 29, 2026 07:37 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,8 +88,12 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    +			// Round-trip both payloads through k8s util/json and compare the
    +			// re-marshaled bytes. util/json decodes whole numbers to int64 (so
    +			// integers beyond float64's 2^53 range stay distinguishable) and
    +			// re-marshaling canonicalizes the rest: map keys are sorted (so
    +			// key-ordering differences don't matter) and equal numbers render
    +			// identically (3 == 3.0, 1e6 == 1000000, int64 == whole float64).

    This round-trip does not canonicalize all numerically equal JSON values: -0.0 is decoded as float64(-0) and marshaled as -0, while 0 is decoded as int64(0) and marshaled as 0. Thus valid payloads such as {"n":-0.0} and {"n":0} still make NeedsUpdate report a change, contrary to the stated format-invariance guarantee; normalize signed zero (and add a regression case) before comparing.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 29, 2026 07:37 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    Copilot review overview

    🟡 Changes recommended

    Normalize signed zero comparisons and qualify the integer-precision comment.

    Review effort: Lite
    Findings: 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture>

    <details open>
    <summary><strong>Open (1)</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Normalize negative zero to preserve numeric format invariance](#discussion_r4130830069) · New

  • </details>

    Copilot Copilot commented on code on Sep 29, 2026 07:47 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,8 +88,12 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    +			// Round-trip both payloads through k8s util/json and compare the
    +			// re-marshaled bytes. util/json decodes whole numbers to int64 (so
    +			// integers beyond float64's 2^53 range stay distinguishable) and
    +			// re-marshaling canonicalizes the rest: map keys are sorted (so
    +			// key-ordering differences don't matter) and equal numbers render
    +			// identically (3 == 3.0, 1e6 == 1000000, int64 == whole float64).

    This normalization is still not format-invariant for integral values near the int64 limit. For example, {"n":9223372036854775807} is preserved as an int64, while the numerically equal {"n":9223372036854775807.0} is decoded as float64 and re-marshaled as {"n":9223372036854776000}, so NeedsUpdate reports an update. Either preserve/compare the original numeric representation exactly across integer and decimal spellings, or narrow the documented guarantee and add a regression test for the intended behavior.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 29, 2026 07:47 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    Copilot review overview

    🟡 Changes recommended

    Moderate issues remain with near-int64 numeric-format invariance and Raw-vs-Object precision coverage.

    Review effort: Lite
    Findings: 2 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture>

    <details open>
    <summary><strong>Open (2)</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Normalization differs for equivalent int64 and decimal values](#discussion_r4130904241) · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Normalize negative zero to preserve numeric format invariance](#discussion_r4130830069)

  • </details>

    tmstff tmstff commented on code on Sep 29, 2026 07:53 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,8 +88,12 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    +			// Round-trip both payloads through k8s util/json and compare the
    +			// re-marshaled bytes. util/json decodes whole numbers to int64 (so
    +			// integers beyond float64's 2^53 range stay distinguishable) and
    +			// re-marshaling canonicalizes the rest: map keys are sorted (so
    +			// key-ordering differences don't matter) and equal numbers render
    +			// identically (3 == 3.0, 1e6 == 1000000, int64 == whole float64).

    that's acceptable.

    tmstff tmstff commented on code on Sep 29, 2026 07:53 UTC
    Code Review
    internal/controllerutils/needs_update.go:1
    @@ -88,8 +88,12 @@ var needsUpdateEqualities = func() conversion.Equalities {
     			if bytes.Equal(aBytes, bBytes) {
     				return true
     			}
    -			// Normalize both to canonical JSON (sorted keys) so that
    -			// key-ordering differences don't produce false positives.
    +			// Round-trip both payloads through k8s util/json and compare the
    +			// re-marshaled bytes. util/json decodes whole numbers to int64 (so
    +			// integers beyond float64's 2^53 range stay distinguishable) and
    +			// re-marshaling canonicalizes the rest: map keys are sorted (so
    +			// key-ordering differences don't matter) and equal numbers render
    +			// identically (3 == 3.0, 1e6 == 1000000, int64 == whole float64).

    that's acceptable.

    openshift-merge-bot[bot] openshift-merge-bot[bot] commented on Sep 29, 2026 08:13 UTC
    Bot

    Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
    /test e2e-parallel

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 29, 2026 12:22 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    Copilot review overview

    🟢 Approval recommended

    No unresolved review issues were identified.

    Review effort: Lite
    Findings: None

    <details>
    <summary><strong>Resolved since last review (2)</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Normalization differs for equivalent int64 and decimal values](#discussion_r4130904241)

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Normalize negative zero to preserve numeric format invariance](#discussion_r4130830069)

  • </details>

    openshift-merge-bot[bot] openshift-merge-bot[bot] commented on Sep 29, 2026 12:48 UTC
    Bot

    Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
    /test e2e-parallel

    adalrsjr1 adalrsjr1 commented on Sep 29, 2026 14:20 UTC
    Contributor

    /lgtm

    tmstff tmstff commented on Sep 30, 2026 09:24 UTC
    Author

    /retest

    openshift-ci[bot] openshift-ci[bot] commented on Sep 30, 2026 10:22 UTC
    Bot

    @tmstff: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

    Test name | Commit | Details | Required | Rerun command
    --- | --- | --- | --- | ---
    ci/prow/e2e-parallel | 6e66d4c793650a413acda3f74dda6a03700e788a | link | true | /test e2e-parallel

    Full PR test history. Your PR dashboard.

    <details>

    Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.
    </details>
    <!-- test report -->

    geoberle geoberle commented on Oct 01, 2026 08:21 UTC
    Contributor

    /approve

    miguelsorianod miguelsorianod commented on Oct 01, 2026 08:28 UTC
    Contributor

    Do we know if this could impact existing data being serialized/deserialized somehow, specially considering we have pre-existing resources?

    geoberle geoberle commented on Oct 01, 2026 08:29 UTC
    Contributor

    /hold for Miguels concern

    tmstff tmstff commented on Oct 01, 2026 08:37 UTC
    Author

    Do we know if this could impact existing data being serialized/deserialized somehow, specially considering we have pre-existing resources?

    NeedsUpdate is used in reconciliation loops to check if a resource already has the desired state. The result of serialization / deserialization in NeedsUpate is not persisted. That means that the only impact can be on the decision whether or not a resource is updated.

    Due to thorough code review and unit testing it becomes clear, that the only change in behavior is that for really large numbers (> 2^53 and < 2^63) differences between numbers can now be reliably distinguished.

    That was not the case before, because these kind of large numbers were converted to float64, resulting in precision loss.

    In short: no negative side effect expected.

    miguelsorianod miguelsorianod commented on Oct 01, 2026 09:07 UTC
    Contributor

    As a side question, non blocking for the PR, do we know if json v2 has changed the behavior around it?

    > Do we know if this could impact existing data being serialized/deserialized somehow, specially considering we have pre-existing resources?

    > NeedsUpdate is used in reconciliation loops to check if a resource already has the desired state. The result of serialization / deserialization in NeedsUpate is not persisted. That means that the only impact can be on the decision whether or not a resource is updated.

    > Due to thorough code review and unit testing it becomes clear, that the only change in behavior is that for really large numbers (> 2^53 and < 2^63) differences between numbers can now be reliably distinguished.

    > That was not the case before, because these kind of large numbers were converted to float64, resulting in precision loss.

    > In short: no negative side effect expected.

    I was discussing this with @geoberle and we noticed that the Cosmos serialization/deserialization itself also depends on encoding/json currently. This means that we are also getting potentially truncated results when deserializing. I think this would probably need fixing at that layer too. Otherwise when unmarshaling from Cosmos we would get the truncated value.

    tmstff tmstff commented on Oct 01, 2026 09:29 UTC
    Author

    @geoberle @miguelsorianod yes, you are right! This solution will not help in this case, and might even trigger a hot loop. Putting it on draft for now and might revisit it later. Thanks for your input! :-)

    tmstff tmstff commented on Oct 01, 2026 09:30 UTC
    Author

    As a side question, non blocking for the PR, do we know if json v2 has changed the behavior around it?

    I don't know - but I will check it out!

    openshift-ci[bot] openshift-ci[bot] commented on Oct 05, 2026 06:39 UTC
    Bot

    New changes are detected. LGTM label has been removed.

    openshift-ci[bot] openshift-ci[bot] commented on Oct 05, 2026 06:39 UTC
    Bot

    [APPROVALNOTIFIER] This PR is APPROVED

    This pull-request has been approved by: <a href="https://github.com/Azure/ARO-HCP/pull/7071#issuecomment-5892183844" title="LGTM">adalrsjr1</a>, <a href="https://github.com/Azure/ARO-HCP/pull/7071#issuecomment-5927593630" title="Approved">geoberle</a>, <a href="https://github.com/Azure/ARO-HCP/pull/7071#" title="Author self-approved">tmstff</a>

    The full list of commands accepted by this bot can be found here.

    The pull request process is described here

    <details >
    Needs approval from an approver in each of these files:

  • ~~backend/OWNERS~~ [geoberle]

  • ~~internal/OWNERS~~ [geoberle]

  • ~~kube-applier/OWNERS~~ [geoberle]
  • Approvers can indicate their approval by writing /approve in a comment
    Approvers can cancel approval by writing /approve cancel in a comment
    </details>
    <!-- META={"approvers":[]} -->

    Copilot Copilot commented on code on Oct 05, 2026 06:44 UTC
    Code Review
    internal/database/cosmosstorage/cosmosstorageutils/crud_helpers.go:1
    @@ -16,14 +16,14 @@ package cosmosstorageutils
     
     import (
     	"context"
    -	"encoding/json"
     	"errors"
     	"fmt"
     	"strings"
     	"time"
     
     	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
    +	"k8s.io/apimachinery/pkg/util/json"

    This import change also affects softDeleteByCosmosID, which unmarshals GenericDocument[map[string]interface{}] and then reads cosmosMetadata.instanceVersion with unstructured.NestedFloat64 at line 463. util/json preserves that JSON integer as int64, so the lookup errors, current remains 1, and every soft-delete of a document with version >1 writes version 2 instead of incrementing the existing value. Handle both integer types (or keep the generic soft-delete decode on the standard JSON path) and add a regression test with an existing version such as 7.

    Copilot Copilot commented on code on Oct 05, 2026 06:44 UTC
    Code Review
    backend/pkg/kubeapplierhelpers/desire_helpers.go:1
    @@ -16,10 +16,11 @@ package kubeapplierhelpers
     
     import (
     	"context"
    -	"encoding/json"
     	"fmt"
     	"reflect"
     
    +	"k8s.io/apimachinery/pkg/util/json"

    This import changes jsonBytesEqual below from decoding every JSON number as float64 to decoding integral literals as int64, but that function still compares the decoded values with reflect.DeepEqual. Consequently, equivalent payloads such as {"n":3} and {"n":3.0} now compare unequal and EnsureApplyDesire performs a needless replacement; unlike NeedsUpdate, this path does not re-marshal to normalize numeric spellings. Canonicalize the decoded values before comparison (or otherwise retain the previous numeric-format invariance) and add a regression test.

    Copilot Copilot commented on code on Oct 05, 2026 06:44 UTC
    Code Review
    internal/database/cosmosstorage/cosmosstorageutils/crud_helpers.go:1
    @@ -16,14 +16,14 @@ package cosmosstorageutils
     
     import (
     	"context"
    -	"encoding/json"
     	"errors"
     	"fmt"
     	"strings"
     	"time"
     
     	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
    +	"k8s.io/apimachinery/pkg/util/json"

    The repository guidance requires regenerating docs/cosmos-data-flow.md for changes to internal/database CRUD/precondition logic and controller/informer implementations (CLAUDE.md:262-268). This PR changes shared CRUD serialization/deserialization behavior, but the generated data-flow documentation is not included; please regenerate and commit it, or document why this path is intentionally excluded.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Oct 05, 2026 06:44 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    Copilot review overview

    🟡 Changes recommended

    Unresolved critical and moderate findings remain, along with the required generated documentation update.

    Review effort: Lite
    Findings: 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> · 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> · 1 <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.png" alt="Low severity" width="62" height="18" align="texttop"></picture>

    <details open>
    <summary><strong>Open (3)</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> [Prevent soft-delete version reset from integer metadata decoding](#discussion_r4181351186) · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Preserve numeric-format invariance in JSON equality comparisons](#discussion_r4181351246) · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.png" alt="Low severity" width="62" height="18" align="texttop"></picture> [Regenerate missing cosmos data-flow documentation](#discussion_r4181351267) · New

  • </details>

    openshift-ci[bot] openshift-ci[bot] commented on Oct 07, 2026 11:46 UTC
    Bot

    PR needs rebase.

    <details>

    Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.
    </details>

    Reviewers
    Assignees
    tmstff tmstff
    Labels
    risk: low confidence: 81.8% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 96% (HIGH) · Higher = larger blast radius
    96%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 81.8% · Lower = rushed or shallow review
    81.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.4% · Safe to merge
    17.4%
    Repository