google-gemini/gemini-cli · warning · Error

Execution aborted

Error message

Execution aborted

What it means

Thrown at the top of the agent turn loop in CoderAgentExecutor.execute when abortSignal.aborted is already true before processing a turn. It is the executor's cooperative-cancellation exit: an AbortController (tracked in activeAbortControllers) was triggered, typically by an explicit cancel request or a secondary execution loop being superseded. The error is intended to unwind the turn, not signal a defect.

Source

Thrown at packages/a2a-server/src/agent/executor.ts:747

            `[CoderAgentExecutor] Starting main execution for message ${userMessage.messageId} for task ${taskId}.`,
          );
          this.executingTasks.add(taskId);

          let agentTurnActive = true;
          logger.info(
            `[CoderAgentExecutor] Task ${taskId}: Processing user turn.`,
          );
          let agentEvents = currentTask.acceptUserMessage(
            requestContext,
            abortSignal,
          );

          while (agentTurnActive) {
            if (abortSignal.aborted) {
              logger.info(
                `[CoderAgentExecutor] Task ${taskId} aborted before turn. Exiting loop.`,
              );
              throw new Error('Execution aborted');
            }
            logger.info(
              `[CoderAgentExecutor] Task ${taskId}: Processing agent turn (LLM stream).`,
            );
            const toolCallRequests: ToolCallRequestInfo[] = [];
            for await (const event of agentEvents) {
              if (abortSignal.aborted) {
                logger.warn(
                  `[CoderAgentExecutor] Task ${taskId}: Abort signal received during agent event processing.`,
                );
                throw new Error('Execution aborted');
              }
              if (event.type === GeminiEventType.ToolCallRequest) {
                toolCallRequests.push(event.value);
                continue;
              }
              await currentTask.acceptAgentMessage(event);
            }

View on GitHub (pinned to 5024443c72)

Solutions

  1. Treat this error as expected control flow: catch it at the caller and transition the task to a 'canceled'/'failed' state rather than logging a stack trace.
  2. Verify the cancel surface (tasks/cancel handler) is only invoked deliberately, not by a retry/debounce bug that double-fires.
  3. If aborts happen spuriously, check whether the secondary-execution guard at executor.ts:700 is incorrectly throwing for non-aborted errors.
  4. Confirm the AbortController is registered in activeAbortControllers so cancellation reaches the right signal.

Example fix

// before
try {
  await agentExecutor.execute(requestContext, eventBus);
} catch (e) {
  logger.error('Execution failed', e);
}

// after
try {
  await agentExecutor.execute(requestContext, eventBus);
} else if (e instanceof Error && e.message === 'Execution aborted') {
  logger.info(`Task ${taskId} was aborted by cancel signal.`);
  publishTaskState(eventBus, taskId, 'canceled');
} else {
  logger.error('Execution failed', e);
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Check before entering the loop / before delegating to execute:
if (abortSignal?.aborted) {
  publishTaskState(eventBus, taskId, 'canceled');
  return;
}
await agentExecutor.execute(requestContext, eventBus);

Try / catch

try {
  await agentExecutor.execute(requestContext, eventBus);
} catch (e) {
  if (e instanceof Error && e.message === 'Execution aborted' && abortSignal?.aborted) {
    logger.info(`Task ${taskId} canceled by client.`);
    publishTaskState(eventBus, taskId, 'canceled');
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Client sends a tasks/cancel (or the SDK cancels) for an in-flight task while the executor is between turns; the abort controller for the task is aborted, and on the next iteration of `while (agentTurnActive)` the check at line 743 fires. Also occurs when a primary-execution race aborts a secondary loop.

Common situations: User hits stop/cancel in a UI mid-run; a duplicate message for the same task triggers the explicit-cancel path for the prior in-flight run; abort signal wired from request timeout.

Related errors


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