Skip to content

[SDK] Fix delta double sums retaining values from earlier intervals - #7963

Merged
martincostello merged 5 commits into
open-telemetry:mainfrom
Kielek:codex/fix-ant-2026-85ypfow4
Oct 16, 2026
Merged

martincostello merged 5 commits into
open-telemetry:mainfrom
Kielek:codex/fix-ant-2026-85ypfow4

Conversation

@Kielek

@Kielek Kielek commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

This fix addresses a ANT-2026-85YPFOW4 finding from Anthropic's OSS Scanner.
Project enrollment: anthropics/oss-scanner#117.

Changes

Delta Counter<double> and Counter<float> exports currently subtract two
process-lifetime sums. After one NaN, infinity, or large finite measurement,
later intervals can export NaN, zero, or an inaccurate sum even when all new
measurements are ordinary. Reset the synchronous sum atomically at each delta
snapshot so each interval contains only its own measurements.

Use bitwise equality for pending-data checks on double sums and gauges so an
unchanged NaN does not keep an idle point active or prevent reclamation.
Observable counters retain their cumulative-input subtraction semantics.

Add 12 regression cases covering both numeric counter types, tagged and untagged
series, finite precision loss, and synchronous/observable counter/gauge
reclamation. All 12 fail on the unchanged baseline and pass after the fix on
net10.0, net9.0, net8.0, and net472. The full affected SDK Release test suite
passes all four frameworks: 6,458 passed, eight existing skips, zero failures.

Standalone solution-build and relative-path formatting results are recorded in
the local handoff. Source sanity passes on a canonical LF source snapshot with
the changes overlaid.

No public API changes.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, successful build/tests, etc.)
  • Tests added/updated
  • CHANGELOG.md file(s) updated for non-trivial changes
  • Changes in public API reviewed (if applicable)
  • AI usage disclosure:
    • No AI used
    • AI-assisted
    • Bulk AI-generated
  • I have the experience and knowledge necessary to understand, review, and validate all content in this PR1

Note

This PR description was generated with OpenAI Codex.

Footnotes

  1. Yes, I can answer maintainer questions about the content of this PR without using AI. ↩

Reset synchronous double sums atomically at each delta snapshot so a large
or non-finite measurement cannot corrupt later intervals. Use bitwise double
comparisons when checking for pending data so idle NaN points can be reclaimed.

Add regressions for double and float counters, tagged and untagged series,
and synchronous and observable counter/gauge reclaim.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-85YPFOW4.
@github-actions github-actions Bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label Oct 16, 2026
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-10-16 15:25 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@martincostello
martincostello requested a balanced review from Copilot October 16, 2026 12:20
Merge upstream main at 953708d
before completing the changelog for PR open-telemetry#7963.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-85YPFOW4.
Complete the SDK changelog after merging upstream main, with the real fix
PR link open-telemetry#7963.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-85YPFOW4.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The behavioral fixes still need the repository-required SDK changelog entry.

1 open finding
What changed in this PR

Fixes SDK delta floating-point counters so earlier measurements do not contaminate later intervals.

Changes:

  • Atomically resets synchronous delta sums while preserving observable-counter subtraction.
  • Uses bitwise comparisons for pending-data and reclamation checks.
  • Adds 12 regression cases covering interval isolation and idle-point reclamation.
File Description
test/​OpenTelemetry.Tests/​Metrics/​DoubleDeltaAggregationTests.cs Adds counter and reclamation regressions.
src/​OpenTelemetry/​Metrics/​MetricPoint/​MetricPoint.cs Resets delta sums and corrects pending-data comparisons.
src/​OpenTelemetry/​Internal/​InterlockedHelper.cs Exposes the existing bitwise double comparison internally.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.37%. Comparing base (1777f8d) to head (f8c94cf).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #7963   +/-   ##
=======================================
  Coverage   92.37%   92.37%           
=======================================
  Files         364      364           
  Lines       21090    21093    +3     
=======================================
+ Hits        19482    19485    +3     
  Misses       1608     1608           
Flag Coverage Δ
unittests-Project-Experimental 92.48% <100.00%> (-0.02%) ⬇️
unittests-Project-Stable 92.49% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/OpenTelemetry/Internal/InterlockedHelper.cs 100.00% <100.00%> (ø)
...c/OpenTelemetry/Metrics/MetricPoint/MetricPoint.cs 95.03% <100.00%> (+0.03%) ⬆️

@Kielek
Kielek marked this pull request as ready for review October 16, 2026 12:32
@Kielek
Kielek requested a review from a team as a code owner October 16, 2026 12:32
@martincostello martincostello changed the title [Sdk] Fix delta double sums retaining values from earlier intervals [SDK] Fix delta double sums retaining values from earlier intervals Oct 16, 2026
This was referenced Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants