Skip to content

Proposal: Automation concurrency limits, overlap policy, and coalesced runs #573

Open

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. misfirePolicy covers 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." AutomationTriggeredRunOrigin names 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

  1. Concurrency policy. AutomationDefinition gains optional concurrency:
    • maxConcurrentRuns: the most runs of this automation that may be running at once (at least 1).
    • overlap: how automatic occurrences are admitted:
      • queue: when the limit is reached, create the run anyway. It stays pending until 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 still pending, the occurrence joins it, whether or not the limit is reached. Otherwise the host creates a run, which waits in pending if the limit is reached. So at most one eligible run waits at a time, and it covers everything that arrived while it waited.
    • batchWindowSeconds (with coalesce): every new automatic run waits at least this long in pending before 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.
  2. No implicit behavior. When concurrency is 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.
  3. 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 as pending.
  4. Coalescing rules.
    • Eligibility. An occurrence can join only a run of the same automation that is still pending and 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. AutomationRunState gains the occurrences the run covers in addition to origin, in arrival order, using the existing AutomationTriggeredRunOrigin shape, appended by a new server-only action. The run summary carries a count. origin still 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.
  5. Interaction with existing rules.
    • Only enabled automations produce automatic occurrences, so a disabled automation's pending run stops accepting new ones.
    • misfirePolicy first 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 to overlap.
    • For afterRuns disable conditions, an occurrence that joins an existing run doesn't consume allowance, because no run is admitted.
  6. Capability. automations.concurrency lists the overlap values the host supports, the largest maxConcurrentRuns it accepts, and whether it supports batchWindowSeconds. 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. AutomationRunStatus stays @exhaustive and 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 concurrency keep 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

  1. Should the policy be per automation (proposed) or per trigger? For example, a schedule might skip while an event trigger queues.
  2. Should there be a "newest wins" option that cancels the active or pending run in favor of the new occurrence?
  3. Should manual runs be able to bypass the queue, or not count toward the limit?
  4. Should queue have a maximum depth, and what should happen beyond it?
  5. 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)

Activity

  1. added
    feature-request
    on Nov 6, 2026
  2. connor4312 commented on Nov 9, 2026

    @connor4312
    Member

    I think the general controls around AutomationConcurrency make sense. Rather than capability detailing in AutomationCapabilities, I wonder if e.g. batch support is declared on the AutomationEventTrigger or AutomationTriggerEventDefinition, since that may determine the batching in addition to or instead of the host's own capabilities.

  3. benvillalobos commented on Nov 13, 2026

    @benvillalobos
    Member

    No concerns for this proposal, coalesced runs make a lot of sense for input-based automations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

feature-request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions