Files
c9e9a2a43e [MM-69693] notify token owners when an expired PAT is deleted (#37349)
* MM-69693: notify token owners when an expired PAT is deleted

Send an at-expiry DM from the cleanup_expired_access_tokens job at the
moment it deletes an expired personal access token. This complements the
pre-expiry warning cascade (MM-69215): for the silent-integration case,
where a fire-and-forget caller swallows the rejection error, the owner is
now told their token stopped working.

The notification fires in the same step as the delete, so no grace period,
tombstone, or new schema is needed and re-notification is inherently
impossible. It is best-effort: sent before the delete (while the
token->owner mapping still exists) and the delete proceeds regardless of
the result. Bot-owned tokens and tokens owned by deactivated users are
skipped, matching the pre-expiry job.

An app-layer notify callback is injected into the worker, mirroring how
expirynotify is wired, so cleanupExpired stays unit-testable with a fake
notifier.

* MM-69693: add app-layer notify tests and isolate notifier panics

Add expired_access_token_notify_test.go covering NotifyExpiredAccessTokensDeleted:
empty list, happy-path DM, bot-owned skip, deactivated-user skip, and
unknown-owner skip with continued processing.

Wrap the notifyExpired call in the cleanup worker with its own recover so a
panic in the best-effort notifier can't abort execute() before DeleteByIds
runs, and add a worker test asserting deletion still happens after a notify
panic.

* MM-69693: drop notifier panic recover from cleanup worker

The job-level HandleJobPanic in execute() is already the panic boundary for
the run, and NotifyExpiredAccessTokensDeleted logs and swallows its own
errors, so the local recover around notifyExpired added no real protection.
Remove it (and its test) along with the now-redundant inline comment; the
notify-before-delete rationale stays documented on cleanupExpired.

* MM-69693: thread request.CTX into NotifyExpiredAccessTokensDeleted

Pass the job's request context from the cleanup worker down through
cleanupExpired into the notify callback instead of building a fresh
EmptyContext inside the app function, so notification logging is correlated
with the job's logger.

---------

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-09 11:13:30 +02:00
..
…