{"record":{"id":"c1d3c7cdb04a4577","repo":"t8y2/dbx","slug":"query-session-not-found-s-c1d3c7","errorCode":null,"errorMessage":"query session not found: %s","messagePattern":"query session not found: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/neo4j-go/query.go","lineNumber":97,"sourceCode":"\t\t\tHasMore: false,\n\t\t}, nil\n\t}\n\tid := s.nextQuerySessionID()\n\ts.querySessions[id] = &querySession{\n\t\tsession: session, result: result, ctx: ctx, cancel: cancel,\n\t\tcolumns: columns, columnTypes: columnTypes, remaining: remaining,\n\t}\n\treturn queryPageResult{\n\t\tColumns: columns, ColumnTypes: columnTypes, Rows: rows,\n\t\tExecutionTimeMS: time.Since(started).Milliseconds(), SessionID: &id, HasMore: true,\n\t}, nil\n}\n\nfunc (s *server) fetchQueryPage(id string, pageSize int) (queryPageResult, error) {\n\tstarted := time.Now()\n\tquery := s.querySessions[id]\n\tif query == nil {\n\t\treturn queryPageResult{}, fmt.Errorf(\"query session not found: %s\", id)\n\t}\n\tif pageSize <= 0 {\n\t\tpageSize = defaultPageSize\n\t}\n\tif pageSize > query.remaining {\n\t\tpageSize = query.remaining\n\t}\n\trows, _, _, hasMore, err := readResultPage(query.ctx, query.result, pageSize)\n\tif err != nil {\n\t\ts.closeQuerySession(id)\n\t\treturn queryPageResult{}, err\n\t}\n\tquery.remaining -= len(rows)\n\ttruncated := hasMore && query.remaining <= 0\n\tif !hasMore || query.remaining <= 0 {\n\t\ts.closeQuerySession(id)\n\t\treturn queryPageResult{\n\t\t\tColumns: query.columns, ColumnTypes: query.columnTypes, Rows: rows,","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/neo4j-go/query.go#L79-L115","documentation":"Paged query results are stored in per-session querySessions keyed by an id returned when the query was started. fetchQueryPage returns this error when asked to fetch the next page for an id that has no entry, typically because the query finished (all pages consumed), the session was closed, or the id is wrong.","triggerScenarios":"Calling fetchQueryPage with an id that was never returned by query start, an id from a closed query session, or an id whose entry was deleted after the final page was consumed (remaining == 0).","commonSituations":"Client paginating past the last page and reusing a freed id; caching query ids across an agent restart; mixing ids between two sessions; a client bug double-fetching the same completed query.","solutions":["Stop paginating once the result reports no remaining rows and do not call fetch again with that id","Re-run the query to obtain a fresh query session id if the old one is gone","Verify the id passed to fetch is the one returned by the query call for that same session","Check the agent process has not restarted (in-memory registry is lost)"],"exampleFix":"// before\nfor { page, err := fetch(id); if err != nil { return err } } // fetches past the end\n// after\nfor remaining > 0 {\n    page, err := fetch(id)\n    if err != nil { return err }\n    remaining -= len(page.Rows)\n}","handlingStrategy":"try-catch","validationCode":"// stop paginating when the previous page says no rows remain\nif queryState.remaining == 0 {\n    return io.EOF // do not call fetch again with this id\n}","typeGuard":null,"tryCatchPattern":"page, err := call(\"fetch\", map[string]any{\"id\": id, \"page_size\": n})\nif err != nil && strings.Contains(err.Error(), \"query session not found\") {\n    // id consumed or lost: restart the query rather than retrying the id\n    id, err = startQuery(origSQL)\n    if err != nil { return err }\n    page, err = call(\"fetch\", map[string]any{\"id\": id, \"page_size\": n})\n}\nreturn err","preventionTips":["Treat query session ids as single-use: drop after the final page","Never persist query ids across agent restarts","Track remaining rows client-side and stop at zero","Map each id to exactly one logical query to avoid cross-session mixups"],"tags":["neo4j","pagination","query","not-found"],"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"}