Skip to content

Fix stop-loss count and percent check - #195

Draft
Areson wants to merge 1 commit into
Areson/level-collector-stopfrom
Areson/stop-loss-count
Draft

Areson wants to merge 1 commit into
Areson/level-collector-stopfrom
Areson/stop-loss-count

Conversation

@Areson

@Areson Areson commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #191.

Stop-loss in Loader.Load miscounts and its percent form never triggers.

  • "Now" was len(diff.removed), the number of removed monitors, not the number left. A small removal could trigger stop-loss (removing 2 of 10 with limit 3 counted as a loss of 8), and removing every monitor never did.
  • blip.StopLoss returns the percent as a whole number (50 for 50%), but the check compared it to a 0 to 1 fraction, so a percent stop-loss could never trigger. The error message also printed the fraction as a percent.

Stop-loss now counts the net drop: monitors loaded before minus monitors loaded after (before − removed + new). New monitors offset removed ones, and changed monitors don't count. This matches the existing "before/now" message and the "big drop in the number" intent, and it allows a legitimate replacement such as renamed hosts. A drop equal to the limit is still allowed. The percent check compares lost*100 > limit*before so a drop exactly at the limit isn't pushed over by rounding. Only one of number or percent can be configured, so the two branches are now a switch.

Tests: TestLoaderStopLoss covers number and percent stop-loss below, at, and above the limit, with and without new monitors, plus full replacement and changed monitors. 10 of its 19 cases fail on the old code. TestLoaderUnloadedMonitorsHaveNoCounters got ErrStopLoss only because of the miscount, so it now removes 3 of 4 monitors (a net loss of 2 against limit 1).

Docs: explained the count in monitors/loading.md and config-file.md#stop-loss, and added an Unreleased note that a percent stop-loss now triggers.

🤖 Generated with Claude Code

@Areson
Areson force-pushed the Areson/level-collector-stop branch from 66c753e to 076b2b8 Compare October 26, 2026 18:27
@Areson
Areson force-pushed the Areson/stop-loss-count branch 2 times, most recently from 3c70a5b to 98af9d4 Compare October 26, 2026 19:37
@Areson
Areson force-pushed the Areson/level-collector-stop branch 2 times, most recently from 4e27986 to f386824 Compare October 26, 2026 20:17
@Areson
Areson force-pushed the Areson/stop-loss-count branch from 98af9d4 to 55030fb Compare October 26, 2026 20:17
@Areson
Areson force-pushed the Areson/level-collector-stop branch from f386824 to 1ecfa67 Compare October 26, 2026 20:39
@Areson
Areson force-pushed the Areson/stop-loss-count branch from 55030fb to 1a7153d Compare October 26, 2026 20:39
@Areson
Areson force-pushed the Areson/level-collector-stop branch from 1ecfa67 to 2aad61e Compare October 26, 2026 21:30
@Areson
Areson force-pushed the Areson/stop-loss-count branch from 1a7153d to d747dfc Compare October 26, 2026 21:30
@Areson
Areson force-pushed the Areson/level-collector-stop branch from 2aad61e to b033f87 Compare October 26, 2026 22:37
@Areson
Areson force-pushed the Areson/stop-loss-count branch from d747dfc to 1e480bb Compare October 26, 2026 22:37
Loader.Load used the number of removed monitors as the number left, and
compared a 0-1 loss fraction against the whole-number percent from
blip.StopLoss, so a percent stop-loss never triggered. Count the net drop
(before - removed + new; changed monitors don't count) and compare
lost*100 > limit*before for percent stop-loss.

TestLoaderUnloadedMonitorsHaveNoCounters relied on the miscount; it now
removes 3 of 4 monitors to get ErrStopLoss.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Areson
Areson force-pushed the Areson/level-collector-stop branch from b033f87 to 4125884 Compare October 27, 2026 00:13
@Areson
Areson force-pushed the Areson/stop-loss-count branch from 1e480bb to 2f972b5 Compare October 27, 2026 00:14

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.

1 participant