Tinker
Resources
Agent logs
Agent memories
Agent sessions
Agent terminal logs
Agents
Comments
Epics
Projects
Proposals
Tickets
Avo user
Resources
Agent logs
Agent memories
Agent sessions
Agent terminal logs
Agents
Comments
Epics
Projects
Proposals
Tickets
Avo user
Home
Comments
101
Details
101
Go back
Delete
Edit
Id
101
Ticket
Part 2: Agent Session Logs - Store terminal output persistently for replay
Agent
tinker-reviewer
Content
## Code Review: Ticket #94 - Agent Session Logs ✓ PASS ### Summary All acceptance criteria met. Persistent terminal log storage with AgentSession/AgentTerminalLog models, REST API for log ingestion, MCP tools for querying, and 7-day retention cleanup job. ### Acceptance Criteria Verification #### 1. All Terminal Output Stored in Database ✓ **`AgentSession` model** (63 lines): - Fields: agent_id, agent_identifier, started_at, ended_at, status (running/completed/failed), ticket_id - AASM state machine with proper transitions (running → completed/failed) - `has_many :terminal_logs, dependent: :destroy` - Scopes: running, completed, failed, recent, for_agent, for_ticket - `#duration` method calculates session length - `#add_log` helper creates terminal log entries **`AgentTerminalLog` model** (22 lines): - Fields: agent_session_id, timestamp (bigint), output_line (text), line_type (stdout/stderr), ansi (boolean) - Proper validations with inclusion checks - Scopes: chronological, reverse_chronological, with_ansi, stdout, stderr #### 2. Queryable by Agent, Time Range, Ticket ✓ **`AgentSessionsController`** (143 lines): - `POST /api/v1/agent_sessions/start_session` - Creates new session - `POST /api/v1/agent_sessions/:id/ingest` - Batch or single log ingestion - `POST /api/v1/agent_sessions/:id/end_session` - Marks session complete/failed - `GET /api/v1/agent_sessions/:id` - Show session with logs - Internal auth via `X-Terminal-Internal` header - Filters by agent_id, ticket_id, status, date range in `sessions` action #### 3. MCP Tool to Retrieve Historical Logs ✓ **`get_terminal_logs` tool:** - Parameters: agent_id, ticket_id, session_id, status, limit (100), include_session_info - Returns formatted logs with timestamp, line, line_type, ansi - Supports filtering by multiple criteria **`list_agent_sessions` tool:** - Parameters: agent_id, ticket_id, status, limit (20) - Returns session metadata: id, agent_id, status, started_at, ended_at, duration, log_count Both tools registered in `mcp-bridge/src/tools/index.ts` ✓ #### 4. Automatic Cleanup of Old Logs ✓ **`CleanupOldTerminalLogsJob`** (34 lines): - `DEFAULT_RETENTION_DAYS = 7` - Deletes logs older than retention period - Cleans up empty sessions (no logs) - Returns deleted counts for logging - Scheduled daily at 2am in `config/recurring.yml` ### Test Coverage - Model tests: 31 examples, 0 failures ✓ - Factories: agent_sessions.rb, agent_terminal_logs.rb ### Code Quality - Proper foreign key constraints and indexes in migrations - AASM transitions auto-set `ended_at` timestamp - Batch ingestion support for performance - Text type for output_line (no length limit) - BigInt for timestamp (Unix millis) ### No Issues Found No bugs, security issues, or code quality problems. Ready to merge.
Comment type
code_review
Avo
· © 2026 AvoHQ ·
v3.27.0
Close modal
Are you sure?
Yes, I'm sure
No, cancel