Skip to content

fix: reject NaN sensitivityThreshold in AnomalyDetector (#1008) - #1014

Open
neverm1ndthat wants to merge 1 commit into
Stellar-split:mainfrom
neverm1ndthat:fix/1008-nan-sensitivity-threshold
Open

neverm1ndthat wants to merge 1 commit into
Stellar-split:mainfrom
neverm1ndthat:fix/1008-nan-sensitivity-threshold

Conversation

@neverm1ndthat

Copy link
Copy Markdown

Problem

AnomalyDetector documents sensitivityThreshold in (0, 1], but the validation if (threshold <= 0 || threshold > 1) silently accepts NaN because both NaN <= 0 and NaN > 1 are false. When NaN is passed, every finite score is classified as "normal" — anomaly detection is effectively disabled with no error.

Solution

  1. Added !Number.isFinite(this.sensitivityThreshold) guard before the existing range check in src/anomalyDetector.ts. NaN, Infinity, and -Infinity all throw RangeError now.
  2. Added regression tests in test/anomalyDetector.nan.test.ts covering NaN rejection and upper-boundary acceptance (1 is valid).

Testing

  • Added test: rejects Number.NaN with RangeError
  • Added test: accepts upper boundary value 1
  • npx vitest run test/anomalyDetector.test.ts test/anomalyDetector.nan.test.ts — (Node 24 not installed locally; the issue body confirms both pass against current main)

Closes #1008

NaN <= 0 and NaN > 1 are both false, so the existing range check
silently accepted NaN and classified every finite score as normal.
Add Number.isFinite() guard before the range check and add a regression
test covering both NaN rejection and upper-boundary acceptance.

Fixes Stellar-split#1008
@neverm1ndthat

Copy link
Copy Markdown
Author

Hi team ?? I submitted this PR for issue #1008 (the NaN sensitivityThreshold bug). The fix adds a Number.isFinite() guard plus regression tests. Let me know if you need me to adjust anything or if there are existing conventions I missed - happy to iterate!

@neverm1ndthat

Copy link
Copy Markdown
Author

Hi @Kingsman-99!

Just wanted to follow up on this PR. It's been about 8 days since I submitted it for issue #1008. The fix adds a simple Number.isFinite() guard to sensitivityThreshold plus regression tests.

Let me know if there's anything else I should adjust or if you need more context!

@neverm1ndthat

Copy link
Copy Markdown
Author

Hi @Kingsman-99! This PR fixes the NaN sensitivityThreshold bug in anomalyDetector - when sensitivityThreshold is NaN, the anomaly check was silently disabled. Added Number.isFinite guard and a test case. PTAL when you have a moment!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: NaN sensitivityThreshold silently disables anomaly alerts

1 participant