google-gemini/gemini-cli · error

A2AClient getTask Error [${agentName}]: ${error.message}

Error message

A2AClient getTask Error [${agentName}]: ${error.message}

What it means

Thrown by `getTask` when the underlying A2A client's `getTask` call raises an `Error`. The manager wraps the original in a new prefixed Error and chains it via `cause`, preserving the agent name and operation context for downstream handlers.

Source

Thrown at packages/core/src/agents/a2a-client-manager.ts:266

  getClient(name: string): Client | undefined {
    return this.clients.get(name);
  }

  /**
   * Retrieves a task from an agent.
   * @param agentName The name of the agent.
   * @param taskId The ID of the task to retrieve.
   * @returns The task details.
   */
  async getTask(agentName: string, taskId: string): Promise<Task> {
    const client = this.clients.get(agentName);
    if (!client) throw new Error(`Agent '${agentName}' not found.`);
    try {
      return await client.getTask({ id: taskId });
    } catch (error: unknown) {
      const prefix = `A2AClient getTask Error [${agentName}]`;
      if (error instanceof Error) {
        throw new Error(`${prefix}: ${error.message}`, { cause: error });
      }
      throw new Error(`${prefix}: Unexpected error: ${String(error)}`);
    }
  }

  /**
   * Cancels a task on an agent.
   * @param agentName The name of the agent.
   * @param taskId The ID of the task to cancel.
   * @returns The cancellation response.
   */
  async cancelTask(agentName: string, taskId: string): Promise<Task> {
    const client = this.clients.get(agentName);
    if (!client) throw new Error(`Agent '${agentName}' not found.`);
    try {
      return await client.cancelTask({ id: taskId });
    } catch (error: unknown) {
      const prefix = `A2AClient cancelTask Error [${agentName}]`;

View on GitHub (pinned to 5024443c72)

Solutions

  1. Read `error.cause.message` for the original remote error text.
  2. Confirm the taskId was returned by a prior `sendMessageStream` call against the same agent.
  3. Retry with backoff for transient failures; if the task is gone, stop polling and surface a 'task unavailable' status.
  4. Verify auth is still valid (re-load the agent) if the cause suggests a 401/403.

Example fix

// before
try { await manager.getTask('rev', id); } catch (e) { throw e; }

// after
try { await manager.getTask('rev', id); }
catch (e) {
  if (e instanceof Error && /not found/i.test(e.cause?.message ?? '')) {
    return null; // task expired
  }
  throw e;
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
  return await manager.getTask(name, taskId);
} catch (e) {
  const cause = (e as Error).cause;
  if (cause instanceof Error && /not found|expired/i.test(cause.message)) {
    return null; // task is gone — stop polling
  }
  if (isTransient(cause)) {
    await backoff();
    return await manager.getTask(name, taskId);
  }
  throw e;
}

Prevention

When it happens

Trigger: The remote agent returns an error for the task lookup, the task id does not exist on the remote, the network fails, or an AbortSignal/timeout trips inside `client.getTask`. Any `instanceof Error` throw lands here.

Common situations: Polling a task id that has expired or was never created on the remote; transient network failure during retrieval; auth expired between message send and task poll; remote agent restarted and lost task state.

Related errors


AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12). Data as JSON: /api/errors/de2122c41ed0c0c1. Report an issue: GitHub.