rtk-ai/rtk · error

Failed to query first seen timestamp: {e}

Error message

Failed to query first seen timestamp: {e}

What it means

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.

Source

Thrown at src/core/tracking.rs:1354

        let pattern = format!("rtk {}", name);
        let count: i64 = self.conn.query_row(
            "SELECT COUNT(*) FROM commands WHERE rtk_cmd LIKE ?1 || '%'",
            params![pattern],
            |row| row.get(0),
        )?;
        Ok(count)
    }

    /// Days since first recorded command (installation age).
    pub fn first_seen_days(&self) -> Result<i64> {
        let oldest: Option<String> =
            match self
                .conn
                .query_row("SELECT MIN(timestamp) FROM commands", [], |row| row.get(0))
            {
                Ok(v) => v,
                Err(rusqlite::Error::QueryReturnedNoRows) => None,
                Err(e) => return Err(anyhow::anyhow!("Failed to query first seen timestamp: {e}")),
            };
        match oldest {
            Some(ts) => {
                let first = chrono::NaiveDateTime::parse_from_str(&ts, "%Y-%m-%dT%H:%M:%S")
                    .or_else(|_| chrono::NaiveDateTime::parse_from_str(&ts, "%Y-%m-%d %H:%M:%S"))
                    .map(|dt| dt.and_utc())
                    .unwrap_or_else(|_| chrono::Utc::now());
                let days = (chrono::Utc::now() - first).num_days();
                Ok(days.max(0))
            }
            None => Ok(0),
        }
    }

    /// Number of distinct active days in the last 30 days.
    pub fn active_days_30d(&self) -> Result<i64> {
        let since = (chrono::Utc::now() - chrono::Duration::days(30))
            .format("%Y-%m-%dT%H:%M:%S")

View on GitHub (pinned to 36788f6bd4)

Solutions

  1. Inspect the full SQLite error chained in the context for the failing constraint or I/O reason
  2. Run rtk gain to see if other queries against the same database succeed
  3. Reset or recreate the tracking database (deleting the rtk SQLite file) if it is corrupted — history is lost but functionality is restored
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at src/core/tracking.rs:1354 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rtk-ai/rtk@36788f6bd4 (2026-09-03). Data as JSON: /api/errors/ac9c5819f13d4b08. Report an issue: GitHub.