Bulk Thread Actions as Per-Action Endpoints
- Deciders: Julian Bäume
- Date: 2026-09-04
Status
Accepted
Context
The thread list has supported multi-selection for a long time (shift-click, ctrl-click, Ctrl+A), but no action ever applied to more than one thread. Production feedback asked for exactly that: being able to clear ten non-actionable mails from a busy shared inbox with one click.
Every thread action so far is a resource-oriented route on one thread (POST /threads/:inboxId/:threadId/<action>) with a typed request and response schema. Applying an action to many threads needed an API shape, and the App Suite middleware suggests one: its multiple endpoint takes a JSON list of arbitrary operations and answers with a list of results. That envelope is familiar to App Suite developers.
Decision
Bulk actions are per-action endpoints at inbox level, not a generic operation envelope:
POST /threads/:inboxId/bulk/delete { threadIds }
POST /threads/:inboxId/bulk/restore { threadIds }
POST /threads/:inboxId/bulk/spam { threadIds }
POST /threads/:inboxId/bulk/status { threadIds, status }
POST /threads/:inboxId/bulk/assignee { threadIds, user? }
POST /threads/:inboxId/bulk/categories { threadIds, categories }Each call handles up to 200 threads of one inbox and does:
- one middleware round-trip per affected folder where the action touches the mailbox (delete, restore, spam), instead of one per thread;
- one database transaction;
- one
threads.changedevent with the affected ids (omitted above 50 ids to respect thepg_notifypayload limit), so connected clients refresh once instead of once per thread.
Actions that touch the mailbox share their implementation with the single-thread routes (lib/delete-threads.ts, lib/restore-threads.ts, lib/spam-threads.ts); the single-thread route is the one-element case. Status, assignee and categories are small enough to be implemented directly and mirror the single-thread rules (auto-assign on status change, "new" becomes "to do" on assignment).
Responses report per-thread results (results[] or updated[]) so the client can tell partial failures apart from complete ones. A thread that could not be processed is reported, never silently skipped.
The frontend groups the selection by inbox before calling, because the virtual "me" folder mixes threads of several inboxes.
Consequences
Positive
- The API stays uniform: typed bodies, typed responses, one route per action, discoverable in the OpenAPI spec without discriminated unions.
- Authorization and inbox resolution happen once per request, not once per operation inside a loop.
- The real win of batching, a single middleware move for all mails, falls out naturally because each endpoint already knows which action it performs.
- Connected members see one refresh per bulk action.
Negative
- Six endpoints instead of one. Adding a new bulk-capable action means adding a route.
- The UI only ever applies one action to many threads. Heterogeneous batches (delete these, mark those as done) need several calls. Nothing in the product asks for them today.
Alternatives Considered
Client-side fan-out to the single-thread routes. Zero backend work and fine for ten threads, but N middleware calls, N transactions, N events and a messy partial-failure story. Rejected.
A generic multiple envelope like the middleware's. One endpoint with [{ action, threadId, data }]. Familiar to App Suite developers, but it fights the existing resource-oriented API: the request schema becomes a discriminated union, authorization moves into a per-operation loop, and the implementation still has to group operations by action to obtain a single middleware call. Its main feature, heterogeneous batches, has no use case in the UI. Rejected; the reasons are recorded here so the question does not come back with every new action.

