ruvnet/ruflo · error · Error

Task '${input.taskId}' not found

Error message

Task '${input.taskId}' not found

What it means

CancelTaskCommandHandler loads the task with repository.findById(input.taskId); when no aggregate is found it throws before task.cancel() and save() are ever reached. A plain entity-not-found guard on the CQRS command side: cancelling an unknown, mistyped, or already-removed task id fails fast.

Source

Thrown at v3/@claude-flow/swarm/src/application/commands/create-task.command.ts:111

/**
 * Cancel Task Command Result
 */
export interface CancelTaskResult {
  success: boolean;
  taskId: string;
  previousStatus: string;
}

/**
 * Cancel Task Command Handler
 */
export class CancelTaskCommandHandler {
  constructor(private readonly repository: ITaskRepository) {}

  async execute(input: CancelTaskInput): Promise<CancelTaskResult> {
    const task = await this.repository.findById(input.taskId);
    if (!task) {
      throw new Error(`Task '${input.taskId}' not found`);
    }

    const previousStatus = task.status;
    task.cancel();
    await this.repository.save(task);

    return {
      success: true,
      taskId: input.taskId,
      previousStatus,
    };
  }
}

View on GitHub (pinned to fa13ee4ad6)

Solutions

  1. Verify the id first: only cancel when repository.findById(taskId) (or a task listing) finds the task.
  2. Make cancellation idempotent in the caller: treat 'not found' as already-cancelled success.
  3. Re-fetch the canonical id from the component that created the task.

Example fix

// before
await cancelTask.execute({ taskId }); // throws on unknown/stale id

// after — treat a missing task as already cancelled
if (await taskRepository.findById(taskId)) {
  await cancelTask.execute({ taskId });
}
Defensive patterns

Strategy: validation

Validate before calling

if (!(await taskRepository.findById(taskId))) {
  // already gone: treat cancellation as complete
  return { success: true, taskId, previousStatus: 'unknown' };
}
await cancelTaskHandler.execute({ taskId });

Try / catch

try {
  await cancelTaskHandler.execute({ taskId });
} catch (e) {
  if (e instanceof Error && /^Task '.*' not found$/.test(e.message)) {
    return; // idempotent cancel: missing entity is the desired end state
  }
  throw e;
}

Prevention

When it happens

Trigger: Cancelling with a wrong or stale task id; the task already completed and was deleted/archived; the repository is in-memory and was reset by a process restart; a double-submit where the first cancel already succeeded and removed the task.

Common situations: A UI cancel button holding an id from a stale list; retry logic repeating a cancel whose first attempt actually succeeded; tests running against an empty repository; ids from a different environment.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18). Data as JSON: /api/errors/9bff6e7408ab9929. Report an issue: GitHub.