Add tool_traces table to Ava SQLite db

t-272.1·WorkTask·
·
·
Parent:t-272·Created2 months ago·Updated2 months ago

Description

Edit

Create new table in Ava's SQLite db for storing tool traces.

Context

Ava already uses SQLite for various storage. The db is at $AVA_DATA_ROOT/ava.db (typically /home/ava/ava.db). Look at existing table creation patterns in the codebase.

Schema

CREATE TABLE tool_traces ( id TEXT PRIMARY KEY, -- UUID, e.g. 'trace-550e8400-e29b-41d4-a716-446655440000' created_at TEXT NOT NULL, -- ISO8601 timestamp tool_name TEXT NOT NULL, -- e.g. 'python_exec', 'run_bash', 'read_file' input TEXT NOT NULL, -- JSON string of tool input output TEXT NOT NULL, -- JSON string of tool output duration_ms INTEGER NOT NULL, -- Execution time in milliseconds user_id TEXT, -- Telegram user ID (optional, for filtering) chat_id TEXT -- Telegram chat ID (optional, for filtering) );

CREATE INDEX idx_traces_created ON tool_traces(created_at);

Implementation

1. Add migration/table creation in Omni/Ava.hs or wherever DB is initialized 2. Create helper functions:

  • insertTrace :: Connection -> TraceRecord -> IO Text (returns trace ID)
  • getTrace :: Connection -> Text -> IO (Maybe TraceRecord)
  • cleanupOldTraces :: Connection -> IO Int (delete traces older than 7 days, return count)

3. Add TraceRecord data type in appropriate module

Cleanup Job

Call cleanupOldTraces periodically (e.g., on startup and every hour). Can use a simple approach - no need for a separate thread, just clean on each insert or on startup.

Testing

Add unit tests for insert/get/cleanup functions.

Files to Modify

  • Omni/Ava.hs or create Omni/Ava/Db.hs for trace storage functions
  • Look at existing SQLite usage patterns in the codebase (grep for 'sqlite' or 'Database.SQLite')

Timeline (1)

🔄[human]Open → Done2 months ago