{"record":{"id":"c73cecf7fbd9e92d","repo":"t8y2/dbx","slug":"agent-session-not-found-id","errorCode":null,"errorMessage":"agent session not found: {id}","messagePattern":"agent session not found: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/tdengine/src/runtime.rs","lineNumber":257,"sourceCode":"            .map_err(|_| anyhow!(\"agent session limit reached: {MAX_AGENT_SESSIONS}\"))?;\n        let mut driver = TdengineDriver::new();\n        driver.connect(params).await?;\n        let session = Arc::new(AgentSession {\n            driver: Mutex::new(driver),\n            active: StdMutex::new(None),\n            next_operation_id: AtomicU64::new(1),\n            _slot: slot,\n        });\n        let mut sessions = self.sessions.write().await;\n        if sessions.contains_key(id) {\n            bail!(\"agent session already exists: {id}\");\n        }\n        sessions.insert(id.to_string(), session);\n        Ok(())\n    }\n\n    async fn session(&self, id: &str) -> Result<Arc<AgentSession>> {\n        self.sessions.read().await.get(id).cloned().ok_or_else(|| anyhow!(\"agent session not found: {id}\"))\n    }\n\n    async fn close_session(&self, id: &str) -> Result<()> {\n        let session = self.sessions.write().await.remove(id);\n        let Some(session) = session else {\n            return Ok(());\n        };\n        session.cancel();\n        session.driver.lock().await.disconnect().await;\n        Ok(())\n    }\n\n    async fn close_all_sessions(&self) {\n        let sessions = {\n            let mut sessions = self.sessions.write().await;\n            std::mem::take(&mut *sessions)\n        };\n        for (_, session) in sessions {","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/tdengine/src/runtime.rs#L239-L275","documentation":"Thrown by the session lookup helper in the TDengine agent driver's runtime when `session(id)` is called with an id that has no entry in the in-memory sessions map. Sessions only exist after `create_session`/registration inserts them, and `close_session` removes them, so lookups of closed or never-created ids fail. The message includes the offending id to make debugging straightforward.","triggerScenarios":"Calling an agent-runtime method that resolves a session by id when: (1) the id was never created via the session creation path, (2) `close_session(id)` already removed it, (3) the caller passes a stale or typo'd id, or (4) the process restarted and in-memory sessions were lost.","commonSituations":"Reusing a cached session handle after closing the session; sharing ids between processes (sessions are in-memory, not persisted); race conditions where one task closes a session while another still uses it; service restart dropping all session state while clients still hold old ids.","solutions":["Verify the session id passed to the API matches one returned by the session-creation call.","Recreate the session via the create-session API before retrying the operation.","Ensure `close_session` is not called while other tasks still reference the session id.","If ids must survive restarts, add an external session store instead of relying on in-memory state."],"exampleFix":"// before\nlet session = runtime.session(\"sess-123\").await?; // may be stale\n// after\nlet session = match runtime.session(\"sess-123\").await {\n    Ok(s) => s,\n    Err(_) => runtime.create_session(params).await?, // recreate and use new id\n};","handlingStrategy":"try-catch","validationCode":"async fn session_exists(runtime: &dyn AgentRuntime, id: &str) -> bool {\n    !id.trim().is_empty() && runtime.session(id).await.is_ok()\n}","typeGuard":null,"tryCatchPattern":"match runtime.session(id).await {\n    Ok(session) => use_session(session).await,\n    Err(e) if e.to_string().starts_with(\"agent session not found\") => {\n        let session = runtime.create_session(default_params()).await?;\n        use_session(session).await\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Store the session id returned at creation time, never a hand-typed id.","Guard against concurrent close: don't close a session while other tasks hold its id.","Treat process restarts as invalidating all session ids.","Centralize session access behind a helper that recreates on miss."],"tags":["session","not-found","rust","runtime"],"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"}