Skip to content

Fix numerical instability in tick generation (division by zero / NaN propagation) - #7

Open
samanthataylor3 wants to merge 1 commit into
masterfrom
devin/1782231922-fix-tick-numerical-instability
Open

Fix numerical instability in tick generation (division by zero / NaN propagation)#7
samanthataylor3 wants to merge 1 commit into
masterfrom
devin/1782231922-fix-tick-numerical-instability

Conversation

@samanthataylor3

@samanthataylor3 samanthataylor3 commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Closes #3

Describe your changes:

Two defects in src/plugins/plot/tickUtils.js allow non-finite values (Infinity, NaN) to propagate into plot rendering, corrupting tick marks or causing infinite loops.

Defect 1 — tickStep() / timeTickStep() division by zero:

Math.abs(stop - start) / Math.max(0, count)
//                                ^ allows count=0 → Infinity

Changed Math.max(0, count)Math.max(1, count) in both functions to guarantee a positive divisor.

Defect 2 — getLogTicks() passes non-positive count to ticks():

ticks(..., secondaryTickCount - 2)
// when secondaryTickCount ≤ 2  →  count ≤ 0  →  triggers Defect 1

This is hit in practice: MctTicks.vue calls getLogTicks(…, SECONDARY_TICK_NUMBER) where SECONDARY_TICK_NUMBER = 2, so secondaryTickCount - 2 = 0.

Clamped to Math.max(1, secondaryTickCount - 2) and added an early-return guard in ticks() itself for defense-in-depth.

All 4 locations fixed in one file:

Location Fix
tickStep() L23 Math.max(0, count)Math.max(1, count)
timeTickStep() L41 same
getLogTicks() L223 secondaryTickCount - 2Math.max(1, secondaryTickCount - 2)
ticks() L237 early return [] when count < 1

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Is this a notable change that will require a special callout in the release notes? For example, will this break compatibility with existing APIs or projects that consume these plugins?

Author Checklist

  • Changes address original issue?
  • Tests included and/or updated with changes?
  • Has this been smoke tested?
  • Have you associated this PR with a type: label? Note: this is not necessarily the same as the original issue.
  • Have you associated a milestone with this PR? Note: leave blank if unsure.
  • Testing instructions included in associated issue OR is this a dependency/testcase change?

Reviewer Checklist

  • Changes appear to address issue?
  • Reviewer has tested changes by following the provided instructions?
  • Changes appear not to be breaking changes?
  • Appropriate automated tests included?
  • Code style and in-line documentation are appropriate?

Link to Devin session: https://app.devin.ai/sessions/dcf6ca69fe8f4bd88047d072b3daeb19
Requested by: @samanthataylor3


Devin Review

Status Commit
⚪ Not started

Run Devin Review

💡 Connect your GitHub account to enable automatic code reviews.

Open in Devin Review (Staging)

Guard tickStep() and timeTickStep() against division by zero when count <= 0
by changing Math.max(0, count) to Math.max(1, count).

Clamp secondary tick count in getLogTicks() to at least 1 to prevent passing
zero or negative count to ticks() when secondaryTickCount <= 2.

Add early return in ticks() for non-positive count values.

Closes #3

Co-Authored-By: Samantha Taylor <samantha.taylor@cognition.ai>
@samanthataylor3 samanthataylor3 self-assigned this Jun 23, 2026
@devin-ai-integration

Copy link
Copy Markdown
Original prompt from Samantha

Can you look at the issues in @COG-GTM/openmct, choose the ticket that is most straightforward to implement, and make the changes and create a PR?

@devin-ai-integration

Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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.

Numerical Instability in Tick Generation

1 participant