TencentCloud/TencentDB-Agent-Memory · error · MetadataError

task_not_found

task_not_found

Error message

task not found: ${taskId}

What it means

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.

Source

Thrown at MemoryCore/src/metadata/service/metadata-service.ts:968

      if (!agent) {
        throw new MetadataError("agent_not_found", `agent not found: ${link.agent_id}`);
      }
      if (agent.team_id !== input.team_id) {
        throw new MetadataError(
          "agent_team_mismatch",
          `agent ${link.agent_id} not in team ${input.team_id}`,
        );
      }
    }
    return this.store.createTask(input);
  }

  async getTaskById(taskId: string): Promise<TaskEntity | null> {
    return this.store.getTaskById(taskId);
  }

  async updateTask(taskId: string, patch: Partial<TaskEntity>): Promise<TaskEntity> {
    if (!(await this.getTaskById(taskId))) throw new MetadataError("task_not_found", `task not found: ${taskId}`);
    const updated = await this.store.updateTask(taskId, patch);
    if (!updated) throw new MetadataError("task_not_found", `task not found: ${taskId}`);
    return updated;
  }

  async deleteTasks(taskIds: string[]): Promise<BatchDeleteResult> {
    return this.store.deleteTasks(taskIds);
  }

  async listTasksByTeam(
    teamId: string,
    pagination: PaginationParams = DEFAULT_PAGINATION,
    filter?: TaskFilter,
  ): Promise<PaginatedResult<TaskEntity>> {
    const page = await this.store.listTasksByTeam(teamId, pagination, filter);
    const items = page.items;
    return formatListResult({ items, total: page.total }, pagination);
  }

View on GitHub (pinned to 3efcd317b8)

Solutions

  1. Verify the taskId exists before updating by calling getTaskById(taskId) and handling null.
  2. Confirm the task was created through the same MetadataService/store instance (not a different database or environment).
  3. Check for typos, whitespace, or ID-format mismatches (e.g., using a local object key instead of the persisted ID).
  4. 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'.

Example fix

// before
const task = await svc.updateTask(taskId, { status: "done" });

// after
const existing = await svc.getTaskById(taskId);
if (!existing) {
  // handle missing task (create, log, or return 404)
  throw new Error(`cannot update: task ${taskId} does not exist`);
}
const task = await svc.updateTask(taskId, { status: "done" });
Defensive patterns

Strategy: validation

Validate before calling

const task = await metadataService.getTaskById(taskId);
if (!task) throw new Error(`task ${taskId} does not exist; cannot update`);

Type guard

function taskExists(t: TaskEntity | null): t is TaskEntity {
  return t !== null;
}

Try / catch

try {
  await metadataService.updateTask(taskId, patch);
} catch (e) {
  if (e instanceof MetadataError && e.code === "task_not_found") {
    return handleMissingTask(taskId); // 404 / create / skip
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of TencentCloud/TencentDB-Agent-Memory@3efcd317b8 (2026-09-01). Data as JSON: /api/errors/a95b1599f85c5fb2. Report an issue: GitHub.