feat(cleanup): hide and prune stale mailboxes

Mailbox listings grew unbounded as old sessions ended without
unregistering. This adds two layers of cleanup, configurable via
mailbox.json or `serve` flags:

- Lazy filter: list responses (REST /v1/list, MCP list_mailboxes)
  drop mailboxes idle longer than hideAfterMinutes (default 24h),
  while always keeping the caller and any sender with messages
  pending for them.
- Background sweep: startServer runs an initial prune on boot and
  schedules an unref'd interval timer that hard-deletes mailboxes
  idle longer than deleteAfterMinutes (default 7d) which have no
  pending messages, and wipes their delivered history.
This commit is contained in:
Mika Kuns
2026-05-20 13:54:03 +02:00
parent 06a2ea6b7b
commit 0c06e2cf4b
7 changed files with 349 additions and 17 deletions

View File

@@ -78,7 +78,30 @@ program
.option("--bind <address>", "Bind address")
.option("--db-path <path>", "SQLite database path")
.option("--config <path>", "Path to mailbox.json")
.action(async (opts: { port?: number; bind?: string; dbPath?: string; config?: string }) => {
.option(
"--hide-after-minutes <n>",
"Hide mailboxes idle longer than N minutes from list responses (0 = disabled)",
(v) => parseInt(v, 10),
)
.option(
"--delete-after-minutes <n>",
"Hard-delete mailboxes idle longer than N minutes (0 = disabled)",
(v) => parseInt(v, 10),
)
.option(
"--sweep-interval-minutes <n>",
"Stale-mailbox sweep interval in minutes (0 = disabled)",
(v) => parseInt(v, 10),
)
.action(async (opts: {
port?: number;
bind?: string;
dbPath?: string;
config?: string;
hideAfterMinutes?: number;
deleteAfterMinutes?: number;
sweepIntervalMinutes?: number;
}) => {
const cfg = resolveConfig(opts);
try {
const { startServer } = await import("./server.js");