{"record":{"id":"9bff6e7408ab9929","repo":"ruvnet/ruflo","slug":"task-input-taskid-not-found","errorCode":null,"errorMessage":"Task '${input.taskId}' not found","messagePattern":"Task '(.+?)' not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/swarm/src/application/commands/create-task.command.ts","lineNumber":111,"sourceCode":"/**\n * Cancel Task Command Result\n */\nexport interface CancelTaskResult {\n  success: boolean;\n  taskId: string;\n  previousStatus: string;\n}\n\n/**\n * Cancel Task Command Handler\n */\nexport class CancelTaskCommandHandler {\n  constructor(private readonly repository: ITaskRepository) {}\n\n  async execute(input: CancelTaskInput): Promise<CancelTaskResult> {\n    const task = await this.repository.findById(input.taskId);\n    if (!task) {\n      throw new Error(`Task '${input.taskId}' not found`);\n    }\n\n    const previousStatus = task.status;\n    task.cancel();\n    await this.repository.save(task);\n\n    return {\n      success: true,\n      taskId: input.taskId,\n      previousStatus,\n    };\n  }\n}\n","sourceCodeStart":93,"sourceCodeEnd":125,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/swarm/src/application/commands/create-task.command.ts#L93-L125","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the id first: only cancel when repository.findById(taskId) (or a task listing) finds the task.","Make cancellation idempotent in the caller: treat 'not found' as already-cancelled success.","Re-fetch the canonical id from the component that created the task."],"exampleFix":"// before\nawait cancelTask.execute({ taskId }); // throws on unknown/stale id\n\n// after — treat a missing task as already cancelled\nif (await taskRepository.findById(taskId)) {\n  await cancelTask.execute({ taskId });\n}","handlingStrategy":"validation","validationCode":"if (!(await taskRepository.findById(taskId))) {\n  // already gone: treat cancellation as complete\n  return { success: true, taskId, previousStatus: 'unknown' };\n}\nawait cancelTaskHandler.execute({ taskId });","typeGuard":null,"tryCatchPattern":"try {\n  await cancelTaskHandler.execute({ taskId });\n} catch (e) {\n  if (e instanceof Error && /^Task '.*' not found$/.test(e.message)) {\n    return; // idempotent cancel: missing entity is the desired end state\n  }\n  throw e;\n}","preventionTips":["Use only ids returned by create commands.","Design cancel endpoints idempotently: not-found means already cancelled.","Refresh task ids in UI state on every list/subscribe cycle."],"tags":["task","not-found","cqrs","command-handler"],"backgroundTag":"resource-not-found","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}