Repository navigation
Description
Summary
Converge backend notification sending onto a single dispatch owner. Today 15+ modules call notification-send functions directly, so cross-cutting policy — rate limiting, dedup, quiet hours, user preference checks, batching — must be re-implemented (or is silently missing) at each call site. Callers should submit typed notification intents; one dispatcher owns policy and delivery.
Same governing rule as #9515 / #9516: one exclusive mutation API per canonical concern, migrate every caller, delete the alternatives. This is deliberately the smaller second convergence on the backend — sequence it after #9516 proves the pattern.
Evidence (verified in tree)
Direct senders (via utils/notifications.py send functions, webhooks, or proactive_notification):
routers/action_items.py,routers/oauth.py,routers/payment.py,routers/users.py,routers/apps.py,routers/integration.py,routers/notifications.pyutils/app_integrations.py,utils/webhooks.py,utils/fair_use.py,utils/wrapped/generate_2025.pyutils/conversations/process_conversation.py,utils/llm/proactive_notification.py(~22K of its own policy),utils/llm/model_config.pymodal/job.py(notifications cron)
There is no single point where "should this user receive this, now, on this channel?" is decided.
Target architecture
Producers (routers, processing pipeline, integrations, cron)
|
| typed intents: {kind, uid, payload, urgency, dedup_key, source}
v
Notification dispatch service (one module)
- owns preference/consent checks
- owns rate limits, dedup (by dedup_key), quiet hours, batching
- owns channel selection (FCM push, in-app, integration webhook)
- emits one delivery outcome per intent (delivered / suppressed(reason) / failed)
|
v
delivery drivers (FCM sender, webhook poster) — transport only, no policy
Suppressions are observable outcomes, not silent drops (AGENTS.md: silent UX healing allowed, silent ops is not — use existing domain metrics; only provider/mode fallbacks use record_fallback).
Scope
- Introduce the intent type + dispatcher; migrate every producer listed above.
- Delete before merge: direct calls to low-level send functions outside the dispatcher and delivery drivers; per-caller dedup/preference snippets superseded by the dispatcher.
- CI guard: fail on new direct send-function calls outside the dispatcher module. Ratchet to zero.
- Contract tests: preference-off suppression, dedup collision, rate-limit ceiling, quiet-hours deferral, delivery failure surfaced — through controllable seams per
backend/docs/test_isolation.md.
Definition of done
- All producers submit intents; zero direct send calls outside dispatcher/drivers (guard at zero).
- Policy checks exist exactly once.
- Suppression reasons observable in metrics/logs without raw content (log-sanitizer rules apply).
-
modal/job.pycron migrated (its deploy env constraints in AGENTS.md still hold). - Contract tests hermetic and in CI;
backend/test.shgreen. - Docs updated where service boundaries are described.
Non-goals
- Changing what notifications exist or their copy/timing product behavior.
- The proactive-notification content generation in
utils/llm/proactive_notification.py— only its send path moves. - Client-side notification handling (Flutter/macOS).
Related
- refactor(backend): converge conversation lifecycle onto a single mutation owner #9516 — conversation lifecycle convergence (do that first; it proves the intent→single-owner pattern and its guard style).
- refactor(macOS): converge chat, PTT, agents, tools, and continuity onto single owners #9515 — macOS convergence (origin of the governing rule and issue format).
Activity
aryanorastar commentedon Aug 30, 2026
Opened #12409 as the first production convergence slice for this issue.
What moved behind the new owner:
NotificationIntentvalues with explicit source/kind/policydispatched,suppressed, andfailedoutcomesThe external contract remains 10 notifications per app/user per UTC hour, including the existing rate-limit headers and 429 response. A deterministic test pins expiry to the next UTC-hour boundary. Plugin attribution and app/main-chat navigation payloads are also covered.
Proof:
The new AST ratchet records the remaining 20 legacy transport dependencies exactly and rejects new direct imports/calls, alias escapes, stale baselines, and baseline-assisted growth. Follow-up slices can only reduce that number toward the issue's zero-direct-sender definition of done.
This PR is intentionally marked
Part of #9518; it does not close the parent until the other producer families and shared preference/dedup/quiet-hour policies are migrated.refactor(backend): centralize app notification dispatch (#12409)