{"record":{"id":"4162144de7aa98b2","repo":"alibaba/arthas","slug":"sessionid-is-required-for-this-operation","errorCode":null,"errorMessage":"SessionId is required for this operation","messagePattern":"SessionId is required for this operation","errorType":"exception","errorClass":"SessionNotFoundException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/taobao/arthas/core/command/CommandExecutorImpl.java","lineNumber":57,"sourceCode":" */\npublic class CommandExecutorImpl implements CommandExecutor {\n    private static final Logger logger = LoggerFactory.getLogger(CommandExecutorImpl.class);\n    private static final String ONETIME_SESSION_KEY = \"oneTimeSession\";\n    \n    private final SessionManager sessionManager;\n    private final JobController jobController;\n    private final InternalCommandManager commandManager;\n\n    public CommandExecutorImpl(SessionManager sessionManager) {\n        this.sessionManager = sessionManager;\n        this.commandManager = sessionManager.getCommandManager();\n        this.jobController = sessionManager.getJobController();\n    }\n\n    public Session getCurrentSession(String sessionId, boolean oneTimeIsAllowed) {\n        if (sessionId == null || sessionId.trim().isEmpty()) {\n            if (!oneTimeIsAllowed) {\n                throw new SessionNotFoundException(\"SessionId is required for this operation\");\n            }\n\n            Session session = sessionManager.createSession();\n            if (session == null) {\n                throw new SessionNotFoundException(\"Failed to create temporary session\");\n            }\n            session.put(ONETIME_SESSION_KEY, new Object());\n            logger.debug(\"Created one-time session {}\", session.getSessionId());\n            return session;\n        } else {\n            Session session = sessionManager.getSession(sessionId);\n            if (session == null) {\n                throw new SessionNotFoundException(\"Session not found: \" + sessionId);\n            }\n            sessionManager.updateAccessTime(session);\n            logger.debug(\"Using existing session {}\", sessionId);\n            return session;\n        }","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/core/src/main/java/com/taobao/arthas/core/command/CommandExecutorImpl.java#L39-L75","documentation":"Thrown as SessionNotFoundException by CommandExecutorImpl.getCurrentSession when the caller supplied a blank/null sessionId AND one-time sessions are not allowed for this operation (oneTimeIsAllowed == false). The executor requires a real session id for stateful commands; only explicitly whitelisted one-time commands may run without one.","triggerScenarios":"Call CommandExecutorImpl with a null, empty, or whitespace-only sessionId while oneTimeIsAllowed=false. Common with HTTP/programmatic callers that omit the sessionId header/param for a stateful command (watch, trace, monitor, dashboard, etc.).","commonSituations":"Calling the Arthas HTTP API without a sessionId (or with an empty string); a client that drops the session cookie/param; chaining a stateful command without first opening a session.","solutions":["Open a session first (createSession) and pass the returned sessionId on every stateful call.","If the command is genuinely one-shot, ensure it is routed through the one-time-allowed code path.","Validate/normalize sessionId on the client side and surface a clear error to the user instead of sending blank."],"exampleFix":"// before\nexecutor.execute(commandLine, timeout, null /*sessionId*/, false);\n\n// after\nString sid = sessionManager.createSession().getSessionId();\nexecutor.execute(commandLine, timeout, sid, false);","handlingStrategy":"validation","validationCode":"if (sessionId == null || sessionId.trim().isEmpty()) {\n    sessionId = sessionManager.createSession().getSessionId();\n}","typeGuard":"static boolean isBlankSessionId(String s) { return s == null || s.trim().isEmpty(); }","tryCatchPattern":"try {\n    Session s = executor.getCurrentSession(sessionId, false);\n} catch (SessionNotFoundException e) {\n    // open a session and retry with the new id\n}","preventionTips":["Always open a session first for stateful commands and thread the id through.","Validate sessionId is non-blank on the client before sending.","Whitelist which commands are truly one-time."],"tags":["session","api-contract","command-execution"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}