{"record":{"id":"6def7e7c4138f9b1","repo":"t8y2/dbx","slug":"query-session-not-found-sessionid","errorCode":null,"errorMessage":"Query session not found: {sessionId}","messagePattern":"Query session not found: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agents/common/src/main/java/com/dbx/agent/JdbcExecutor.java","lineNumber":706,"sourceCode":"            result.append(Character.forDigit((b >> 4) & 0xF, 16));\n            result.append(Character.forDigit(b & 0xF, 16));\n        }\n        return result.toString();\n    }\n\n    private static String sqlXmlToString(SQLXML value) throws SQLException {\n        return value == null ? null : value.getString();\n    }\n\n    private QueryPageResult fetchSessionPage(\n        ConcurrentHashMap<String, QuerySession> targetSessions,\n        String sessionId,\n        int pageSize,\n        String missingMessage\n    ) {\n        QuerySession session = targetSessions.get(sessionId);\n        if (session == null) {\n            throw new IllegalArgumentException(missingMessage);\n        }\n        synchronized (session) {\n            try {\n                return readSessionPage(targetSessions, session, pageSize, 0L);\n            } catch (RuntimeException | Error error) {\n                closeSession(targetSessions, sessionId);\n                throw error;\n            }\n        }\n    }\n\n    private QueryPageResult readSessionPage(\n        ConcurrentHashMap<String, QuerySession> targetSessions,\n        QuerySession session,\n        int pageSize,\n        long executionTimeMs\n    ) {\n        return unchecked(() -> {","sourceCodeStart":688,"sourceCodeEnd":724,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/common/src/main/java/com/dbx/agent/JdbcExecutor.java#L688-L724","documentation":"JdbcExecutor throws IllegalArgumentException when a query-session lookup by sessionId finds no entry in the target session map. Sessions are created lazily by read methods and removed on close/expiration, so this indicates the caller referenced a session that the executor no longer tracks. The custom missingMessage lets each caller produce a specific 'Query session not found: {sessionId}' style message.","triggerScenarios":"Calling a paginated read API (e.g. query results paging) with a sessionId that was never created, was already closed (explicit close, cleanup, or session expiry), or that belongs to a different executor instance. Also occurs after closeSession ran as part of error recovery for a previous page read.","commonSituations":"Client restarts or reconnects and reuses a stale sessionId; sessions evicted by maintenance/cleanup between page fetches; copying a sessionId across agent sessions in multi-session mode; page reads after calling the close-session method.","solutions":["Re-issue the original query to obtain a fresh sessionId, then page through results without gaps","Check that the sessionId was not closed and that page fetches happen before session expiry/cleanup","Ensure the same JdbcExecutor instance (or same agent session) is used for creating and reading the session","On receiving this error, treat the session as gone and restart pagination from row 0"],"exampleFix":"// before\nPage page = executor.readPage(sessionId, 100);\n// after\nPage page;\ntry {\n    page = executor.readPage(sessionId, 100);\n} catch (IllegalArgumentException e) {\n    sessionId = executor.executeQuery(sql); // recreate session\n    page = executor.readPage(sessionId, 100);\n}","handlingStrategy":"try-catch","validationCode":"// caller-side: only use IDs obtained from a live query and not yet consumed/closed\nif (sessionId == null || !activeSessions.contains(sessionId)) {\n    sessionId = executor.executeQuery(sql); // recreate before paging\n}","typeGuard":"boolean sessionAlive(String id) { return id != null && activeSessions.contains(id); }","tryCatchPattern":"try {\n    page = executor.readPage(sessionId, pageSize);\n} catch (IllegalArgumentException e) {\n    sessionId = executor.executeQuery(sql); // session lost: restart pagination\n    page = executor.readPage(sessionId, pageSize);\n}","preventionTips":["Never cache query session IDs across reconnects or agent restarts","Page through results promptly, before session cleanup/expiry","Close sessions explicitly when done to avoid stale IDs","Wrap pagination loops with recreate-on-missing logic"],"tags":["jdbc","session-management","illegal-argument"],"backgroundTag":"session-not-found","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}