Repository navigation
Open
Description
Summary
Implement concurrency limits to control how many automation runs can execute simultaneously, with a hierarchical system of defaults and caps.
Motivation
- System Protection: Prevent a single automation from overwhelming backend services (e.g., key-value store) with unbounded concurrent runs
- Monetization: Enable billing tiers based on org-level concurrency limits
- Fair Resource Sharing: Ensure no single org monopolizes system resources
Current Behavior
- No concurrency guards exist - multiple runs of the same automation can run concurrently
- Scheduled automations create new runs even if previous runs are still executing
- Event-triggered automations queue runs but dispatch without limit checks
- Manual dispatch API creates runs without checking for existing active runs
Proposed Hierarchy
GLOBAL (config/environment)
├── max_org_aggregate_cap = 500 (hard upper bound for any org)
├── max_per_automation_cap = 20 (hard upper bound for any automation)
├── default_org_aggregate = 50 (default org aggregate if not set)
├── default_per_automation = 1 (default per-automation if not set)
│
└── ORG (DB table or fetched from OpenHands API)
├── aggregate_max (total concurrent runs for this org)
├── default_per_automation (default for automations in this org)
│
└── AUTOMATION (existing table, new column)
└── max_concurrent_runs (limit for this specific automation)
Two Distinct Limit Types
- Per-Automation Max: How many concurrent runs can this specific automation have?
- Org Aggregate Max: How many total concurrent runs can this org have across ALL automations?
Resolution Chain
Per-Automation Limit:
automation.max_concurrent_runs
?? org.default_per_automation
?? settings.default_per_automation
(capped by settings.max_per_automation_cap)
Org Aggregate Limit:
org.aggregate_max
?? settings.default_org_aggregate
(capped by settings.max_org_aggregate_cap)
Behavior by Trigger Type
| Trigger Type | Behavior When At Limit | Recommended Default |
|---|---|---|
| Cron (scheduled) | Skip creating run, log the skip | 1 (no overlapping runs) |
| Manual dispatch API | Return HTTP 409 Conflict | 1 |
| Event-triggered | Create PENDING run (preserve payload), but don't dispatch until under limit | TBD - needs discussion. Events can burst (e.g., many commits pushed). |
Open Questions
-
Where should org settings live?
- Local
org_settingstable (simpler, self-contained) - Fetch from OpenHands API (single source of truth)
- Hybrid with caching?
- Local
-
Should PENDING runs count toward limits?
- Current proposal: only RUNNING counts
- Alternative: count PENDING too to prevent queue buildup
-
What happens when limits change mid-flight?
- Proposed: Let running jobs finish, only affect new dispatches
-
What's a reasonable default for event-triggered automations?
- Events can arrive in bursts (e.g., webhook replay, mass commits)
- Too low = long queue backlogs
- Too high = potential resource issues
Metadata
Metadata
Assignees
Labels
No labels
Activity
linear commentedon Apr 25, 2026
APP-1415
jpshackelford commentedon Apr 25, 2026
Implementation Tasks
1. Schema Changes
max_concurrent_runscolumn toautomationstableorg_settingstable (or decide to fetch from OpenHands API)2. Config Changes
config.py:max_org_aggregate_capmax_per_automation_capdefault_org_aggregatedefault_per_automation3. Validation
max_concurrent_runson automation create/update (can't exceed org/global caps)4. Scheduler Changes
5. Dispatcher Changes
6. API Changes
max_concurrent_runsin automation create/update/response schemas7. Database Index
jpshackelford commentedon Apr 25, 2026
Why hard concurrency caps are needed despite scaling
Q: If sandboxes auto-scale and we can add automation service pods, do we still need hard concurrency caps (system-configurable limits)?
A: Yes. Scaling and concurrency caps solve different problems:
Key insight: Sandboxes auto-scaling means more concurrent runs hit external resources (APIs, databases, services the automation interacts with), not fewer. Hard caps protect those downstream dependencies.
Additionally, without caps:
Hard caps are orthogonal to scaling — they bound how many runs execute simultaneously for a given automation/org, regardless of infrastructure capacity.
all-hands-bot commentedon Sep 15, 2026
[Automatic Post]: This issue has had no activity for 142 days (labels: none). Could someone take a look when they have a chance and help figure out next steps?
Generated by OpenHands automation on behalf of the user.
all-hands-bot commentedon Oct 23, 2026
[Automatic Post]: This issue has had no activity for 37 days (labels: none). Could someone take a look when they have a chance and help figure out next steps?
Generated by OpenHands automation on behalf of the user.