{"record":{"id":"5fb6711e858fd484","repo":"t8y2/dbx","slug":"tdengine-query-session-not-found-session-id","errorCode":null,"errorMessage":"TDengine query session not found: {session_id}","messagePattern":"TDengine query session not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/tdengine/src/driver.rs","lineNumber":377,"sourceCode":"            self.query_sessions.insert(session_id, cursor);\n        }\n        page.execution_time_ms = start.elapsed().as_millis() as i64;\n        if may_change_metadata(&options.sql) {\n            self.table_cache = None;\n        }\n        Ok(page)\n    }\n\n    pub async fn fetch_query_page(\n        &mut self,\n        session_id: &str,\n        page_size: usize,\n        timeout_secs: u64,\n        token: &CancellationToken,\n    ) -> Result<QueryPageResult> {\n        self.expire_query_sessions();\n        let Some(mut cursor) = self.query_sessions.remove(session_id) else {\n            bail!(\"TDengine query session not found: {session_id}\");\n        };\n        cursor.last_accessed_at = Instant::now();\n        let page_size = normalized_page_size(page_size, 0, cursor.remaining_limit().max(1));\n        let mut page = read_cursor_page(&mut cursor, page_size, token, timeout_secs).await?;\n        let (has_more, truncated) = cursor.prepare_next_page(token, timeout_secs).await?;\n        page.truncated = truncated;\n        if has_more {\n            page.session_id = Some(session_id.to_string());\n            page.has_more = true;\n            self.query_sessions.insert(session_id.to_string(), cursor);\n        }\n        Ok(page)\n    }\n\n    pub fn close_query_session(&mut self, session_id: &str) -> bool {\n        self.query_sessions.remove(session_id).is_some()\n    }\n","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/tdengine/src/driver.rs#L359-L395","documentation":"fetch_query_page continues a paged query by looking up a server-side cursor stored under the given session_id in an in-process session map. If no such session exists (expired, evicted by expire_query_sessions, never created, or from a different process/restart), it errors. Sessions are held in memory, so they do not survive process restarts or expiry.","triggerScenarios":"Requesting the next page with a session_id that was never returned by a prior query, reusing a session after its TTL expired (expire_query_sessions removed it), or after the agent process restarted.","commonSituations":"Long pauses between page fetches exceeding the session TTL, load-balanced deployments where page requests hit a different agent instance, or app restarts while a client holds a paging token.","solutions":["Re-run the original query to obtain a fresh session_id and re-fetch from page 1","Fetch pages promptly before the session TTL expires","Ensure all page requests for one query go to the same agent instance (sticky routing) and avoid restarts mid-pagination"],"exampleFix":"// before\nlet page = driver.fetch_query_page(&stale_session_id, page_size, timeout, &token).await?;\n// after\nlet page = match driver.fetch_query_page(&session_id, page_size, timeout, &token).await {\n    Ok(p) => p,\n    Err(_) if session_gone => { let s = driver.execute_query_page(&sql, ...).await?; /* use new session */ }\n    Err(e) => return Err(e),\n};","handlingStrategy":"retry","validationCode":"// track session freshness client-side\nif session.last_used.elapsed() > SESSION_TTL / 2 { reissue_session(); }","typeGuard":null,"tryCatchPattern":"match driver.fetch_query_page(&session_id, size, timeout, &token).await {\n    Err(e) if e.to_string().contains(\"session not found\") => restart_query_from_page_one(),\n    other => other,\n}","preventionTips":["Re-issue sessions after agent restarts","Use sticky routing for paged requests","Fetch pages faster than the session TTL"],"tags":["rust","tdengine","pagination","session","state"],"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"}