{"record":{"id":"b07d7bf57bbc029a","repo":"alibaba/arthas","slug":"32602-b07d7b","errorCode":"-32602","errorMessage":"Task not found (may have expired after TTL): {}","messagePattern":"Task not found \\(may have expired after TTL\\): (.+?)","errorType":"error_code","errorClass":"McpError","httpStatus":null,"severity":"error","filePath":"arthas-mcp-server/src/main/java/com/taobao/arthas/mcp/server/task/InMemoryTaskStore.java","lineNumber":275,"sourceCode":"                    wasTerminal.set(true);\n                    return entry;\n                }\n                results.put(taskId, result);\n                String now = Instant.now().toString();\n                McpSchema.Task newTask = McpSchema.Task.builder()\n                    .taskId(oldTask.getTaskId())\n                    .status(status)\n                    .createdAt(oldTask.getCreatedAt())\n                    .lastUpdatedAt(now)\n                    .ttl(oldTask.getTtl())\n                    .pollInterval(oldTask.getPollInterval())\n                    .build();\n                logger.debug(\"Stored result for task: {}\", taskId);\n                return new TaskEntry(newTask, entry.originatingRequest(), entry.context(), entry.sessionId());\n            });\n\n            if (!taskFound.get()) {\n                throw new CompletionException(\n                    McpError.builder(McpSchema.ErrorCodes.INVALID_PARAMS)\n                        .message(\"Task not found (may have expired after TTL): \" + taskId)\n                        .build()\n                );\n            }\n            if (!sessionValid.get()) {\n                throw new CompletionException(\n                    McpError.builder(McpSchema.ErrorCodes.INVALID_PARAMS)\n                        .message(\"Task not found (may have expired after TTL): \" + taskId)\n                        .build()\n                );\n            }\n            if (wasTerminal.get()) {\n                logger.debug(\"Skipped storing result for task {} - already in terminal state\", taskId);\n            }\n        });\n    }\n","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/arthas-mcp-server/src/main/java/com/taobao/arthas/mcp/server/task/InMemoryTaskStore.java#L257-L293","documentation":"Thrown by InMemoryTaskStore during result storage (the storeResult/update path) when the target taskId is not present in the tasks map (taskFound.get() is false after the compute-if-present block). It builds a McpError with ErrorCodes.INVALID_PARAMS (-32602). The message notes the task may have expired after its TTL, distinguishing a 'never existed or evicted' case from a session-mismatch case.","triggerScenarios":"A task handler tries to store a result for a taskId that was evicted by TTL before completion, or for a taskId that was never created in this store; late result delivery after expiry.","commonSituations":"Long-running task whose result arrives after TTL eviction; result posted to the wrong store instance; store restart losing in-memory state; handler holding a stale taskId.","solutions":["Ensure task completion stores results well within the configured TTL window.","Increase the task TTL to exceed the handler's realistic completion time.","Confirm the result is stored against the same TaskStore instance and taskId used at creation.","For durability across restarts, use a persistent TaskStore instead of the in-memory one."],"exampleFix":"// before\nLong ttl = Duration.ofSeconds(10).toMillis(); // shorter than task runtime\nstore.createTask(opts.withRequestedTtl(ttl));\n// ... later, after expiry\nstore.storeResult(taskId, result); // INVALID_PARAMS\n\n// after\nLong ttl = Duration.ofMinutes(10).toMillis(); // exceeds runtime\nstore.createTask(opts.withRequestedTtl(ttl));\nstore.storeResult(taskId, result); // ok","handlingStrategy":"validation","validationCode":"// Ensure TTL exceeds the handler's realistic completion time\nlong ttl = Math.max(defaultTtl, estimatedMaxRuntimeMillis * 3);\noptions = options.withRequestedTtl(ttl);\nstore.createTask(options);","typeGuard":null,"tryCatchPattern":"try {\n    store.storeResult(taskId, result).join();\n} catch (CompletionException e) {\n    Throwable c = e.getCause();\n    if (c instanceof McpError me && me.getMessage().contains(\"expired after TTL\")) {\n        // task was evicted; recreate or report stale, do not loop\n        logger.warn(\"Task {} expired before result stored\", taskId);\n        return;\n    }\n    throw e;\n}","preventionTips":["Store results well within the TTL window.","Set TTL larger than the handler's worst case.","Confirm you use the same store instance and taskId.","Use a persistent store if the process may restart mid-task."],"tags":["mcp","task","ttl","in-memory-store","invalid-params","java"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}