mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-12-04 06:21:59 +09:00
Merge pull request #4908 from ruvnet/fix/4902-queen-failover-config
fix(swarm): honor enableFailover and maxDelegationAttempts in QueenCoordinator (#4902)
This commit is contained in:
2 files changed
+54
-2
No files matched your search
@@ -580,6 +580,52 @@ describe('QueenCoordinator', () => {
|
||||
expect(plan.backupAgents.length).toBeLessThanOrEqual(2);
|
||||
});
|
||||
|
||||
describe('failover config (#4902)', () => {
|
||||
// Six identical idle coders: one becomes primary, five are eligible
|
||||
// backups (each scores well above the 0.3 backup floor), so the
|
||||
// backup count is bounded only by the config under test.
|
||||
const sixIdleCoders = () =>
|
||||
Array.from({ length: 6 }, (_, i) => createMockAgent(`coder_${i + 1}`, 'coder', 'idle'));
|
||||
|
||||
async function planWith(config: Partial<QueenCoordinatorConfig>): Promise<DelegationPlan> {
|
||||
const q = createQueenCoordinator(mockSwarm, { enableLearning: false, ...config });
|
||||
await q.initialize();
|
||||
vi.mocked(mockSwarm.getAllAgents).mockReturnValue(sixIdleCoders());
|
||||
vi.mocked(mockSwarm.getAvailableAgents).mockReturnValue(sixIdleCoders());
|
||||
try {
|
||||
const task = createMockTask('task_failover', 'coding');
|
||||
const analysis = await q.analyzeTask(task);
|
||||
return await q.delegateToAgents(task, analysis);
|
||||
} finally {
|
||||
await q.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
it('selects 2 backups with the default config (control)', async () => {
|
||||
const plan = await planWith({});
|
||||
expect(plan.backupAgents).toHaveLength(2);
|
||||
expect(plan.backupAgents.map(b => b.agentId)).not.toContain(plan.primaryAgent.agentId);
|
||||
});
|
||||
|
||||
it('selects no backups when enableFailover is false', async () => {
|
||||
const plan = await planWith({ enableFailover: false });
|
||||
expect(plan.backupAgents).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('selects no backups when maxDelegationAttempts is 1', async () => {
|
||||
const plan = await planWith({ maxDelegationAttempts: 1 });
|
||||
expect(plan.backupAgents).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('selects maxDelegationAttempts - 1 backups when more are eligible', async () => {
|
||||
const plan = await planWith({ maxDelegationAttempts: 5 });
|
||||
expect(plan.backupAgents).toHaveLength(4);
|
||||
const ids = plan.backupAgents.map(b => b.agentId);
|
||||
expect(new Set(ids).size).toBe(4);
|
||||
expect(ids).not.toContain(plan.primaryAgent.agentId);
|
||||
});
|
||||
});
|
||||
|
||||
it('should create parallel assignments for subtasks', async () => {
|
||||
const task = createMockTask('task_1', 'coding', 'high');
|
||||
task.description = 'Complex task requiring design, implementation, and testing phases';
|
||||
|
||||
@@ -1316,11 +1316,17 @@ export class QueenCoordinator extends EventEmitter {
|
||||
): AgentAssignment[] {
|
||||
const backups: AgentAssignment[] = [];
|
||||
|
||||
// Select up to 2 backup agents
|
||||
// Failover disabled: no backups at all.
|
||||
if (!this.config.enableFailover) return backups;
|
||||
|
||||
// The primary counts as the first delegation attempt, so backups fill
|
||||
// the remaining attempts (default maxDelegationAttempts 3 -> 2 backups).
|
||||
const maxBackups = Math.max(0, this.config.maxDelegationAttempts - 1);
|
||||
|
||||
for (const score of scores) {
|
||||
if (backups.length >= maxBackups) break;
|
||||
if (score.agentId === primary.agentId) continue;
|
||||
if (score.totalScore < 0.3) continue;
|
||||
if (backups.length >= 2) break;
|
||||
|
||||
backups.push({
|
||||
agentId: score.agentId,
|
||||
|
||||
Reference in new issue
Block a user