Skip to content

[Feature]: workflows: named pools that cap how much runs at once, with queueing #42486

Done

Description

@juliusmarminge

Problem

Nothing limits how much of a workflow runs at once. A workflow started 200 times runs 200 bodies; if each starts an agent, 200 agents start. The only limit in the engine is a webhook's 60 starts a minute. Authors who need "at most N of these at a time" build a queue in the store, with a sweep to give back places held by runs that died. #39013 lists "a concurrency cap or lock" under "Later".

Proposal

A named pool with a size, held for part of a run:

const { within, agent } = T3;

yield* within("builders", { limit: 4 }, agent("fix", { ... }));
  • At most limit holders of a pool run at once across all runs on the server. Later ones wait in the order they asked.
  • A place is given back when the wrapped step ends, fails, or its run is cancelled or paused for a person; a server restart does not leak places.
  • A waiting step shows as queued in the run view, with its position, and the run counts as active, not as needing anyone.
  • workflow(name, { concurrency: 4 }, …) is the same for whole runs, with the workflow as the pool.
  • limit: 1 is a lock.

The pool is a counted lock. It knows nothing about agents or machines; what to limit and to how many is the workflow's choice.

Acceptance

  • Ten runs entering within("p", { limit: 2 }, …) have two inside at a time, in arrival order.
  • Cancelling a holder lets the next one in without any sweep.
  • After a server restart mid-hold, the count is right (no leaked and no doubled places).
  • The run view shows "queued" for a waiting step.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions