Skip to content

dashboard: guard stability ratio when every observation is UNKNOWN#247

Merged
Zac-HD merged 1 commit intoZac-HD:masterfrom
SAY-5:fix/stability-zero-division
Apr 18, 2026
Merged

dashboard: guard stability ratio when every observation is UNKNOWN#247
Zac-HD merged 1 commit intoZac-HD:masterfrom
SAY-5:fix/stability-zero-division

Conversation

@SAY-5
Copy link
Copy Markdown
Contributor

@SAY-5 SAY-5 commented Apr 18, 2026

Problem

Test.stability only treats the "no rolling observations" case specially:

@property
def stability(self) -> float | None:
    if not self.rolling_observations:
        return None

    count_stable   = sum(o.stability is Stability.STABLE   for o in self.rolling_observations)
    count_unstable = sum(o.stability is Stability.UNSTABLE for o in self.rolling_observations)

    return count_stable / (count_stable + count_unstable)

If every rolling observation records Stability.UNKNOWN (the third
variant) — which happens routinely while a test is still being
collected — both counts are 0 and the division raises
ZeroDivisionError. The stack in #245 has it bubbling up through
websocket.send_tests, so every subsequent poll re-triggers the
exception and the dashboard websocket stays broken.

Fix

Compute the denominator explicitly, return None when it is 0, and
keep the existing ratio otherwise.

- return count_stable / (count_stable + count_unstable)
+ total = count_stable + count_unstable
+ if total == 0:
+     return None
+ return count_stable / total

No behaviour change for any test that has at least one stable or
unstable observation — they continue to return the same float as
before.

Fixes #245

Test.stability returns None only when rolling_observations is empty, but
the ratio is still count_stable / (count_stable + count_unstable). If
every observation is UNKNOWN (the third Stability variant), both counts
are 0 and the division raises ZeroDivisionError. The dashboard websocket
caller then tears down with every poll, leaving the UI unresponsive
(Zac-HD#245).

Compute the denominator explicitly, return None when it is 0, and keep
the existing ratio otherwise. No behaviour change for any call where at
least one observation reports a stable or unstable verdict.

Fixes Zac-HD#245

Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
Copy link
Copy Markdown
Owner

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

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

Thanks!

@Zac-HD Zac-HD merged commit 0779b02 into Zac-HD:master Apr 18, 2026
13 checks passed
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.

ZeroDivisionError in dashboard/test.py

2 participants