Skip to content

fix(runtime): respect max concurrent tasks in ExecutionEngine::execute_parallel()#1576

Open
SH20RAJ wants to merge 2 commits intomofa-org:mainfrom
SH20RAJ:fix/1505-execution-engine-concurrency
Open

fix(runtime): respect max concurrent tasks in ExecutionEngine::execute_parallel()#1576
SH20RAJ wants to merge 2 commits intomofa-org:mainfrom
SH20RAJ:fix/1505-execution-engine-concurrency

Conversation

@SH20RAJ
Copy link
Copy Markdown
Contributor

@SH20RAJ SH20RAJ commented Apr 4, 2026

Summary

Fixes #1505 - ExecutionEngine::execute_parallel() was spawning unbounded tokio tasks, completely ignoring the RuntimeConfig::max_concurrent_tasks setting, leading to potential resource exhaustion.

Problem

The execute_parallel() method spawned one tokio::spawn per input with zero concurrency limits. A caller passing 1,000 inputs would spawn 1,000 concurrent tasks simultaneously:

  • Memory exhaustion
  • File descriptor limit exceeded
  • LLM API rate limit abuse
  • Cascading system failures

The RuntimeConfig::max_concurrent_tasks setting was effectively dead code—users could set it to 5 through AgentBuilder but the executor would ignore it.

Solution

Implement Semaphore-based back-pressure:

  • Acquire a permit before spawning each task
  • Hold permit for task lifetime (prevents task from counting against limit)
  • Respects concurrency constraints (default: 10 max concurrent tasks)
  • Tasks queue naturally in executor; no busy-waiting

Impact

  • Maximum concurrent tasks is now enforced
  • No unbounded memory growth
  • Graceful queueing under high load
  • API rate limits protected
  • System stability guaranteed

Testing

Tested with high-volume input (1000+ tasks) to verify:

  • Only N concurrent tasks spawn at a time
  • Memory remains bounded
  • No tasks are dropped

GSOC 2026 Contribution

Critical bug fix for production stability. Addresses priority P1 issue #1505.

Cc: @Mustafa11300 @rahulkr182

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ExecutionEngine::execute_parallel() ignores max_concurrent_tasks — spawns unbounded tokio::spawn tasks

1 participant