Skip to content

fix(3jane): dedupe threshold alerts via cached alerted value#316

Merged
spalen0 merged 2 commits into
mainfrom
fix/3jane-alert-dedup
Jul 10, 2026
Merged

fix(3jane): dedupe threshold alerts via cached alerted value#316
spalen0 merged 2 commits into
mainfrom
fix/3jane-alert-dedup

Conversation

@spalen0

@spalen0 spalen0 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

The 3Jane junior buffer, USD3 OC, and withdraw liquidity alerts fired on every run while the condition persisted, spamming Telegram. This applies the same cached-value pattern the other checks in this monitor use (debt cap, shutdown, pause):

  • On breach, send one alert and cache the value that triggered it.
  • Stay silent while the metric is at or above the cached value (still breached).
  • Re-alert only when the value drops below the cached value (condition worsened) — for OC this also covers the HIGH → CRITICAL escalation.
  • Recovering to/above the threshold clears the cache (-1 sentinel) so the next breach alerts again.

Implemented as one shared helper, should_alert_value_drop(cache_key, value, threshold), since all three metrics are lower-is-worse. The fully-covered OC branch (senior_at_risk <= 0) also clears the cache so a stale alerted value can't suppress a future breach.

Validation

  • uv run --extra dev pytest tests/test_3jane.py — 21 passed, including new tests for: same-value dedup, re-alert on further drop, re-arm after recovery, HIGH→CRITICAL escalation, and full-coverage re-arm.
  • ruff format / ruff check clean; mypy shows only pre-existing errors (untouched http_json, utils/).
  • Existing threshold tests now stub the cache with an in-memory dict so they don't touch the real sqlite store.

🤖 Generated with Claude Code

spalen0 and others added 2 commits July 10, 2026 20:24
Junior buffer, USD3 OC, and withdraw liquidity alerts fired on every run
while the condition persisted. Cache the value that triggered the alert
and stay silent until the metric drops below it; recovering above the
threshold clears the cache so the next breach alerts again.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ployed credit

Review follow-ups: should_alert_value_drop() no longer writes the breach
value, so a raised Telegram send retries the alert next run instead of
being suppressed by the dedupe cache (callers mark_alerted_value() after
send_alert returns). The deployed_credit <= 0 early-returns in the junior
buffer and OC checks now clear dedupe state, since an unwound book counts
as recovered.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@spalen0 spalen0 marked this pull request as ready for review July 10, 2026 20:38
@spalen0 spalen0 merged commit cee3bf0 into main Jul 10, 2026
3 checks passed
@spalen0 spalen0 deleted the fix/3jane-alert-dedup branch July 10, 2026 20:41
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