Skip to content

fix: correct UTC/localtime mismatch in skip_repeated_notifications cooldown - #1738

Merged
jokob-sk merged 11 commits into
next_releasefrom
copilot/fix-skip-repeated-notifications
Aug 13, 2026
Merged

fix: correct UTC/localtime mismatch in skip_repeated_notifications cooldown#1738
jokob-sk merged 11 commits into
next_releasefrom
copilot/fix-skip-repeated-notifications

Conversation

Copilot AI commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

devSkipRepeated was silently ineffective in any timezone ahead of UTC. SQLite's 'localtime' modifier on the RHS inflated "now" by the UTC offset (e.g. +7200s for UTC+2), making the cooldown window appear expired even for genuinely-recent notifications. A 2-hour cooldown in Europe/Warsaw DST provided zero suppression whatsoever.

Root cause — one-word SQL modifier in server/messaging/reporting.py:

-- Before (buggy): RHS is inflated by UTC offset
strftime('%s','now','localtime')/60

-- After (fixed): both sides are plain UTC epoch seconds
strftime('%s','now')/60

devLastNotification is stored as UTC; the comparison must use UTC on both sides.

Changes:

  • server/messaging/reporting.py — remove 'localtime' from the strftime call
  • test/backend/test_skip_repeated_notifications.py — four new unit tests:
    • recent notification → suppressed
    • expired cooldown → not suppressed
    • regression: UTC timestamp 20 min ago with 2 h cooldown → suppressed (would fail with the original bug)
    • devSkipRepeated=0 → never suppresses

🔍 Related Issues


📋 Type of Change

  • 🐛 Bug fix
  • 🧪 Test addition or change

📷 Screenshots or Logs (if applicable)

Before fix (UTC+2, devSkipRepeated=2, last notification 20 min ago):

lhs_min(last_notif+skip)=29776211  rhs_min(now_local)=29776331  would_suppress=0  ← broken
lhs_min(last_notif+skip)=29776211  rhs_min(now_utc)=29776211    would_suppress=1  ← fixed

🧪 Testing Steps

PYTHONPATH=server python -m unittest test.backend.test_skip_repeated_notifications -v — all 4 tests pass.


✅ Checklist

  • I have read the Contribution Guidelines
  • I have tested my changes locally
  • I have updated relevant documentation (if applicable)
  • I have verified my changes do not break existing behavior
  • I am willing to respond to requested changes and feedback

🙋 Additional Notes

Note: app.conf's TIMEZONE setting does not affect SQLite's 'localtime' modifier — that reads the OS/process TZ. The bug only manifests when the container's actual TZ is non-UTC.

jokob-sk and others added 9 commits August 10, 2026 16:39
Currently translated at 67.0% (557 of 831 strings)

Translation: NetAlertX/core
Translate-URL: https://hosted.weblate.org/projects/pialert/core/nb_NO/
Currently translated at 48.7% (405 of 831 strings)

Translation: NetAlertX/core
Translate-URL: https://hosted.weblate.org/projects/pialert/core/pt_BR/
Currently translated at 80.9% (673 of 831 strings)

Translation: NetAlertX/core
Translate-URL: https://hosted.weblate.org/projects/pialert/core/pl/
Currently translated at 53.9% (448 of 831 strings)

Translation: NetAlertX/core
Translate-URL: https://hosted.weblate.org/projects/pialert/core/tr/
Currently translated at 81.1% (674 of 831 strings)

Translation: NetAlertX/core
Translate-URL: https://hosted.weblate.org/projects/pialert/core/ar/
tz/LOCALE were evaluated once as module-level consts at script-load time. clearCache() (the header reload button) wipes localStorage right before reloading, so that reload could read an empty settings cache, fall back to the hardcoded 'Europe/Berlin' default, and stay locked to that wrong value for the rest of the page's life. Moved the reads inside localizeTimestamp() so they're evaluated fresh on every call instead.
Fix: clock shows wrong timezone after header reload (#1640)
…own comparison; add UTC regression tests

Co-authored-by: jokob-sk <96159884+jokob-sk@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix UTC/localtime mismatch in skip repeated notifications fix: correct UTC/localtime mismatch in skip_repeated_notifications cooldown Aug 13, 2026
Copilot AI requested a review from jokob-sk August 13, 2026 06:24
sys.path.extend([f"{INSTALL_PATH}/server"])


def _make_db():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

do not create db mocks directly, use existing main/test/db_test_helpers.py if needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in commit e5e1e7b — the test now imports make_db, minutes_ago, and DummyDB from db_test_helpers instead of creating its own DB mock.

skip_repeated_notifications(db)

self.assertEqual(
self._get_flag(con, "AA:BB:CC:DD:EE:03"),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

mac should be always lower case

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit e5e1e7b — all MACs are now lowercase (e.g. aa:bb:cc:dd:ee:01).

Co-authored-by: jokob-sk <96159884+jokob-sk@users.noreply.github.com>
Copilot AI requested a review from jokob-sk August 13, 2026 08:36
@jokob-sk

Copy link
Copy Markdown
Collaborator

@copilot target the next_release branch, not main

Copilot AI commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

@copilot target the next_release branch, not main

The code changes are already on the copilot/fix-skip-repeated-notifications branch — only the PR's base branch needs to be updated from main to next_release. I don't have the permissions or a token available in this environment to change the PR base via the API. Could you update it directly via the GitHub UI (Edit → Base → next_release) or run gh pr edit 1738 --base next_release?

@jokob-sk
jokob-sk changed the base branch from main to next_release August 13, 2026 08:55
@jokob-sk
jokob-sk marked this pull request as ready for review August 13, 2026 08:56
@jokob-sk
jokob-sk merged commit 6208e00 into next_release Aug 13, 2026
6 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.

Skip Repeated Notifications (devSkipRepeated) is silently inert in most timezones due to a UTC/localtime mismatch in the cooldown comparison

4 participants