解决 Nx 报错 Distributed Task Execution failed: timeout 分布式任务执行超时修复
排查 Nx Monorepo 使用 Nx Cloud 分布式任务执行时 CI 报错 Distributed Task Execution failed: agent timed out,分析 DTE agent 资源配额与网络心跳。
问题现象
GitHub Actions 或 GitLab CI 执行分布式 Nx 构建时发生流水线超时中断:
[Nx Cloud] Agent 3 timed out after 30 minutes waiting for task completion
Error: Distributed Task Execution failed: 2 tasks failed on external agents
触发根因
- 个别重型前端应用或端到端测试(E2E)耗时极长,超过了 Nx Cloud Agent 预设的单任务等待超时阈值;
- 配置的 Agent 容器并发任务数(
--max-parallel)过高,引发单机 CPU 与内存严重超卖导致构建进程陷入休眠; - Agent 机器到 Nx Cloud API 控制平面的网络连接发生抖动中断。
解决步骤
为高耗时任务拆分独立流水线或调大超时上限
在 CI 配置中为慢任务分配专用 Worker 并放宽超时限制:
- name: Run E2E Tests
run: npx nx affected --target=e2e --parallel=2
timeout-minutes: 60
在 nx.json 中配置合理的本地任务并发度
根据机器 CPU 物理核心数限制并发峰值:
{
"tasksRunnerOptions": {
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": ["build", "test", "lint"],
"parallel": 4
}
}
}
}
验证确认
重新触发 CI 流水线:
分布式代理负载均匀平衡,构建与测试在 8 分钟内全部顺利交付完成。


