Repository navigation
Description
Tracked in #568. This proposal stands on its own and doesn't depend on the others tracked there.
Summary
AHP doesn't say what happens when an automation is triggered while its previous run is still going. Hosts behave differently (some allow one active run per automation, others cap concurrent runs), and clients can neither see nor choose the behavior.
This proposal adds an optional concurrency policy to the definition: how many runs may execute at once, whether an occurrence beyond that limit queues, is skipped, or is coalesced into the run that is already waiting, and an optional batch window that lets a burst of occurrences become one run. The host publishes the policy it actually applies, and a run records, and gives its agent, every trigger occurrence it covers.
Scenarios
- An hourly job sometimes takes 90 minutes. Should the next occurrence wait, be skipped, or run in parallel? The author should decide, and every client should show the answer.
- Capacity. At most two runs of an expensive automation should execute at once.
- Bursts. A reviewer leaves five comments in 30 seconds. One run should handle all five, with the agent seeing every comment, rather than five runs racing each other.
- Simultaneous schedules. Two schedule triggers fire in the same minute. One run is enough, but it should record both occurrences.
AHP today
- The spec is silent about overlap.
misfirePolicycovers occurrences missed while automatic execution was unavailable, not occurrences that arrive while runs are active. - The spec guarantees that "one trigger occurrence is atomically associated with at most one run."
AutomationTriggeredRunOriginnames exactly one occurrence, so a host that combines occurrences has to leave all but one out of the record. - A run waiting for a slot can only be
pending, with no indication of why (see the related proposal on wait reasons).
Proposal
- Concurrency policy.
AutomationDefinitiongains optionalconcurrency:maxConcurrentRuns: the most runs of this automation that may berunningat once (at least 1).overlap: how automatic occurrences are admitted:queue: when the limit is reached, create the run anyway. It stayspendinguntil a slot frees, in arrival order.skip: when the limit is reached, don't create a run. The occurrence is dropped.coalesce: first, if an eligible run (see below) is stillpending, the occurrence joins it, whether or not the limit is reached. Otherwise the host creates a run, which waits inpendingif the limit is reached. So at most one eligible run waits at a time, and it covers everything that arrived while it waited.
batchWindowSeconds(withcoalesce): every new automatic run waits at least this long inpendingbefore it starts, even when a slot is free, so the rest of a burst can join it. Without a window, the first occurrence of a burst starts right away when a slot is free, and the rest join the next run.
- No implicit behavior. When
concurrencyis omitted, the host chooses. Either way, the host publishes the policy it applies in the stored definition, just as it normalizes event-trigger titles today, so clients always display real behavior. - Manual runs. Manual runs are explicit requests, so they are never skipped or coalesced. They count toward
maxConcurrentRuns, and if the limit is reached they wait aspending. - Coalescing rules.
- Eligibility. An occurrence can join only a run of the same automation that is still
pendingand would execute the same definition (the definition hasn't changed since the run was admitted) in the same way (for example, to the same delivery target, where targets can differ between runs). Otherwise, the occurrence is handled as a new arrival. For example, after a definition change, a run pinned to the old definition can still be waiting while a new run collects occurrences for the new one. - Cutoff. The host decides atomically whether each occurrence joins a run. A run accepts no more occurrences once it starts, and an occurrence that arrives later is handled as a new arrival.
- Record.
AutomationRunStategains the occurrences the run covers in addition toorigin, in arrival order, using the existingAutomationTriggeredRunOriginshape, appended by a new server-only action. The run summary carries a count.originstill means the occurrence that created the run, and every occurrence still belongs to at most one run. - Delivery. A coalesced run's agent receives the context of every occurrence the run covers, in the same way the host gives any run's agent its trigger context. Recording occurrences on the run isn't enough on its own; an agent that sees only the first comment of a burst hasn't handled the burst.
- Eligibility. An occurrence can join only a run of the same automation that is still
- Interaction with existing rules.
- Only enabled automations produce automatic occurrences, so a disabled automation's pending run stops accepting new ones.
misfirePolicyfirst decides what happens to occurrences missed while execution was unavailable. A resulting catch-up run that arrives while another run is active is then subject tooverlap.- For
afterRunsdisable conditions, an occurrence that joins an existing run doesn't consume allowance, because no run is admitted.
- Capability.
automations.concurrencylists theoverlapvalues the host supports, the largestmaxConcurrentRunsit accepts, and whether it supportsbatchWindowSeconds. Clients MUST NOT author other values.
Sketch
Names and shapes are illustrative. The implementation PR settles them.
interface AutomationDefinition {
// ...existing fields
concurrency?: AutomationConcurrency;
}
interface AutomationConcurrency {
/** @minimum 1 */
maxConcurrentRuns?: number;
overlap?: AutomationOverlapPolicy;
/** With coalesce: minimum time a new automatic run waits so a burst can join it. */
batchWindowSeconds?: number;
}
/** @nonexhaustive */
const enum AutomationOverlapPolicy {
Queue = 'queue',
Skip = 'skip',
Coalesce = 'coalesce',
}
interface AutomationRunState {
// ...existing fields
/** Occurrences after `origin` that joined this run while it was pending. */
coalesced?: AutomationTriggeredRunOrigin[];
}
interface AutomationRunSummary {
// ...existing fields
coalescedCount?: number;
}
/** Server-only: an occurrence joined this pending run. */
interface AutomationRunOccurrenceAddedAction {
type: 'automationRun/occurrenceAdded';
occurrence: AutomationTriggeredRunOrigin;
}
interface AutomationCapabilities {
// ...existing fields
concurrency?: {
overlap: AutomationOverlapPolicy[];
maxConcurrentRunsLimit?: number;
batchWindow?: {};
};
}Why this shape
- Policy lives in the definition, like
misfirePolicy. It describes how triggers become runs, it's authored with the automation, and the host enforces it. - The host stays authoritative and explicit. Publishing the applied policy follows the existing normalization pattern and removes host-to-host surprises.
- No new run statuses. A queued run is
pending, which is what it is.AutomationRunStatusstays@exhaustiveand unchanged. - One vocabulary for an occurrence. Coalesced occurrences reuse
AutomationTriggeredRunOrigin, so clients render them the same way they render a run's origin.
Compatibility
- Additive: an optional definition field, optional run-state and summary fields, one server-only action, and a capability for authoring.
- Clients that ignore
concurrencykeep working. They see runs that wait longer (pending) or occurrences that don't produce runs, as can already happen today.
Out of scope
- Host-wide capacity limits that span automations. These are host configuration. A waiting run's reason can explain them (see the related proposal on wait reasons).
- Limits per correlation value, which applies only if runs can be routed by correlation key (see the related proposal on continuing existing sessions).
Open questions
- Should the policy be per automation (proposed) or per trigger? For example, a schedule might skip while an event trigger queues.
- Should there be a "newest wins" option that cancels the active or pending run in favor of the new occurrence?
- Should manual runs be able to bypass the queue, or not count toward the limit?
- Should
queuehave a maximum depth, and what should happen beyond it? - Is a fixed batch window enough, or do some sources need a window that extends while occurrences keep arriving (a true debounce)?
Related proposals (none required)
- Run inputs (Proposal: Give automation runs their trigger context and manual input as data #569) makes delivering each occurrence's context portable: one input attachment per occurrence.
- Continue an existing session (Proposal: Let automation runs continue an existing session #572): with correlated delivery, limits and coalescing could apply per correlation value, and occurrences could join a message that's still queued in the target chat.
- Wait reasons and skipped occurrences (Proposal: Explain why an automation run is waiting or didn't happen #570): a queued run can report a
concurrencywait reason, and skipped occurrences can be recorded with anoverlapreason.
Activity
connor4312 commentedon Nov 9, 2026
I think the general controls around
AutomationConcurrencymake sense. Rather than capability detailing inAutomationCapabilities, I wonder if e.g. batch support is declared on theAutomationEventTriggerorAutomationTriggerEventDefinition, since that may determine the batching in addition to or instead of the host's own capabilities.benvillalobos commentedon Nov 13, 2026
No concerns for this proposal, coalesced runs make a lot of sense for input-based automations