ruvnet/ruflo · error · Error
Task ${taskId} not assigned to this agent
Error message
Task ${taskId} not assigned to this agent What it means
Agent.completeTask(taskId) requires the taskId to be present in the agent's current task set — it throws when asked to complete a task it was never assigned (or already completed). This guards the bookkeeping invariant between assignment and completion.
Source
Thrown at v3/@claude-flow/swarm/src/domain/entities/agent.ts:267
if (this._status === 'terminated') {
throw new Error('Cannot assign task to terminated agent');
}
if (this._currentTaskIds.size >= this._maxConcurrentTasks) {
throw new Error('Agent at maximum concurrent task capacity');
}
this._currentTaskIds.add(taskId);
this._status = 'busy';
this._lastActiveAt = new Date();
this._updatedAt = new Date();
}
/**
* Complete a task
*/
completeTask(taskId: string): void {
if (!this._currentTaskIds.has(taskId)) {
throw new Error(`Task ${taskId} not assigned to this agent`);
}
this._currentTaskIds.delete(taskId);
this._completedTaskCount++;
if (this._currentTaskIds.size === 0) {
this._status = 'active';
}
this._lastActiveAt = new Date();
this._updatedAt = new Date();
}
/**
* Check if agent can accept more tasks
*/
canAcceptTask(): boolean {
return (View on GitHub (pinned to fa13ee4ad6)
Solutions
- Make completion idempotent in the caller: check membership first or swallow this specific throw Single-flight task execution: cancel retry timers once completion starts Route completions through the coordinator that owns the task->agent mapping, not straight to the entity For retried tasks, complete them on the CURRENT assigned agent only
Example fix
// before
agent.completeTask(taskId); // throws on duplicate/misrouted completion
// after
function safeComplete(agent, taskId) {
try { agent.completeTask(taskId); }
catch (e) {
if (e instanceof Error && /not assigned to this agent/.test(e.message)) return; // idempotent no-op
throw e;
}
} Defensive patterns
Strategy: try-catch
Validate before calling
// Route completion through the coordinator that owns the task->agent map: const agent = coordinator.ownerOf(taskId); if (!agent) return; // unknown/stale task — nothing to complete agent.completeTask(taskId);
Try / catch
try { agent.completeTask(taskId); }
catch (e) {
if (e instanceof Error && /not assigned to this agent/.test(e.message)) return; // idempotent duplicate/misroute
throw e;
} Prevention
- Deduplicate completion events (idempotency key per taskId) Cancel retry timers before completing to avoid complete/fail races After fail() re-queues a task, complete it on the NEW assignee only
When it happens
Trigger: Calling completeTask() twice with the same id (the first call removed it from the set) Completing a task on the wrong agent instance after reassignment (task.fail() resets _assignedAgentId and re-queues) Coordinator tracking divergence: its task->agent map disagrees with the entity's set Task retry flow that re-assigned the task elsewhere but completion raced back to the old agent
Common situations: At-least-once delivery of completion events causing duplicate completeTask() calls Concurrent retries: fail() re-queues a task while a late success handler completes it on the original agent Event-sourcing replays applying completion events against a rebuilt agent state Cross-service id mismatches (string taskId normalized differently)
Related errors
- Cannot start terminated agent
- Can only pause active or busy agent
- Can only resume paused agent
- Can only recover from error state
- Can only complete running tasks
AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18).
Data as JSON: /api/errors/1f32d507caca6845.
Report an issue: GitHub.