{"record":{"id":"ac9c5819f13d4b08","repo":"rtk-ai/rtk","slug":"failed-to-query-first-seen-timestamp-e","errorCode":null,"errorMessage":"Failed to query first seen timestamp: {e}","messagePattern":"Failed to query first seen timestamp: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/core/tracking.rs","lineNumber":1354,"sourceCode":"        let pattern = format!(\"rtk {}\", name);\n        let count: i64 = self.conn.query_row(\n            \"SELECT COUNT(*) FROM commands WHERE rtk_cmd LIKE ?1 || '%'\",\n            params![pattern],\n            |row| row.get(0),\n        )?;\n        Ok(count)\n    }\n\n    /// Days since first recorded command (installation age).\n    pub fn first_seen_days(&self) -> Result<i64> {\n        let oldest: Option<String> =\n            match self\n                .conn\n                .query_row(\"SELECT MIN(timestamp) FROM commands\", [], |row| row.get(0))\n            {\n                Ok(v) => v,\n                Err(rusqlite::Error::QueryReturnedNoRows) => None,\n                Err(e) => return Err(anyhow::anyhow!(\"Failed to query first seen timestamp: {e}\")),\n            };\n        match oldest {\n            Some(ts) => {\n                let first = chrono::NaiveDateTime::parse_from_str(&ts, \"%Y-%m-%dT%H:%M:%S\")\n                    .or_else(|_| chrono::NaiveDateTime::parse_from_str(&ts, \"%Y-%m-%d %H:%M:%S\"))\n                    .map(|dt| dt.and_utc())\n                    .unwrap_or_else(|_| chrono::Utc::now());\n                let days = (chrono::Utc::now() - first).num_days();\n                Ok(days.max(0))\n            }\n            None => Ok(0),\n        }\n    }\n\n    /// Number of distinct active days in the last 30 days.\n    pub fn active_days_30d(&self) -> Result<i64> {\n        let since = (chrono::Utc::now() - chrono::Duration::days(30))\n            .format(\"%Y-%m-%dT%H:%M:%S\")","sourceCodeStart":1336,"sourceCodeEnd":1372,"githubUrl":"https://github.com/rtk-ai/rtk/blob/36788f6bd4932037caac5cbb1d15d6e2fb9f33da/src/core/tracking.rs#L1336-L1372","documentation":"The SQLite query selecting MIN(timestamp) from the commands table returned an unexpected error while computing installation age (first_seen_days). The input at fault is the tracking database (rtk's SQLite store); this indicates schema drift, corruption, or an I/O problem rather than user misuse.","triggerScenarios":"Thrown at src/core/tracking.rs:1354 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the full SQLite error chained in the context for the failing constraint or I/O reason","Run rtk gain to see if other queries against the same database succeed","Reset or recreate the tracking database (deleting the rtk SQLite file) if it is corrupted — history is lost but functionality is restored"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"36788f6bd4932037caac5cbb1d15d6e2fb9f33da","analyzedAt":"2026-09-03T16:33:57.738Z","contentChangedAt":"2026-09-03T16:33:57.738Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}