fix(#338): Add max concurrent agents limit

- Add MAX_CONCURRENT_AGENTS configuration (default: 20)
- Check current agent count before spawning
- Reject spawn requests with 429 Too Many Requests when limit reached
- Add comprehensive tests for limit enforcement

Refs #338
This commit is contained in:
Jason Woltje
2026-02-05 18:30:42 -06:00
parent ce7fb27c46
commit 3b80e9c396
4 changed files with 211 additions and 2 deletions

View File

@@ -83,4 +83,30 @@ describe("orchestratorConfig", () => {
expect(config.valkey.url).toBe("redis://localhost:6379");
});
});
describe("spawner config", () => {
it("should use default maxConcurrentAgents of 20 when not set", () => {
delete process.env.MAX_CONCURRENT_AGENTS;
const config = orchestratorConfig();
expect(config.spawner.maxConcurrentAgents).toBe(20);
});
it("should use provided maxConcurrentAgents when MAX_CONCURRENT_AGENTS is set", () => {
process.env.MAX_CONCURRENT_AGENTS = "50";
const config = orchestratorConfig();
expect(config.spawner.maxConcurrentAgents).toBe(50);
});
it("should handle MAX_CONCURRENT_AGENTS of 10", () => {
process.env.MAX_CONCURRENT_AGENTS = "10";
const config = orchestratorConfig();
expect(config.spawner.maxConcurrentAgents).toBe(10);
});
});
});

View File

@@ -37,4 +37,7 @@ export const orchestratorConfig = registerAs("orchestrator", () => ({
yolo: {
enabled: process.env.YOLO_MODE === "true",
},
spawner: {
maxConcurrentAgents: parseInt(process.env.MAX_CONCURRENT_AGENTS ?? "20", 10),
},
}));