alibaba/arthas · warning · McpError

-32602

-32602

Error message

Task not found or not accessible

What it means

Thrown by DefaultTaskManager during task cancellation when taskStore.requestCancellation(taskId, sessionId) resolves to null, meaning no task was found for that ID and session. It builds a McpError with ErrorCodes.INVALID_PARAMS (-32602) and the task ID as data. It is distinct from the 'missing taskId parameter' guard that runs earlier in the same method.

Source

Thrown at arthas-mcp-server/src/main/java/com/taobao/arthas/mcp/server/task/DefaultTaskManager.java:646

            failed.completeExceptionally(McpError.builder(McpSchema.ErrorCodes.INTERNAL_ERROR)
                    .message("TaskStore not configured")
                    .build());
            return failed;
        }

        String taskId = extractTaskIdFromParams(requestParams);
        if (taskId == null) {
            CompletableFuture<McpSchema.Result> failed = new CompletableFuture<>();
            failed.completeExceptionally(McpError.builder(McpSchema.ErrorCodes.INVALID_PARAMS)
                    .message("Missing required parameter: taskId")
                    .build());
            return failed;
        }

        return this.taskStore.requestCancellation(taskId, ctx.sessionId())
                .thenApply(task -> {
                    if (task == null) {
                        throw new CompletionException(
                                McpError.builder(McpSchema.ErrorCodes.INVALID_PARAMS)
                                        .message("Task not found or not accessible")
                                        .data("Task ID: " + taskId)
                                        .build());
                    }
                    return (McpSchema.Result) McpSchema.CancelTaskResult.fromTask(task);
                });
    }

    private String extractTaskIdFromParams(Object params) {
        return extractStringFromParams(params, "taskId");
    }

    private String extractCursorFromParams(Object params) {
        return extractStringFromParams(params, "cursor");
    }

    @SuppressWarnings("unchecked")

View on GitHub (pinned to 21cf2e9ba5)

Solutions

  1. Before cancelling, verify the task exists via the get/poll API for the current session.
  2. Treat 'not found' on cancel as a benign no-op on the client side (the task is already gone).
  3. Ensure the cancel request carries the correct sessionId that owns the task.
  4. Avoid caching taskIds across long periods; re-query when needed.

Example fix

// before
manager.cancelTask(paramsWithStaleId).join(); // INVALID_PARAMS

// after
manager.getTaskState(taskId, sessionId)
    .thenCompose(state -> state == null
        ? CompletableFuture.completedFuture(null) // already gone, ignore
        : manager.cancelTask(paramsWithCurrentId))
    .join();
Defensive patterns

Strategy: validation

Validate before calling

// Verify the task exists for this session before cancelling
manager.getTaskState(taskId, sessionId).thenCompose(state -> {
    if (state == null) return CompletableFuture.completedFuture(null);
    return manager.cancelTask(paramsWithCurrentId);
}).join();

Try / catch

try {
    manager.cancelTask(params).join();
} catch (CompletionException e) {
    Throwable c = e.getCause();
    if (c instanceof McpError me && me.getMessage().contains("not found or not accessible")) {
        // benign: task already gone
        return;
    }
    throw e;
}

Prevention

When it happens

Trigger: A client sends a cancel request for a taskId that does not exist, has expired (TTL), belongs to another session, or was already terminal and removed; a typo or stale taskId in the cancel payload.

Common situations: Client cancels after the task already finished/expired; cross-session cancellation attempt; stale taskId cached client-side after restart; race between completion and cancellation.

Related errors


AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14). Data as JSON: /api/errors/3b35eecace2e0004. Report an issue: GitHub.