Skip to content

fix: Propagate NaN from CircularDoubleBuffer Max/Min - #2271

Merged
DaveSkender merged 1 commit into
mainfrom
claude/youthful-volta-e3duxh
Oct 2, 2026
Merged

DaveSkender merged 1 commit into
mainfrom
claude/youthful-volta-e3duxh

Conversation

@DaveSkender

@DaveSkender DaveSkender commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Summary

CircularDoubleBuffer.GetMax() / GetMin() seeded from physical slot 0 and compared with > / <. Because NaN comparisons are always false, a NaN was returned only when it sat in slot 0 (not necessarily the oldest element after wraparound) and was silently ignored in any other slot.

Semantics chosen: any NaN in the filled window → NaN, independent of ring position. This follows the NaN policy in src/AGENTS.md ("let NaN propagate"). It also matches the canonical Series behavior of the Stoch family (CalcStoch explicitly returns NaN for a NaN in the window, used by Stoch, WilliamsR, StochRsi, and Stc) and of FisherTransform and Chop (Math.Max / Math.Min propagate NaN). The implementation adds an early double.IsNaN return inside the existing scan and allocates nothing.

Series parity

No hub's output changes:

  • Bar-fed hubs (Stoch, WilliamsR, Smi, Chop, Donchian, Chandelier, Ichimoku, RollingPivots) take values from decimal bar fields, so the buffer can never hold NaN.
  • Chained hubs (StochRsi, Stc, FisherTransform) already skip NaN values before calling Add.

So the buffer never receives NaN in production today. This fix makes the utility correct for any future caller; it does not change current results.

Tests

RollingWindow.Tests.cs adds tests for NaN at the oldest, middle, and newest positions, both before and after wraparound, plus a partial window and a NaN that has been evicted (results recover). On the old code, 5 of the 7 NaN-in-window tests fail; the 2 that pass are the cases where the NaN sits in physical slot 0.

Performance

Stream benchmarks were run for all 11 hubs that use the buffer, comparing old and new code on the same machine.

  • 10 hubs: results are within run-to-run noise. The error bars are about 1 ms against means of about 2 ms.
  • StochRsiHub: it looked about 2x slower in the first comparison. An alternating re-run showed this was noise: old 2.34 / 2.50 ms, new 2.37 / 2.36 ms.

perf.sh spot flags most of these hubs against the committed baselines. Those baselines come from a different machine, so the flags don't reflect this change.

Quality gates

  • dotnet build (-warnAsError): 0 warnings, 0 errors
  • Unit tests: 2350 passed
  • dotnet format --verify-no-changes: clean
  • audit-streamhub.sh: clean

🤖 Generated with Claude Code

https://claude.ai/code/session_0112YAMNCuDSg5D2UyndEgqi

GetMax/GetMin seeded from physical slot 0 and compared with > / <, so a
NaN was returned only when it sat in slot 0 and was ignored anywhere
else. They now return NaN when any value in the filled window is NaN,
independent of ring position, with no allocation.

No hub output changes: bar-fed hubs receive decimal values, and the
chained hubs (StochRsi, Stc, FisherTransform) skip NaN before Add.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0112YAMNCuDSg5D2UyndEgqi
@codacy-production

codacy-production Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 4 complexity · 0 duplication

Metric Results
Complexity 4
Duplication 0

View in Codacy

🟢 Coverage 100.00% diff coverage · -0.01% coverage variation

Metric Results
Coverage variation ✅ -0.01% coverage variation (-1.00%)
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (e92f641) 19599 18911 96.49%
Head commit (aedc30b) 19649 (+50) 18957 (+46) 96.48% (-0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#2271) 14 14 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@DaveSkender
DaveSkender marked this pull request as ready for review October 2, 2026 17:13
@DaveSkender
DaveSkender requested a review from a team October 2, 2026 17:13
@facioquoqa

facioquoqa Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

:neckbeard: FaciōQuōqa Mage code review was completed with comments.

  • Trigger re-review

@DaveSkender

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@facioquoqa facioquoqa Bot 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.

Review summary — no actionable findings.

Scope: Tier 2 — Developer, Tester, Inspector, plus an independent pass, over both changed files; CI is green.

  • The scan in GetMax/GetMin is correct: valid entries always occupy slots 0.._fill-1, so any NaN in the window (partial, full, or wrapped) now returns NaN, and empty-buffer, ±0, and ±Infinity behavior is unchanged.
  • The PR's no-parity-change claim holds: StochRsi, Stc, and FisherTransform hubs skip NaN before Add, and the bar-fed hubs read decimal fields.
  • The new tests' slot/window comments are accurate. The two cases that pass on old code (NaN in slot 0) and the eviction test are legitimate regression guards.

Reviewed by the FaciōQuō swarm

@coderabbitai

coderabbitai Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (12)
src/Common/AGENTS.md — configured
AGENTS.md — configured
tests/AGENTS.md — configured
src/AGENTS.md — configured
.agents/skills/indicator-stream/SKILL.md — configured
.agents/skills/code-completion/SKILL.md — configured
.agents/skills/testing-standards/SKILL.md — configured
.agents/skills/indicator-stream/references/provider-selection.md — configured
.agents/skills/testing-standards/references/patterns.md — configured
.agents/skills/indicator-stream/references/performance-patterns.md — configured
.agents/skills/indicator-buffer/references/interface-selection.md — configured
.agents/skills/indicator-series/references/decision-tree.md — configured

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Advanced

Run ID: 0df2c096-339d-4f8b-aa52-73901152d71c

📥 Commits

Reviewing files that changed from the base of the PR and between e92f641 and aedc30b.

📒 Files selected for processing (2)
  • src/Common/StreamHub/CircularDoubleBuffer.cs
  • tests/Library/Common/StreamHub/RollingWindow.Tests.cs

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


📝 Walkthrough

Walkthrough

GetMax and GetMin now return double.NaN when the buffer is empty or a value in the filled window is NaN. New tests cover NaN positions in partial and full windows, wraparound, and the return of numeric extrema after a NaN is evicted.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to aedc3

The extrema change is ready to merge after normal checks; no actionable risk remains in the supplied review evidence.

✨ Finishing Touches
✨ Simplify code
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@DaveSkender
DaveSkender merged commit 3898cf2 into main Oct 2, 2026
@DaveSkender
DaveSkender deleted the claude/youthful-volta-e3duxh branch October 2, 2026 23:56
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants