feat(session_db): add durable agent session database#3259
Conversation
Introduce a Rust-owned SQLite session store (WAL + FTS5) under `src/openhuman/session_db/` that captures sessions, messages, tool calls, cost/token metadata, and parent/child lineage. This makes agent history queryable by text, tool name, source channel, and lineage for UI inspection and diagnostics. Schema: sessions, session_messages, session_tool_calls tables with full-text search via FTS5. 7 JSON-RPC controllers registered under `openhuman.session_db_*` (list, get, search, get_messages, get_tool_calls, get_children, import_transcript). The existing `session_raw/*.jsonl` transcript files remain the source of truth for KV-cache resume — `import_transcript` indexes them into the session database without breaking resume semantics. 27 unit tests covering schema init, CRUD, FTS search, pagination, lineage queries, tool output truncation, and combined filters.
|
Warning Review limit reached
More reviews will be available in 52 minutes and 40 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
Comment |
Summary
session_dbdomain (src/openhuman/session_db/) with a SQLite-backed (WAL + FTS5) durable store for agent sessions, messages, tool calls, cost metadata, and parent/child lineage.openhuman.session_db_*for session listing, search, detail retrieval, and transcript import.session_raw/*.jsonltranscript files as the KV-cache resume source of truth — the session database is a queryable index layer on top.Problem
OpenHuman persists harness transcripts as flat JSONL files and keeps agent orchestration state process-local. This makes cross-session search, child-agent lifecycle recovery, compression lineage, and operational diagnostics harder than they need to be — especially for long-running, cron-triggered, or multi-agent work.
Solution
Introduce
src/openhuman/session_db/following the canonical module shape:mod.rstypes.rsSessionRecord,SessionMessage,SessionToolCall,SessionStatus,SessionSearchParams,SessionSearchResultstore.rsops.rsmark_interruptedschemas.rsops_tests.rsSchema (
{workspace}/session_db/sessions.db):sessions— root + sub-agent session records with cost/token rollups and parent FKsession_messages— per-message records with optional usage attributionsession_tool_calls— tool call/result records with duration and statussessions_fts— FTS5 virtual table for full-text search across agent names, message content, and tool namesRPC surface (all
openhuman.session_db_*):list— paginated session listing with status/parent filtersget— single session by IDsearch— FTS + structured filters (agent, tool, channel, thread, parent, status)get_messages— messages for a sessionget_tool_calls— tool calls for a sessionget_children— sub-agent sessions for a parentimport_transcript— index a JSONL transcript file into the DBDesign decisions:
import_transcriptresolves parent lineage from session key naming convention (parent__child)mark_interruptedfor cold-boot recovery (mirrors existingturn_statepattern)Submission Checklist
Closes #3247Impact
Related
bus.rs) to auto-record sessions fromAgentTurnStarted/AgentTurnCompletedevents (deferred to keep initial PR focused on the persistence layer)session_db_*RPCsAI Authored PR Metadata (required for Codex/Linear PRs)
Linear Issue
Commit & Branch
issue/3247-add-a-durable-agent-session-databaseValidation Run
pnpm --filter openhuman-app format:check— passedcargo test -p openhuman --lib session_db— 27/27 passedcargo fmt --check— passed,cargo check— passed (both manifests)pnpm typecheck— pre-existing failures inmemoryGraphLayout.ts/pixiGraphRenderer.ts(missingd3-force/pixi.jstypes, not related to this PR)Validation Blocked
command:pnpm typecheckerror:error TS2307: Cannot find module 'd3-force'(+ pixi.js type errors in memoryGraphLayout.ts / pixiGraphRenderer.ts)impact:None — files not touched by this PR; pre-existing on mainBehavior Changes
Parity Contract
session_raw/*.jsonltranscript files remain untouched and continue to be the KV-cache resume source of truthDuplicate / Superseded PR Handling