#12998: feat(agents): Add parallel sub-agent execution with concurrency control
channel: slack
app: web-ui
gateway
agents
stale
Cluster:
Subagent Enhancements and Features
## Summary
Adds concurrency-controlled batch execution for sub-agents.
## Features
- parallelWithLimit() for bounded concurrency
- spawnParallel() with timeout handling
- Duration tracking per agent
- Default: max 5 concurrent agents
## Expected Impact
- 40-60% throughput improvement for multi-task workflows
## Files
- src/agents/parallel-spawn.ts
- src/agents/parallel-spawn.test.ts (12 tests)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR introduces concurrency-controlled parallelism for sub-agent spawning (`src/agents/parallel-spawn.ts`) and cron job execution (`src/cron/service/timer.ts`), plus a model auto-routing + escalation-approval flow (new `src/agents/model-routing.ts` / `src/agents/approval-interlay.ts` and gateway handlers).
Key behavior changes include:
- New bounded-concurrency helpers (`parallelWithLimit`, `mapConcurrent`) used to overlap independent work.
- Cron now executes due/missed jobs concurrently (bounded at 3) rather than sequentially, and adds trace timing for `cron.onTimer`.
- Session subagent spawning can now route/override the child model via `routeModel()` (with approval when escalating tiers).
Primary issues to fix before merge:
- New parallel cron tests are timing-based with real timers and extensive console output, making them flaky under CI load.
- Several new approval/IPC paths add `process.on("message")` listeners that are not reliably removed on all exit paths (timeout/error), which can leak listeners and grow memory over time.
- New in-memory approval stores (gateway + broker) have no TTL/cleanup for unresolved requests and can leak/overwrite state in long-running processes.
- Cron’s `onTimer()` currently drops `rejected` settlements from the concurrent execution wrapper, which can leave per-job running markers/events unapplied if the wrapper ever throws.
<h3>Confidence Score: 2/5</h3>
- This PR has correctness and reliability risks that should be addressed before merging.
- Score is lowered due to (1) flaky real-timer concurrency tests likely to fail intermittently in CI, and (2) multiple new long-lived process message listeners and in-memory approval maps that can leak over time in a long-running gateway/agent process. The core concurrency implementation changes look reasonable, but these lifecycle/memory/test issues need fixes before merge.
- src/cron/service.parallel-execution.test.ts, src/agents/approval-interlay.ts, src/agents/approval-message-broker.ts, src/gateway/server-methods/model-approvals.ts, src/cron/service/timer.ts
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#10748: feat: Add sessions.spawn gateway method for direct subagent spawning
by fox-openclaw · 2026-02-06
77.0%
#22845: Pass agentDir through cron and followup embedded runs
by seilk · 2026-02-21
75.4%
#13055: fix: prevent cron RPC stalls with timeout and caching (#13018)
by trevorgordon981 · 2026-02-10
74.7%
#14734: test(agents): guard against stale allowAgents in existing sessions
by davidahmann · 2026-02-12
74.4%
#22627: control-ui: agent runner queue view
by vctorabrdge · 2026-02-21
74.2%
#11816: fix(cron): forward agent-specific exec config to isolated cron sess...
by AnonO6 · 2026-02-08
74.0%
#7584: Tests: align subagent announce wait expectations
by justinhuangcode · 2026-02-03
73.9%
#6515: fix: in-process IPC for cron tool to avoid WS self-contention timeout
by amco3008 · 2026-02-01
73.7%
#10608: fix(agents): honor spawn model override in gateway and session spaw...
by 1kuna · 2026-02-06
73.6%
#18205: fix (agents): add periodic retry timer for failed subagent announces
by MegaPhoenix92 · 2026-02-16
73.6%