Inbox domain
The inbox domain gives each user an organization-scoped view of important platform events. It turns new shares and workflow failures into durable records, exposes those records through the backend API, and keeps browser unread counts current without making live delivery the source of truth. It is a child domain of the backend API platform and relates to versioned backend APIs, backend workflow management, agent key-value extraction, and platform audit events.
Domain responsibilities
The inbox joins event producers, organization membership, user-facing API access, and scheduled cleanup. Its main goal is to give a user a safe and useful list of actions that need attention while keeping inbox failures separate from the action that caused them.
Event signals
The domain accepts two current event kinds. A resource-share event tells newly granted users about a resource, while an execution-failed event tells the owners of the resource that ran about a failed or stopped run. Existing email and webhook notifications remain separate from these inbox records.
| Signal | Recipient idea | User-facing result |
|---|---|---|
| Resource shared | Users who gained access through a direct or group share | A record that can open the shared resource when a route exists |
| Execution failed | Current organization members who own the workflow, pipeline, or API deployment | One record that points to the latest relevant failed run |
References: backend/…/models.py• L16-26 backend/…/events.py• L92-135 backend/…/events.py• L287-371 backend/…/ReadMe.md• L35-42
Event isolation
Inbox work is best-effort. The domain records and logs an inbox error without failing the share or execution status change that produced it. This keeps the inbox useful as a downstream view rather than a required part of the core workflow or permission action.
References: backend/…/events.py• L1-6 backend/…/events.py• L287-304 backend/…/test_execution_failed.py• L420-428 backend/…/test_inbox.py• L287-292
Organization-scoped records
An inbox record belongs to one user and one organization. API queries use the caller's current organization and the caller's user, so a user cannot list or change records from another organization or another user.
Record identity
The domain uses a dedupe key to control how one event appears for one user. Share events use a distinct event key, while failures use the source resource as the key so repeated failures update one record instead of flooding the inbox.
| Record property | Purpose |
|---|---|
kind | Identifies the broad event type |
title and body | Supplies display text and failure detail |
route | Describes the page or run that the client can open |
created | Orders records and starts the retention window |
read | Shows whether the user has seen the current record version |
References: backend/…/models.py• L16-50 backend/…/serializers.py• L15-29 backend/…/ReadMe.md• L13-33
Failure record lifecycle
Failure records represent the current failure state of a source, not every failed run. A newer failure refreshes the record and makes it unread again. When that run later finishes cleanly, the record returns to the newest earlier failure from the last 90 days or is removed when no such failure exists. The read state stays unchanged when the record is handed back to an older failure.
The flow below shows how terminal execution status becomes the current inbox view.
flowchart TD
A[Execution reaches terminal status] --> B{Failure condition?}
B -- No --> C[No failure record]
B -- Yes --> D[Find source owners in the organization]
D --> E[Create or refresh one record per owner]
E --> F[Point to the latest failed run]
F --> G{Later clean completion?}
G -- No --> H[Keep current failure]
G -- Yes --> I{Earlier recent failure?}
I -- Yes --> J[Hand record back to earlier failure]
I -- No --> K[Withdraw record]
References: backend/…/events.py• L138-240 backend/…/events.py• L266-371 backend/…/events.py• L388-402 backend/…/execution.py• L482-487
API access
The user API exposes the current user's inbox under the organization-scoped v2 route /notifications/inbox/. It supports newest-first listing plus single-item and bulk read actions. The list response includes both the page of records and the current unread total.
Inbox operations
The API treats a failure refresh as a new version of the same record. A client can send the created value it saw when it listed an item; if the item changed since then, the API leaves it unread and returns the current item with a conflict response. This prevents a client with stale data from marking a newer failure as read.
| Operation | Result |
|---|---|
GET /notifications/inbox/ | Paginated records and unread_count |
POST /notifications/inbox/<id>/read/ | Marks the seen or current version read |
POST /notifications/inbox/read-all/ | Marks all unread records in the current organization read |
References: backend/…/urls_v2.py• L39-42 backend/…/urls.py• L5-9 backend/…/views.py• L22-45 backend/…/views.py• L47-102 backend/…/serializers.py• L35-64
Client routes
An inbox item can carry a route with a key and string parameters. The client can open shared workflows, pipelines, deployments, connectors, adapters, Prompt Studio projects, Agentic Studio projects, or a failed execution. A missing or unknown route is valid and means that the client should show the item without opening a target.
References: backend/…/events.py• L27-51 backend/…/ReadMe.md• L18-31 backend/…/serializers.py• L7-10
Live unread counts
The list API is the authoritative unread count. In addition, the backend sends count updates to a signed-in user's Socket.IO room after a record is created, refreshed, withdrawn, or marked read. The count includes only the selected organization.
Count delivery
Count pushes happen after the database change commits. A background publisher keeps broker work out of the request path, so a broker failure does not block inbox writes. Pushes can be delayed, dropped when the short queue is full, or arrive out of order; clients must use the list API to repair stale state. A socket must reconnect after sign-in or sign-out because its user room is selected at connection time.
References: backend/…/service.py• L28-85 backend/…/service.py• L137-170 backend/…/ReadMe.md• L44-46 backend/…/test_live_count.py• L46-87
Retention and scheduled work
Inbox records are retained for 90 days from their current created time. A daily scheduler task calls an internal backend endpoint, which deletes old records in batches across all organizations. The purge does not emit live count updates because it is a retention action rather than a user read action.
Purge lifecycle
The purge schedule is declared by the inbox migration as an inert PostgreSQL scheduler row. Scheduler convergence adopts the row and runs inbox.purge at 02:30 UTC on the scheduler queue. The worker task is a thin proxy to POST /internal/v1/inbox/purge/; each batch commits independently, so a stopped run keeps completed deletions.
The scheduled path is:
sequenceDiagram
participant PG as PostgreSQL scheduler
participant W as Scheduler worker
participant API as Backend internal API
participant DB as Inbox records
PG->>W: Run inbox.purge at 02:30 UTC
W->>API: POST /internal/v1/inbox/purge/
API->>DB: Delete records older than 90 days in batches
API-->>W: Deleted record count
References: backend/…/0002_pg_periodic_task.py• L1-29 workers/…/inbox_tasks.py• L1-15 backend/…/internal_views.py• L17-33 backend/…/internal_base_urls.py• L201-203
Scheduler ownership
The migration seeds the schedule disabled for PostgreSQL ownership. The deployment's scheduler convergence step must adopt it before it can run. If the row is not adopted or ownership is released, no purge runs.
References: backend/…/0002_pg_periodic_task.py• L1-7 backend/…/0002_pg_periodic_task.py• L14-29 backend/…/test_purge.py• L60-68
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the public route, operation IDs, response shape, and stale-version read rule aligned between backend/…/urls_v2.py, backend/…/urls.py, backend/…/views.py, and the client contract.
- If a new event kind or resource route is added, update the event producer, route mapping, item contract, and client fallback behavior together.
- If failure identity or retention changes, review dedupe behavior, refresh timestamps, clean-run hand-back rules, and the purge cutoff as one contract.
- If the scheduler task name, queue, cron, or internal path changes, update the PostgreSQL periodic row, worker proxy, internal URL, and deployment convergence assumptions together.
- If organization context rules change, verify both API filtering and internal event paths that run without request context.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A failure has no current organization owners | No inbox record is created | Resolve owners as organization members and log the skipped event |
| A client reads an item after a newer failure refresh | The newer failure remains unread and the client receives 409 with current data | Compare the client's created value before marking read |
| Socket broker is down or the push queue is full | Live counts are delayed or dropped, but the database write still succeeds | Keep the list response authoritative and publish outside the request |
| The purge schedule is not adopted by the PostgreSQL scheduler | Records older than 90 days remain | Check scheduler ownership and the inbox_purge task registration |
| A run status changes without the terminal-status hook | The inbox does not reflect that terminal result | Keep both normal execution updates and internal batch status updates wired to the hook |
Key files
| File | Why to read it |
|---|---|
| backend/…/ReadMe.md | States the inbox contract, item shape, routes, read rules, live count behavior, and retention policy |
| backend/…/events.py | Shows how shares and execution outcomes become user records |
| backend/…/service.py | Defines record creation, dedupe and refresh behavior, unread counts, and live count delivery |
| backend/…/views.py | Defines the authenticated list, read, and read-all API behavior |
| backend/…/models.py | Defines the organization-scoped record identity and query indexes |
| backend/…/internal_views.py | Defines the internal retention purge contract |
| workers/…/inbox_tasks.py | Connects scheduled work to the internal purge endpoint |
| backend/…/execution.py | Shows the normal execution-status integration point |
| backend/…/internal_views.py | Shows the internal batch-status integration point |