Files
warmbly/internal/app/instanceconfig/limits.go
Matthew Meszaros 6b18ab8d2d feat: sync mailboxes through narrow push/IDLE checks and a 15 to 60 minute full check scaled by mailboxes against the plan allowance (#1293)
* feat: run a narrow check (Graph inbox and junk delta, IMAP INBOX and junk from their cursors, Gmail history only) on a push or IDLE wake at most every 30 seconds while the full sync pass keeps its own timer, and resolve each Graph delta page and Gmail history page through one batched message-map lookup including the immutable-id regular fallback

* feat: give every mailbox without a live push channel or IMAP IDLE watch a jittered 5-minute narrow check (Graph inbox and junk, IMAP INBOX and junk, Gmail history) that starts the moment IDLE drops or a push channel lapses and stops when the signal is back

* feat: run every mailbox's full sync check every 15 to 60 minutes scaled by mailboxes held against the plan allowance (operator-editable sync.full_check_min_minutes and full_check_max_minutes, shipped as SyncPolicy.full_check_seconds with seeds and pool-linked mailboxes kept at one minute), give errors their own backoff in nextSyncDelay, retire SYNC_PUSH_FALLBACK_INTERVAL, and widen the sync_stale monitor and provider hold recovery freshness windows to match

* feat: document that mailboxes without push or IDLE see new mail within about 5 minutes through the narrow check while every folder gets the 15 to 60 minute full check, in the mailboxes guide, realtime mailbox sync, configuration and architecture pages, and list the narrow poll interval under effective limits

* feat: keep the full sync pass on a one-minute catch-up cadence while an import or Graph, Gmail or IMAP recovery is unfinished and pull it forward when a narrow check meets such work, add a 15-minute safety narrow check behind live push channels, treat a zero mailbox allowance with mailboxes held as the slowest full check, widen the stale backfill monitor to the full check window, and correct the IMAP_IDLE admin text
2026-11-20 12:15:37 +01:00

132 lines
8.1 KiB
Go

package instanceconfig
import (
"strconv"
"time"
"github.com/warmbly/warmbly/internal/config"
"github.com/warmbly/warmbly/internal/models"
)
// LimitEntry is one number an operator may be looking for.
type LimitEntry struct {
Name string `json:"name"`
Value string `json:"value"`
Unit string `json:"unit"`
Description string `json:"description"`
}
// LimitGroup is a rendered section of the effective-limits page.
type LimitGroup struct {
Title string `json:"title"`
Entries []LimitEntry `json:"entries"`
}
// Limits is the effective-limits document. Every value is a compiled constant
// from internal/config/constants.go, so this page is read-only by construction:
// per-organization variance goes through the admin override flow instead.
func Limits() []LimitGroup {
return []LimitGroup{
{
Title: "Sending",
Entries: []LimitEntry{
{"Default campaign cap", n(config.CampaignLimitDefault), "emails/day", "Per mailbox, before any organization override."},
{"Minimum gap between sends", n(config.MinWaitTimeDefault), "seconds", "Per mailbox. Spacing matters more than throughput."},
{"Highest campaign cap accepted", n(config.LimitMax), "emails/day", "The largest per-mailbox cap the API will store."},
{"Lowest campaign cap accepted", n(config.LimitMin), "emails/day", "The smallest per-mailbox cap the API will store."},
{"Campaign ramp start", n(config.CampaignRampStartDefault), "emails/day", "Where a new campaign sender starts before the ramp lifts it."},
{"Campaign ramp increment", n(config.CampaignRampIncrementDefault), "emails/day", "Added each day, applied only as a lower bound against the mailbox cap."},
{"Campaign ramp ceiling", n(config.CampaignRampCeilingDefault), "emails/day", "Where the ramp stops lifting."},
{"Sender weight ceiling", n(config.CampaignSenderWeightMax), "weight", "The largest share one mailbox can take in a rotation."},
{"New leads per campaign", n(config.CampaignMaxNewLeadsMax), "contacts", "The most contacts one campaign can pull in per run."},
},
},
{
Title: "Warmup",
Entries: []LimitEntry{
{"Warmup start", n(config.WarmupBaseDefault), "emails/day", "Where a mailbox begins warming."},
{"Warmup ceiling", n(config.WarmupMaxDefault), "emails/day", "Where the warmup ramp stops."},
{"Warmup ramp", "+" + n(config.WarmupIncreaseDefault), "emails/day", "Added each day while the mailbox stays healthy."},
},
},
{
Title: "Mailbox allowance",
Entries: []LimitEntry{
{"Fair-use sends per mailbox", n(config.FairUseSendsPerMailbox), "sends/day", "A paid plan holds one mailbox for every this many daily sends it includes; a plan with no daily cap holds unlimited mailboxes."},
{"Free workspace mailboxes", n(models.FreeWorkspaceMailboxLimit), "per organization", "Only workspaces that kept the free plan; new ones need a paid plan."},
{"Bulk connect batch", n(config.MailboxBulkBatchMax), "rows/request", "The most SMTP/IMAP rows one bulk connect call carries; the dashboard streams a CSV through batches of this size."},
{"Bulk connect concurrency", n(config.MailboxBulkConcurrency), "validations", "Credentials dialled at the same time within one batch."},
},
},
{
Title: "Organization hard caps",
Entries: []LimitEntry{
{"Campaigns created", n(config.HardCapCampaignsTotal), "per organization", "Total campaigns ever created."},
{"Active campaigns", n(config.HardCapCampaignsActive), "per organization", "Running at the same time."},
{"Team members", n(config.HardCapTeamMembers), "seats", "Members in one organization."},
{"Contacts", n(config.HardCapContacts), "per organization", "Stored contacts."},
{"Campaign sends", n(config.HardCapDailyCampaignSends), "emails/day", "Across every mailbox in one organization."},
},
},
{
Title: "Daily creation throttles",
Entries: []LimitEntry{
{"New campaigns", n(config.DailyThrottleNewCampaigns), "per organization/day", "Resets at UTC midnight. Not raisable per organization."},
{"New workspaces", n(config.DailyThrottleNewOrgs), "per owner/day", "Resets at UTC midnight."},
},
},
{
Title: "Scheduled and undo sends",
Entries: []LimitEntry{
{"New scheduled sends", n(config.DailyThrottleNewScheduledSends), "per user/day", "Rolling 24 hour window."},
{"Pending scheduled sends", n(config.MaxPendingScheduledSendsPerOrg), "per workspace", "Queued at once. Bounds queue storage rather than cost."},
{"Undo send window", n(config.UndoSendSecondsDefault), "seconds", "Default hold before an instant send leaves. Range " + n(config.UndoSendSecondsMin) + " to " + n(config.UndoSendSecondsMax) + "."},
},
},
{
Title: "Webhooks and integrations",
Entries: []LimitEntry{
{"Dispatch floor", n(config.WebhookDispatchBasePerMinute), "events/minute", "Every organization gets at least this, including free ones."},
{"Added per allowed mailbox", n(config.WebhookDispatchPerMailboxPerMinute), "events/minute", "The cap scales with the plan's mailbox allowance."},
{"Dispatch ceiling", n(config.WebhookDispatchMaxPerMinute), "events/minute", "The hard ceiling for any plan."},
},
},
{
Title: "Content and inbox",
Entries: []LimitEntry{
{"Email body", n(config.MaxEmailBodySize / 1024), "KB", "The largest body the platform stores."},
{"Contact record", n(config.MaxContactSize / 1024), "KB", "The largest single contact payload."},
{"Mailbox folders synced", n(config.MaxEmailFolders), "folders", "Per mailbox."},
{"IMAP fetch batch", n(config.ImapFetchBatchSize), "messages", "How many envelopes one sync window holds in memory."},
},
},
{
Title: "Mailbox sync fair use",
Entries: []LimitEntry{
{"Live burst", n(config.SyncBurstPer5Min), "messages/5 min", "New mail one mailbox may store in any five minute window. Over it, mail waits; nothing is dropped."},
{"Live hourly", n(config.SyncHourlyPerMailbox), "messages/hour", "Per mailbox, any clock hour."},
{"Backfill pace", n(config.SyncBackfillPerMinute), "messages/minute", "Per mailbox during the initial import of history."},
{"Flood threshold", n(config.SyncFloodPerHour), "messages/hour", "New live mail seen in one hour that deactivates the mailbox outright."},
{"Chronic overage", n(config.SyncThrottleEscalationDays), "days of 7", "Daily budget exhausted on this many of the last seven days deactivates the mailbox. The daily budgets, the backfill window and the full check interval are editable on Instance settings."},
{"Wake check gap", n(int(config.SyncWakeMinGap / time.Second)), "seconds", "Least time between two checks of one mailbox; a push or IDLE wake inside it waits."},
{"Narrow poll", n(int(config.SyncNarrowPollInterval / time.Second)), "seconds", "How often a mailbox without push or IDLE gets the inbox and junk check a wake would run."},
{"Push safety check", n(int(config.SyncPushSafetyInterval / time.Second)), "seconds", "How often a mailbox with a live push channel still gets the inbox and junk check, in case notifications stop arriving."},
{"Catch-up full check", n(int(config.SyncCatchUpInterval / time.Second)), "seconds", "Full check interval while a mailbox's history import or a folder recovery is unfinished."},
{"Seed full check", n(config.SyncFullCheckFastSeconds), "seconds", "Full check interval of placement seeds and pool-linked warmup mailboxes."},
{"Unibox page size", n(config.UniboxLimitDefault), "messages", "Default page size, range " + n(config.UniboxLimitMin) + " to " + n(config.UniboxLimitMax) + "."},
{"Sequence step delay", n(config.SequenceWaitAfterMax), "days", "The largest per-step wait a sequence can store."},
{"Sequence subject", n(config.SequenceSubjectLimit), "characters", "Per step."},
{"Sequence body", n(config.SequenceBodyLimit), "characters", "Per step."},
},
},
{
Title: "Notifications",
Entries: []LimitEntry{
{"Email digest window", n(config.NotificationEmailWindowDefaultMinutes), "minutes", "Default hold before notifications flush as one email. Range " + n(config.NotificationEmailWindowMinMinutes) + " to " + n(config.NotificationEmailWindowMaxMinutes) + "."},
},
},
}
}
func n(v int) string { return strconv.Itoa(v) }