Notifications and audit operations
RomM uses notifications to tell users about important system and account events, and uses the audit log to preserve a searchable record of actions. Notifications can remain in the user's inbox, reach approved external channels, and appear in open tabs in real time. Audit events capture who acted, what changed, and which resource was involved so operators can review activity after the action. For the wider runtime context, see Backend runtime and operations, Backend runtime composition, and Background jobs and scheduling.
Notification system
The notification system turns an event into a durable user message before it attempts external delivery. This order keeps the in-app inbox useful even when email, webhooks, or other services are unavailable.
Notification records
Each notification is stored for one user and has a level, kind, content data, and optional in-app link. A kind identifies a known event such as a completed scan, failed task, ended stream, changed role, or device install result. Custom kinds carry their own title and body. The client and outbound channel renderer use the event data to produce user-facing text, which lets the same stored event serve several delivery paths.
The inbox keeps the newest 200 messages for each user. Users can mark selected messages or the full inbox as read, and can dismiss selected messages or the full inbox. A new stored message is also sent to the user's open tabs, while read and dismiss actions are broadcast so those tabs stay aligned.
References: backend/…/notification.py• L17-77 backend/…/notifications_handler.py• L23-107 backend/…/notification_handler.py• L14-34 backend/…/notifications.py• L28-106
Notification recipients
Notification recipients are resolved from enabled accounts. A normal user can notify themself. An administrator can target selected users, all users, or all administrators when the request has the required user-management scope. A background action can notify the user who started it or fall back to administrators when no user started the work.
This boundary keeps system notices tied to valid accounts and prevents a caller from using a notification request to speak for another user without administrator access.
References: backend/…/notification_handler.py• L37-78 backend/…/notification_handler.py• L143-197 backend/…/notifications.py• L37-72
Notification channels
Notification channels are user-owned delivery targets that forward selected inbox messages outside the web application. RomM supports email, its signed JSON webhook format, and Apprise services that cover many third-party notification systems.
Channel configuration
Every channel has a name, an enabled state, a minimum severity, and an optional topic filter. The topic filter groups events such as scans, tasks, streaming, devices, account changes, and custom messages. A missing topic list means that the channel accepts every topic.
Channel secrets and delivery settings are stored in protected form. Webhook targets are checked before save, and non-administrator channels cannot reach private network addresses. Apprise exposes only supported service fields and hides secret fields when the channel is shown again. Each user can keep a limited number of channels.
References: backend/…/notification_channel.py• L14-42 backend/…/notification_channels.py• L65-116 backend/…/channels.py• L40-138 backend/…/webhook.py• L39-63 backend/…/notification_channel.py• L57-117
Email confirmation
An email channel is not deliverable until the address is confirmed. Creating or changing an email address sends a short-lived code, and the user must enter the code to mark the channel as confirmed. Resend requests have a cooldown, and failed or repeated code attempts cannot be used after the code expires or the attempt limit is reached.
Other channel types are considered confirmed after their configuration passes validation. A test action sends a sample message without waiting for a normal notification event, so an operator can check the target before enabling routine delivery.
References: backend/…/channels.py• L75-138 backend/…/channels.py• L211-267 backend/…/confirmation.py• L12-94 backend/…/notification_channels.py• L158-189
Message delivery
Delivery starts only after the notification is saved. The system selects enabled and confirmed channels whose severity and topic rules match the message, then places one low-priority background job on the queue for each selected channel. This keeps a slow destination from delaying the action that created the notification.
The delivery path renders a common message first. Email receives text, a webhook receives JSON, and Apprise sends a text notice through its selected service. Webhook payloads can include an HMAC signature when the channel has a secret. External destinations have bounded timeouts and retry a failed delivery before the failure counts against the channel.
flowchart LR
A[Operational event] --> B[Store inbox notification]
B --> C[Push to open user tabs]
B --> D[Match enabled confirmed channels]
D --> E[Queue one delivery per channel]
E --> F[Render common message]
F --> G[Email]
F --> H[Webhook]
F --> I[Apprise service]
G --> J[Record success or failure]
H --> J
I --> J
J --> K[Disable channel after repeated failures]
A successful delivery records its time and clears the last error. A final failed attempt records the error and increases the consecutive failure count. When the count reaches the channel limit, RomM disables the channel and creates an in-app warning for its owner. Re-enabling a channel starts its failure count again.
References: backend/…/notification_handler.py• L19-34 backend/…/delivery.py• L25-86 backend/…/delivery.py• L88-184 backend/…/notification_channels_handler.py• L63-75 backend/…/notification_channels_handler.py• L142-200
Audit event system
The audit system records operationally significant actions as durable events. It supports actions by signed-in users, anonymous callers, and system work such as scheduled jobs or file watchers. The record keeps copied actor and target names so the event remains readable after an account or target is removed.
Event recording
An audit event has an action, category, actor context, optional target, time, request address, device context, and structured data. Categories group events into consumption, library, collections, operations, and security views. The event data supplies details such as changed fields, counts, or transfer context that the client turns into a localized sentence.
Recording is best effort. If the audit write fails, RomM logs the failure and allows the user action or background job to continue. Event data is bounded before storage, and repeated download requests are combined within a short window so resumed or ranged transfers do not create misleading duplicates.
References: backend/…/audit_event.py• L17-146 backend/…/audit_event.py• L149-185 backend/…/audit_handler.py• L46-63 backend/…/audit_handler.py• L157-257 backend/…/audit_handler.py• L321-346
Audit history
The audit endpoint returns newest-first pages of events. Users can read their own history, while an administrator with the required scope can read and filter other users' events. Filters cover actor, action, category, target, time range, and text. Later pages can be pinned to the first page's highest event id so new activity does not shift the result set while it is being read.
The client presents each event as a translated sentence with actor, target, device, and address context. If the target no longer exists or the action is from an older version, the event still remains readable through its stored names and generic action data.
References: backend/…/audit_events.py• L20-95 backend/…/audit_events_handler.py• L26-140 backend/…/audit_event.py• L15-54 frontend/…/audit.ts• L7-31 frontend/…/auditEvents.ts• L1-41
Audit retention
Audit retention limits how long historical events remain in the database. The retention setting defaults to 90 days, while a value of zero keeps events indefinitely and prevents the scheduled cleanup from running.
When retention is enabled, a daily cleanup task removes events older than the cutoff in batches. Each batch is a short transaction, which limits lock time and allows the audit table to remain usable while old history is removed.
References: backend/…/__init__.py• L321-325 backend/…/cleanup_audit_log.py• L9-42 backend/…/audit_events_handler.py• L142-164
Change checklist
When these files or sections are changed, remember to consider these:
- Keep notification kinds, topic mapping, client text, outbound text, and channel filters aligned. A new kind can remain in the inbox but fail to reach the intended external channels or render as an unhelpful message.
- Keep channel confirmation, enabled-state checks, target validation, secret masking, and delivery-time rechecks aligned. A channel changed after queueing must not send to an old or unconfirmed target.
- Keep delivery retry counts, failure recording, automatic disablement, and the owner warning aligned. A change in one step can leave a broken channel active without a clear notice.
- Keep audit action categories, stored data, client sentence builders, and target links aligned. An event can be stored successfully but become unclear or point to the wrong product view.
- Keep audit retention configuration, task enablement, cutoff time, and batch deletion behavior aligned. A non-positive retention value has a different meaning from a positive retention period.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| An email channel is used before its address is confirmed | The channel cannot deliver messages | Require a valid confirmation code before delivery and before a channel test |
| A webhook target changes to a private address for a non-admin owner | The server could send data into a private network | Validate the URL at configuration time and enforce the owner role again at delivery time |
| A destination fails through all delivery retries | The channel accumulates errors and may keep wasting worker time | Record the final failure, disable the channel at the consecutive-failure limit, and notify its owner |
| Notification storage succeeds but channel queueing fails | The user still has the in-app message, but no external copy is sent | Keep the inbox write before queueing and log queue failures for operations review |
| Audit storage fails during a user or system action | The action completes without an audit record | Treat recording as best effort, log the failure, and do not make the main action depend on the audit write |
| Audit data exceeds its size bound or contains very large lists | The event becomes too large or hard to render | Clip lists and structured data before storing the event |
Key files
| File | Why to read it |
|---|---|
| backend/…/notification_handler.py | Shows the durable inbox write, realtime user push, recipient rules, and handoff to external delivery. |
| backend/…/notification.py | Defines notification kinds, topics, levels, and inbox limits. |
| backend/…/channels.py | Shows channel creation, editing, confirmation, testing, and re-enabling behavior. |
| backend/…/delivery.py | Shows channel matching, queueing, retries, delivery state, and automatic disablement. |
| backend/…/notification_channels.py | Shows the API boundary for channel configuration and confirmation. |
| backend/…/audit_handler.py | Shows actor and target capture, data limits, best-effort recording, and duplicate download control. |
| backend/…/audit_events_handler.py | Shows audit filtering, paging, visibility support, and batch deletion. |
| backend/…/audit_events.py | Shows the permission boundary and query contract for audit history. |
| backend/…/cleanup_audit_log.py | Shows when and how old audit events are removed. |
| frontend/…/auditEvents.ts | Shows how stored audit actions and data become readable user-facing event text. |