{"record":{"id":"3b35eecace2e0004","repo":"alibaba/arthas","slug":"32602","errorCode":"-32602","errorMessage":"Task not found or not accessible","messagePattern":"Task not found or not accessible","errorType":"error_code","errorClass":"McpError","httpStatus":null,"severity":"warning","filePath":"arthas-mcp-server/src/main/java/com/taobao/arthas/mcp/server/task/DefaultTaskManager.java","lineNumber":646,"sourceCode":"            failed.completeExceptionally(McpError.builder(McpSchema.ErrorCodes.INTERNAL_ERROR)\n                    .message(\"TaskStore not configured\")\n                    .build());\n            return failed;\n        }\n\n        String taskId = extractTaskIdFromParams(requestParams);\n        if (taskId == null) {\n            CompletableFuture<McpSchema.Result> failed = new CompletableFuture<>();\n            failed.completeExceptionally(McpError.builder(McpSchema.ErrorCodes.INVALID_PARAMS)\n                    .message(\"Missing required parameter: taskId\")\n                    .build());\n            return failed;\n        }\n\n        return this.taskStore.requestCancellation(taskId, ctx.sessionId())\n                .thenApply(task -> {\n                    if (task == null) {\n                        throw new CompletionException(\n                                McpError.builder(McpSchema.ErrorCodes.INVALID_PARAMS)\n                                        .message(\"Task not found or not accessible\")\n                                        .data(\"Task ID: \" + taskId)\n                                        .build());\n                    }\n                    return (McpSchema.Result) McpSchema.CancelTaskResult.fromTask(task);\n                });\n    }\n\n    private String extractTaskIdFromParams(Object params) {\n        return extractStringFromParams(params, \"taskId\");\n    }\n\n    private String extractCursorFromParams(Object params) {\n        return extractStringFromParams(params, \"cursor\");\n    }\n\n    @SuppressWarnings(\"unchecked\")","sourceCodeStart":628,"sourceCodeEnd":664,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/arthas-mcp-server/src/main/java/com/taobao/arthas/mcp/server/task/DefaultTaskManager.java#L628-L664","documentation":"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.","triggerScenarios":"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.","commonSituations":"Client cancels after the task already finished/expired; cross-session cancellation attempt; stale taskId cached client-side after restart; race between completion and cancellation.","solutions":["Before cancelling, verify the task exists via the get/poll API for the current session.","Treat 'not found' on cancel as a benign no-op on the client side (the task is already gone).","Ensure the cancel request carries the correct sessionId that owns the task.","Avoid caching taskIds across long periods; re-query when needed."],"exampleFix":"// before\nmanager.cancelTask(paramsWithStaleId).join(); // INVALID_PARAMS\n\n// after\nmanager.getTaskState(taskId, sessionId)\n    .thenCompose(state -> state == null\n        ? CompletableFuture.completedFuture(null) // already gone, ignore\n        : manager.cancelTask(paramsWithCurrentId))\n    .join();","handlingStrategy":"validation","validationCode":"// Verify the task exists for this session before cancelling\nmanager.getTaskState(taskId, sessionId).thenCompose(state -> {\n    if (state == null) return CompletableFuture.completedFuture(null);\n    return manager.cancelTask(paramsWithCurrentId);\n}).join();","typeGuard":null,"tryCatchPattern":"try {\n    manager.cancelTask(params).join();\n} catch (CompletionException e) {\n    Throwable c = e.getCause();\n    if (c instanceof McpError me && me.getMessage().contains(\"not found or not accessible\")) {\n        // benign: task already gone\n        return;\n    }\n    throw e;\n}","preventionTips":["Poll task status before cancelling; skip if absent or terminal.","Send the correct sessionId owning the task.","Treat cancel 'not found' as benign on the client.","Do not cache taskIds across restarts."],"tags":["mcp","task","cancellation","invalid-params","java"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}