← Back to PRs

#12998: feat(agents): Add parallel sub-agent execution with concurrency control

by trevorgordon981 open 2026-02-10 01:24 View on GitHub →
channel: slack app: web-ui gateway agents stale
## 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