Skip to content

Optional Pushover delivery for watched-node alerts - #2455

Merged
efiten merged 5 commits into
Kpa-clawbot:masterfrom
anieto:pushover
Nov 28, 2026
Merged

efiten merged 5 commits into
Kpa-clawbot:masterfrom
anieto:pushover

Conversation

@anieto

@anieto anieto commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds Pushover as an optional destination for watched-node alerts, next to email and the push relay from #2447. An admin enables it with a Pushover application token; each user then connects their own Pushover account from My account → Notifications and gets the same alerts as email in the Pushover app. CoreScope sends to Pushover directly; no relay is involved.

It plugs into the notifyDestination interface from #2447 (now merged). The changes are four commits:

  • eca5b21c store and server: the per-user destination behind the notifier interface
  • c12539c2 account page section, docs, OpenAPI and export test
  • 6992fe4a Connect Pushover through a Pushover subscription
  • 41bbfefd docs: stopping Pushover from the Pushover app

Setup (admin)

  1. Create an application on pushover.net.
  2. Set CORESCOPE_PUSHOVER_TOKEN in the server environment. The token never goes in config.json.
  3. Add a block to userManagement.notifications:
"pushover": { "maxPerMonth": 7500, "subscriptionCode": "YourApp-1oiwozgx5tg38a1" }

subscriptionCode is optional. It comes from a web-based subscription in the application's settings on pushover.net, whose base URL must be the analyzer's publicBaseUrl. Without it, users paste their user key instead of using Connect Pushover. CoreScope refuses to start with the block but without a valid token.

Behavior

  • Same alerts as email, separate switch. Pushover uses the events the user chose for notifications. Turning mail off, or a mail's unsubscribe link, doesn't stop Pushover, and the reverse.
  • One message per user per check. All of a user's changes in one evaluation go into one message (at most 1,024 characters): the instance's host name as the title, the same lines a mail would contain, and a link to the node or, for several changes, to the notification settings.
  • Queued in users.db. Messages are queued in the same transaction as the notification state change and sent by a worker every 5 seconds. Failures are retried with backoff (honoring Pushover's Retry-After) for up to an hour, then dropped. If Pushover rejects a user's key, Pushover is turned off for that user. Changing or removing the key, or turning Pushover off, drops that user's queued messages.
  • Instance cap. maxPerMonth (default 7,500) caps the messages sent in a rolling 30 days, test messages included, below Pushover's free tier of 10,000 per application per month. Messages queued after the cap is reached expire unsent.
  • Keys are checked. Every key is validated with Pushover's users/validate endpoint before it is saved. Key checks (saving a key, or the return from Connect Pushover) and Send test share a limit of 10 per hour per user. Each user has at most one Connect Pushover in progress; starting another replaces it.
  • Personal data. The account export includes the key. Deleting the account or the key removes it and the queued messages.

Connect Pushover

With subscriptionCode set, the account page shows Connect Pushover. It sends the browser to the pushover.net subscription page and saves the application-specific key Pushover returns.

  • The success URL carries a one-time token tied to the user who started, valid for 15 minutes. The return also needs that user's session. A crafted link can't attach someone else's Pushover account to yours (which would send your alerts to them). This is the check Pushover's subscription docs recommend.
  • A return with pushover_unsubscribed removes the saved key if it matches.
  • The account page reports the outcome (connected, cancelled, expired, sign in first, try later, failed, disconnected) and drops it from the address.
  • The return responses send Cache-Control: no-store and Referrer-Policy: no-referrer.

Changes

  • internal/users: users.db v12 with notification_pushover, notification_pushover_jobs and notification_pushover_sent. Triggers drop queued jobs when the key changes or Pushover is turned off. Jobs are queued from ApplyNotifyChanges through NotifyOutbox.PushoverMessages.
  • cmd/server:
    • pushoverDestination implements notifyDestination, alongside email and the push relay.
    • New routes: PUT/DELETE /api/account/notifications/pushover, POST .../pushover/test, and, with a subscription code, POST .../pushover/subscribe, GET .../pushover/subscribed/{token} and GET .../pushover/subscribe-failed.
    • GET /api/account/notifications gains a pushover object while the instance offers Pushover.
    • The OpenAPI spec and account export are updated.
  • public/notifications.js: the Pushover part of the Notifications section.
  • docs/user-guide/accounts.md: setup and behavior.

No changes to the analyzer DB, the ingestor or the read/write separation: everything lives in users.db through internal/users.

Testing

  • make test: all modules pass. go test -race passes on the server notification, push, destination, export and OpenAPI tests.
  • New Go tests run against a fake Pushover server:
    • config resolution and the subscription code format;
    • message rendering and the 1,024-character fit;
    • delivery with email off;
    • retry, drop, and a rejected key turning Pushover off;
    • the monthly cap;
    • the account routes;
    • the full Connect Pushover round trip: wrong user, no session, a used or superseded token, an unknown key, unsubscribe and cancel.
  • Store tests in internal/users cover the key lifecycle, queueing only for active users, expiry, and send counting.
  • test-all.sh and eslint pass. tests/unit/test-notifications-ui.js has 20 tests, including Connect Pushover and the outcome messages.
  • Running on the MeshTexas analyzer since 2026-11-22. Connect Pushover was completed with a real Pushover account:

@anieto
anieto force-pushed the pushover branch 3 times, most recently from 13c7062 to 97cb9eb Compare November 23, 2026 23:48
With notifications.pushover.subscriptionCode set, the account page
offers Connect Pushover: CoreScope sends the browser to the
pushover.net subscription page and saves the key Pushover returns.
Pasting a user key stays as the fallback.

The return link carries a one-time token tied to the user who started,
valid for 15 minutes, and the return needs that user's session, so a
crafted link can't put another key on someone's account. A return with
pushover_unsubscribed removes the saved key. The account page reports
how the round trip went.
Unsubscribing in the Pushover app makes Pushover reject the key, and
CoreScope then turns Pushover off for that user. Say so, and how to
connect again.
@anieto
anieto marked this pull request as ready for review November 24, 2026 22:37
@efiten

efiten commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Review of 41bbfefd. The app token is read only from the environment, sent in the POST body, and never logged or returned. The normal API returns only the last four characters of the user key, and a test asserts it. Outbound calls have a 10 s timeout, no redirects and a 64 KiB body limit. Retry, backoff and Retry-After are handled, and a rejected key disables delivery. The feature is off unless both notifications.enabled and a pushover block are set. Schema v12 is additive, and all writes go through internal/users to users.db. The internal/users tests, the Pushover/notify tests in cmd/server and tests/unit/test-notifications-ui.js pass locally.

Two points before merge:

  1. No per-user limit, so one user can use up the instance cap (cmd/server/notify_pushover.go:242, :293). The only limit is maxPerMonth. Email has both perUserPerDay and maxMailsPerDay. At the default 5-minute interval one user can receive 288 messages a day, 8640 per 30 days, which is above the default cap of 7500. After that every user's messages expire unsent for the rest of the window. notification_pushover_sent (internal/users/schema.go:284) stores only sent_at, so adding a per-user count later needs another migration. Could user_id go into that table in v12 now, with a per-user 24 h limit and a test?

  2. The account export returns the full user key (cmd/server/account_export.go:245). This is documented, but it is the one API that returns the key, to any web session or device token, without a password prompt, while the export says it leaves out every token. I would export only keyHint, enabled and validatedAt: the user already has the key on pushover.net, and the key lets any Pushover application message them. Requiring currentPassword for the export would be the other option.

Smaller notes, none blocking:

  • The user key is stored in plain text, so it ends up in the daily users.db snapshots and the admin backup; observer MQTT passwords in the same file are encrypted. Either encrypt it or mention it in the backups section.
  • notify_pushover_handlers.go:134, :158: the one-time token is consumed before the rate-limit check, so a busy outcome forces a new connect.
  • notify_pushover.go:319: the cap is checked per batch of 25, so it can be passed by up to 24.
  • notify_pushover.go:372: a non-JSON 4xx (a proxy error page) drops the message on the first attempt.
  • public/notifications.js:304-305: the signin outcome is read after the signed-out early return.
  • openapi.go:137 omits subscribe?; notify_pushover_handlers.go:113 uses map[string]string where the file otherwise uses named structs.
  • config.example.json has no pushover block.
  • DuePushoverJobs runs a DELETE and a COUNT every 5 s even with an empty queue.
  • There is no Playwright test for the new account-page block.

Not checked: a live pushover.net round trip (the screenshot placeholder in the description is empty), go vet, -race, and Playwright.

- notification_pushover_sent gets user_id (in v12). A user's message is
  queued only while their sends in 24 hours plus their queued messages
  stay under notifications.perUserPerDay; the test endpoint answers 429
  past it. A deleted user's sends still count toward the instance cap.
- The account export carries keyHint (last 4 characters), not the key.
- dispatch sends at most the cap's remaining room, even within a batch.
  An empty queue costs one indexed SELECT: the cap is counted only when
  messages are due, and expired messages are pruned once a minute.
- A 4xx whose body isn't Pushover's JSON is retried like a 5xx and never
  turns a key off.
- Connect Pushover: the rate limit is checked before the one-time token is
  used, so a busy return can be retried with the same link. A signed-out
  return goes to the login page, which reports it.
- Named struct for the subscribe answer; openapi lists subscribe? and the
  new 429; config.example.json shows a pushover block (inactive under
  _pushover); the docs cover the limit, the export and the plain-text
  key in users.db backups.
@anieto

anieto commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Review feedback addressed (commit fa6339d2). Thanks for the thorough pass.

Before merge:

  1. Per-user limit. notification_pushover_sent now has user_id in v12 (ON DELETE SET NULL, so a deleted user's sends still count toward the instance cap), with an index on (user_id, sent_at). A user's message is queued only while their sends in the last 24 hours plus their unexpired queued messages stay under notifications.perUserPerDay, the same number as the mail limit, counted separately. The check is in the queue's INSERT … WHERE, so queued messages never exceed it. The test endpoint counts toward it and answers 429 past it. Tests: TestPushoverPerUserDailyLimit in internal/users (sent and queued both count, test messages count, the window rolls after 24 h, 0 means no limit, deleting a user keeps the cap count) and in cmd/server (stage → queue → dispatch, and the 429).
  2. Export. The export now carries keyHint (last four characters), enabled and validatedAt, like the API. The export test adds the full key to its list of secrets that must not appear. docs/api-spec.md is updated to match.

Smaller notes:

  • Plain-text key: documented rather than encrypted, under Pushover and in the Backups section. SecretBox only has a key when observerLogins is configured, so encrypting would make Pushover depend on that. Happy to change this if you'd rather require a key for it.
  • Token before rate limit: the limit is now checked first, so a busy return leaves the token unused and the same link works again within its 15 minutes. A malformed key also no longer uses it up. Tested in TestPushoverConnectRoundTrip.
  • Cap per batch: dispatch sends at most the remaining room (TestPushoverCapHoldsWithinABatch: room for 2, 4 due, 2 sent).
  • Non-JSON 4xx: marked Unparsed, retried with the usual backoff, and never treated as an invalid key. The fake server gained an HTML 400 mode for the test.
  • signin outcome: a signed-out return now redirects to #/account/login?pushover=signin, and the login view reports it (CSNotify.pushoverOutcome is exported for that, with tests).
  • OpenAPI and struct: subscribe? is listed; the subscribe answer is a named pushoverSubscribeJSON.
  • config.example.json: has the block under _pushover, with a comment to rename it. With a live pushover block, enabling notifications from the example would refuse to start without CORESCOPE_PUSHOVER_TOKEN.
  • Idle queue: an empty queue now costs one indexed SELECT per tick. The cap is counted only when something is due, and expired messages are pruned once a minute.
  • Playwright: not added. The account-page block is covered by tests/unit/test-notifications-ui.js. I can add a Playwright case if you want one.

Ran: gofmt and make vet are clean; make test passes on Linux; every suite in test-all.sh passes; npx eslint public/*.js reports no errors. The screenshot is still to come.

@efiten
efiten merged commit 1c5ec2f into Kpa-clawbot:master Nov 28, 2026
17 checks passed
zfouts added a commit to zfouts/CoreScope that referenced this pull request Nov 29, 2026
Brings in Kpa-clawbot#2457, Kpa-clawbot#2490, Kpa-clawbot#2488, Kpa-clawbot#2500 and Kpa-clawbot#2455. Conflicts were two
added lines on each side: the eslint globals (frameHex/frameSize and
NeighborRank) and the deploy.yml E2E suite list (the privacy-on suite
and test-neighbor-rank-e2e.js); both kept. The leak test now requests
Kpa-clawbot#2457's /api/nodes/neighbor-rank, which serves no positions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zfouts added a commit to zfouts/CoreScope that referenced this pull request Nov 29, 2026
… Pushover to Postgres

Brings in 37 master commits, including the push relay (Kpa-clawbot#2447), Pushover
(Kpa-clawbot#2455), plain SMTP (Kpa-clawbot#2466), neighbour rank (Kpa-clawbot#2457), the observers rebuild
fix (Kpa-clawbot#2445) and Kpa-clawbot#2486.

Conflicts: config.example.json, docs/api-spec.md and auth_service.go keep
both sides (as n30nex's merge notes say); dbschema's observers check keeps
the Postgres branch in front of Kpa-clawbot#2445's rowid-alias check; the
release-routing test keeps musl-test; CHANGELOG keeps only unreleased
entries; notify_service.go keeps master's destinations plus the cluster
lock on evaluation, and the email claim moves to notifyChanges.claim.

users.db schema: master's v11 (push relay) and v12 (Pushover) come first,
this branch's rate_limits becomes v13, and v14 adds push_relay_state,
push_relay_pending and notification_pushover_subscriptions.

Push relay and Pushover on Postgres with several server replicas:
- Postgres migrations v11-v14 with the five SQLite triggers as plpgsql;
  instr -> strpos, typed VALUES, a qualified ON CONFLICT WHERE, integer
  booleans. The parity test also compares trigger names.
- Relay enrollment, delivery phase and the pending enrollment (with the
  Ed25519 proof seed) move from <users.db>.push-relay*.json and process
  memory into the accounts store. Writes are compare-and-set on a
  revision; replicas reload it per tick, per dispatch pass and per job.
  Old files are imported once, except an enrollment under a manual relay
  or for another public origin, which is left on disk and never prunes.
- Credentials and the seed are sealed with userManagement.encryptionKey
  (CORESCOPE_ACCOUNTS_KEY), required on Postgres; on SQLite without a key
  they are stored as before, inside users.db. Leftover plain values are
  re-sealed at startup once a key is set. users.db is set to 0600, and
  user backups blank the relay secrets.
- Queue rows are claimed with a 5-minute lease (SKIP LOCKED on Postgres);
  each queue drains under a cluster lock; advisory locks use their own
  connection pool, so lock holders cannot starve the accounts store.
  Device links and the Pushover per-user limit lock the user.
- The enrollment proof and the Pushover connect token work on any
  replica; the proof endpoint validates before any database read and is
  limited per IP; device link/unlink are limited per user.

Also fixed while integrating:
- node_reach used IS NOT 'tx', which Postgres rejects (from Kpa-clawbot#2486).
- docker/server-exec.sh did not pass five variables the server reads
  (CORESCOPE_ACCOUNTS_KEY, CORESCOPE_PUSHOVER_TOKEN,
  CORESCOPE_PUSH_RELAY_CREDENTIAL, CORESCOPE_SMTP_PASSWORD, CORESCOPE_URL);
  tests/unit/test-server-exec-env.js now checks the list.
- corescope-migrate copy-users/verify-users failed on
  notification_pushover_sent (no key); it gets a rowid on Postgres, like
  mail_events, and verify redacts credential and seed columns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants