Skip to content

[Card Locking] Add engineering alert mailer for lock/unlock events - #14512

Open
garyhtou wants to merge 1 commit into
mainfrom
worktree-card-lock-notif-engr
Open

[Card Locking] Add engineering alert mailer for lock/unlock events#14512
garyhtou wants to merge 1 commit into
mainfrom
worktree-card-lock-notif-engr

Conversation

@garyhtou

@garyhtou garyhtou commented Aug 5, 2026

Copy link
Copy Markdown
Member

Summary of the problem

Card locking shipped ~2 weeks ago. To verify it's behaving correctly in production, HCB engineers want an alert whenever any user's cards get locked or unlocked.

Describe your changes

  • New EngineeringAlertMailer with cards_locked/cards_unlocked actions, sent to a Slack-posting address via Credentials.fetch(:SLACK_HCB_ENGR_ALERTS_EMAIL) (unset today; add the real value in Doppler separately). Content is intentionally minimal (name, email, admin link, counts — no merchant/amount detail).
  • Hooked in via a User model after_update_commit callback (CardLocking::CardholderBehavior, keyed on saved_change_to_cards_locked?) rather than inside UserService::UpdateCardLocking, so it fires on any writer of cards_locked, not just that one service.
  • Counts/suppression state are captured at the moment of the transition and passed into the mailer, rather than queried live inside the async delivery job, so the alert describes the transition it's reporting on.
  • When an unlock leaves overdue charges outstanding and the user is not currently suppressed by an admin (suppression is a supported action that unlocks without resolving receipts by design), it's reported via Rails.error.unexpected as a violated precondition — reported to AppSignal in production, raised loudly in development/test.

Note for reviewers: there's no Rails.env.production? gate on delivery — the only thing preventing this from firing outside production is SLACK_HCB_ENGR_ALERTS_EMAIL staying unset there. That mirrors how AdminMailer/OrganizerPositionDeletionRequestMailer already handle SLACK_NOTIFICATIONS_EMAIL in this codebase, but worth confirming the Doppler value doesn't get shared into a staging config before this ships.

Alerts HCB engineers via a Slack-posting email address whenever any
user's cards get locked or unlocked, to verify the recently-shipped
card-locking feature behaves correctly in production. Hooks in at the
User model level (an after_update_commit callback keyed on
cards_locked changing) rather than in UserService::UpdateCardLocking,
so it catches every writer of that column, not just the one service.

Counts and suppression state are captured at the moment of the
transition and passed into the mailer, rather than queried live inside
the async delivery job, so the alert describes the transition it's
reporting on rather than whatever state exists whenever the job
happens to run.

When an unlock leaves overdue charges outstanding and isn't from admin
suppression (a supported action that unlocks without resolving
receipts by design), it's reported via Rails.error.unexpected as a
violated precondition.

Recipient is env-var-driven via Credentials.fetch(:SLACK_HCB_ENGR_ALERTS_EMAIL).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@garyhtou
garyhtou requested a review from a team August 5, 2026 23:24
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