{"record":{"id":"fa9cadcb15ced18e","repo":"t8y2/dbx","slug":"query-session-not-found","errorCode":null,"errorMessage":"query session not found","messagePattern":"query session not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/argo-go/query.go","lineNumber":184,"sourceCode":"\t\t\tHasMore:         false,\n\t\t}, nil\n\t}\n\treturn queryPageResult{\n\t\tColumns:         columns,\n\t\tColumnTypes:     columnTypes,\n\t\tRows:            page,\n\t\tExecutionTimeMS: time.Since(started).Milliseconds(),\n\t\tTruncated:       false,\n\t\tSessionID:       &sessionID,\n\t\tHasMore:         true,\n\t}, nil\n}\n\nfunc (server *server) fetchQueryPage(sessionID string, requestedPageSize int) (queryPageResult, error) {\n\tserver.expireIdleQuerySessions(time.Now())\n\tstate := server.querySessions[sessionID]\n\tif state == nil {\n\t\treturn queryPageResult{}, errors.New(\"query session not found\")\n\t}\n\tpageSize := requestedPageSize\n\tif pageSize <= 0 {\n\t\tpageSize = defaultPageSize\n\t}\n\tctx := context.Background()\n\tserver.setActiveOperation(state.cancel)\n\tpage, hasMore, truncated, err := server.readQuerySessionPage(ctx, state, pageSize)\n\tserver.activeMu.Lock()\n\tserver.activeCancel = nil\n\tserver.activeMu.Unlock()\n\tif err != nil {\n\t\tserver.closeQuerySession(sessionID)\n\t\treturn queryPageResult{}, err\n\t}\n\tvar resultSessionID *string\n\tif hasMore {\n\t\tresultSessionID = &sessionID","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/argo-go/query.go#L166-L202","documentation":"fetchQueryPage looks up the paged-query state by sessionID in server.querySessions; if no entry exists it returns this error. The session either never existed, was already consumed/cancelled, or was removed by expireIdleQuerySessions after the idle timeout. The library cannot continue fetching results for an unknown session.","triggerScenarios":"Calling fetchQueryPage (the fetch-next-page path) with a sessionID that was never returned by executeQueryPage; fetching again after the final page was consumed; fetching after idle expiry removed the session; fetching after a cancel quarantined the session.","commonSituations":"Long-running paging loops that pause longer than the idle session TTL; reusing a stale session ID stored across requests in a web service; retrying a fetch after a network error without re-executing the statement; a second consumer replaying an already-drained session ID.","solutions":["Re-execute the original SQL to obtain a fresh session ID instead of reusing the old one","Complete all page fetches within the idle-session window; increase the idle timeout if paging is slow","Track the session ID lifecycle in your code and clear it once the result set is exhausted or cancelled","Check logs for session expiry/cancellation between execute and fetch"],"exampleFix":"// before\npage, err := fetchQueryPage(ctx, staleSessionID, 1000)\n// after\npage, err := fetchQueryPage(ctx, sessionID, 1000)\nif err != nil && strings.Contains(err.Error(), \"query session not found\") {\n    sessionID, page, err = restartQuery(ctx, sqlText) // re-run to get a new session\n}","handlingStrategy":"try-catch","validationCode":"// no pre-call check possible; track session lifecycle yourself\nif sessionID == \"\" || sessionConsumed[sessionID] {\n    return errors.New(\"cannot fetch: session already finished\")\n}","typeGuard":null,"tryCatchPattern":"page, err := fetchQueryPage(ctx, sessionID, size)\nif err != nil && strings.Contains(err.Error(), \"query session not found\") {\n    sessionID, page, err = restartQuery(ctx, sqlText) // re-execute to get a new session\n}","preventionTips":["Drain or cancel sessions within the idle TTL window","Clear stored session IDs once results are exhausted","Re-execute the statement on stale-session errors instead of retrying the fetch","Increase idle timeout for slow paging workloads"],"tags":["state","pagination","session-expired","hive","go"],"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-14T00:17:10.932Z"}