Skip to content

feat(trace): persist per-prompt traces to SQLite + query API#233

Open
a-yeyang wants to merge 6 commits into
scitix:mainfrom
a-yeyang:yye-feat-trace
Open

feat(trace): persist per-prompt traces to SQLite + query API#233
a-yeyang wants to merge 6 commits into
scitix:mainfrom
a-yeyang:yye-feat-trace

Conversation

@a-yeyang
Copy link
Copy Markdown
Contributor

Summary

Per-prompt agent traces (previously written only to .siclaw/traces/*.json) are
now also persisted to a local SQLite DB, with a Gateway-served query API. Enables
cross-session retrospective and slow-task audits without scanning files.

What's added

  • .siclaw/traces.sqlite — standalone node:sqlite store (lazy-loaded; on
    Node <22.13 without --experimental-sqlite, gracefully degrades to file-only).
  • Schema: INTEGER PRIMARY KEY AUTOINCREMENT clustered id +
    trace_key TEXT UNIQUE (business key, matches the on-disk filename stem).
    Beijing-time TEXT columns started_at / ended_at / created_at
    (YYYY-MM-DD HH:mm:ss.SSS). Indexes on (user_id, started_at),
    (started_at), (session_id, prompt_idx).
  • Auto-migrations via PRAGMA user_version (v1 → v2 → v3), in-place,
    preserves all existing rows.
  • Query API on Gateway (:3000, eager-start — no AgentBox spawn needed):
    • GET /api/traces — filters: username, userId, lastHours, lastDays,
      from, to, minDurationMs, outcome, limit. Keyset pagination via
      cursorStartedAt + cursorId.
    • GET /api/traces/:traceKey — full JSON body (byte-identical to disk file).

Usage

# Slow tasks (>60s) in the last 3 hours
curl 'http://localhost:3000/api/traces?lastHours=3&minDurationMs=60000' | jq

# Full body for one trace
curl 'http://localhost:3000/api/traces/trace-20260422-11-07-57-admin' | jq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant