tinyhumansai/openhuman · error

failed to prepare mcp_writes list query

Error message

failed to prepare mcp_writes list query

What it means

The runtime could not prepare the SQL statement for the paginated mcp_writes list query (dynamic SQL assembled with bound limit/offset). Wrapped in anyhow context 'failed to prepare mcp_writes list query', it surfaces to the RPC caller. Preparation fails when the generated SQL is invalid for the schema (e.g. after a schema drift where a column the query references no longer exists) or the connection is broken. The faulting input is the dynamically composed SELECT built from filter/bound parameters.

Source

Thrown at src/openhuman/mcp/audit/store.rs:168

        bound.push(Box::new(offset));
        log::trace!(
            "[mcp_audit] list_writes sql={} bound_count={} limit={} offset={}",
            sql,
            bound.len(),
            limit,
            offset
        );

        let refs = bound
            .iter()
            .map(|value| value.as_ref() as &dyn ToSql)
            .collect::<Vec<_>>();
        log::trace!("[mcp_audit] list_writes preparing query");
        let mut stmt = match conn.prepare(&sql) {
            Ok(stmt) => stmt,
            Err(err) => {
                log::warn!("[mcp_audit] list_writes prepare failed error={err}");
                return Err(anyhow::Error::new(err))
                    .context("failed to prepare mcp_writes list query");
            }
        };
        log::trace!("[mcp_audit] list_writes executing query");
        let mapped = match stmt.query_map(refs.as_slice(), row_to_record) {
            Ok(mapped) => mapped,
            Err(err) => {
                log::warn!("[mcp_audit] list_writes query failed error={err}");
                return Err(anyhow::Error::new(err)).context("failed to query mcp_writes");
            }
        };
        let rows = match mapped.collect::<rusqlite::Result<Vec<_>>>() {
            Ok(rows) => rows,
            Err(err) => {
                log::warn!("[mcp_audit] list_writes collect failed error={err}");
                return Err(anyhow::Error::new(err)).context("failed to collect mcp_writes rows");
            }
        };

View on GitHub (pinned to 7491200858)

Solutions

  1. Verify the mcp_writes schema matches the query's expected columns; re-run schema init/migration
  2. Inspect the generated SQL in the preceding trace log ([mcp_audit] list_writes sql=...) for malformed fragments from filter composition
  3. Recreate or repair the audit database if the connection is corrupted
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at src/openhuman/mcp/audit/store.rs:168 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tinyhumansai/openhuman@7491200858 (2026-08-17). Data as JSON: /api/errors/5f45a4684eaf941d. Report an issue: GitHub.