background-agents
background-agents copied to clipboard
feat(automations): per-automation hourly limit for bot-triggered Slack runs
Summary
Make the hourly limit on bot-triggered runs configurable per automation. Today it is hardcoded (SLACK_BOT_TRIGGER_LIMIT = 10, SLACK_BOT_TRIGGER_WINDOW_MS = 1h in packages/control-plane/src/scheduler/slack-bot-trigger-policy.ts), added in #2557.
Motivation
The right limit depends on the bot. A cost-anomaly bot may post a couple of times a day, while a CI or monitoring bot in a busy channel can legitimately exceed 10 posts an hour. The limit is a backstop against a loop where a run's output makes another bot post, which starts the automation again. A single global value is either too loose for quiet bots or too tight for busy ones.
Proposal
- Add an optional
maxBotRunsPerHourtotriggerConfig.slack, next toincludeBotMessages, inpackages/shared/src/triggers/types.ts. Keep the window at one hour. - Default to the current
SLACK_BOT_TRIGGER_LIMIT(10) when absent, so existing automations keep today's behavior. - Validate it as a positive integer with an upper bound, so the loop guard can't be disabled (
automation-validation.ts). SlackBotTriggerPolicy.limitReachedreads the automation's value instead of the constant (pass the parsed trigger config, asacceptsalready does).- Web: a number input under Trigger on bot messages, shown only when it is on. Show the value on the automation detail page.
- Update the run-history skip label,
docs/AUTOMATIONS.mdandpackages/docs/content/docs/automations/slack-messages.mdx, which currently say "10".
Out of scope
- A configurable window length.
- A strict quota. The check stays a soft pre-admission count, and simultaneous bursts can still exceed it, as documented in #2557.
Tests
- Policy: uses the configured limit and falls back to the default when it is absent.
- Route validation: rejects zero, negative, non-integer and over-bound values.
- Web form: the input appears only with bot messages on, and its value round-trips on edit.