{"record":{"id":"a95b1599f85c5fb2","repo":"TencentCloud/TencentDB-Agent-Memory","slug":"task-not-found","errorCode":"task_not_found","errorMessage":"task not found: ${taskId}","messagePattern":"task not found: (.+?)","errorType":"error_code","errorClass":"MetadataError","httpStatus":null,"severity":"error","filePath":"MemoryCore/src/metadata/service/metadata-service.ts","lineNumber":968,"sourceCode":"      if (!agent) {\n        throw new MetadataError(\"agent_not_found\", `agent not found: ${link.agent_id}`);\n      }\n      if (agent.team_id !== input.team_id) {\n        throw new MetadataError(\n          \"agent_team_mismatch\",\n          `agent ${link.agent_id} not in team ${input.team_id}`,\n        );\n      }\n    }\n    return this.store.createTask(input);\n  }\n\n  async getTaskById(taskId: string): Promise<TaskEntity | null> {\n    return this.store.getTaskById(taskId);\n  }\n\n  async updateTask(taskId: string, patch: Partial<TaskEntity>): Promise<TaskEntity> {\n    if (!(await this.getTaskById(taskId))) throw new MetadataError(\"task_not_found\", `task not found: ${taskId}`);\n    const updated = await this.store.updateTask(taskId, patch);\n    if (!updated) throw new MetadataError(\"task_not_found\", `task not found: ${taskId}`);\n    return updated;\n  }\n\n  async deleteTasks(taskIds: string[]): Promise<BatchDeleteResult> {\n    return this.store.deleteTasks(taskIds);\n  }\n\n  async listTasksByTeam(\n    teamId: string,\n    pagination: PaginationParams = DEFAULT_PAGINATION,\n    filter?: TaskFilter,\n  ): Promise<PaginatedResult<TaskEntity>> {\n    const page = await this.store.listTasksByTeam(teamId, pagination, filter);\n    const items = page.items;\n    return formatListResult({ items, total: page.total }, pagination);\n  }","sourceCodeStart":950,"sourceCodeEnd":986,"githubUrl":"https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/3efcd317b84146d6a08518ac0f7ee7c8a8d200ec/MemoryCore/src/metadata/service/metadata-service.ts#L950-L986","documentation":"MetadataService.updateTask throws MetadataError with code 'task_not_found' when no TaskEntity with the given taskId exists in the store. The service pre-checks existence via getTaskById and also guards against a racing delete: if store.updateTask returns null/undefined after the pre-check passed, it throws the same error. This is a lookup failure on an identifier supplied by the caller, not a data corruption issue.","triggerScenarios":"Calling metadataService.updateTask(taskId, patch) with a taskId that was never created, was already deleted via deleteTasks, or contains a typo/wrong-case ID. Also triggered when the task is deleted concurrently between the existence check and the store update.","commonSituations":"Stale references held by a worker after another service deleted the task; passing a session-local ID instead of the persisted task ID; tests reusing IDs from a wiped in-memory store; microservice calls crossing tenant boundaries where the task lives in another store.","solutions":["Verify the taskId exists before updating by calling getTaskById(taskId) and handling null.","Confirm the task was created through the same MetadataService/store instance (not a different database or environment).","Check for typos, whitespace, or ID-format mismatches (e.g., using a local object key instead of the persisted ID).","Create the task first (or re-fetch a fresh ID) if it was deleted; wrap the update in try-catch to handle 'task_not_found'."],"exampleFix":"// before\nconst task = await svc.updateTask(taskId, { status: \"done\" });\n\n// after\nconst existing = await svc.getTaskById(taskId);\nif (!existing) {\n  // handle missing task (create, log, or return 404)\n  throw new Error(`cannot update: task ${taskId} does not exist`);\n}\nconst task = await svc.updateTask(taskId, { status: \"done\" });","handlingStrategy":"validation","validationCode":"const task = await metadataService.getTaskById(taskId);\nif (!task) throw new Error(`task ${taskId} does not exist; cannot update`);","typeGuard":"function taskExists(t: TaskEntity | null): t is TaskEntity {\n  return t !== null;\n}","tryCatchPattern":"try {\n  await metadataService.updateTask(taskId, patch);\n} catch (e) {\n  if (e instanceof MetadataError && e.code === \"task_not_found\") {\n    return handleMissingTask(taskId); // 404 / create / skip\n  }\n  throw e;\n}","preventionTips":["Always create tasks through the same MetadataService instance you update them with.","Keep task IDs in typed references, not free-form strings copied between systems.","Delete tasks through a lifecycle that also invalidates cached task IDs.","Add an integration test that updates a nonexistent ID and asserts 'task_not_found'."],"tags":["metadata","lookup-failure","task","not-found"],"backgroundTag":"entity-not-found","analyzedSha":"3efcd317b84146d6a08518ac0f7ee7c8a8d200ec","analyzedAt":"2026-09-01T05:44:22.276Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}