- M5-004: Add `session_id` column to conversations table (nullable text) with Drizzle migration 0006_swift_shen.sql; bind sessionId to conversation on session creation; reuse existing sessionId when resuming a conversation
- M5-005: Emit session:info with agentName on model/agent switch via broadcastSessionInfo(); set:thinking and setModelOverride now broadcast updated session:info to all clients on a conversation
- M5-006: /agent new <name> gateway command creates an agent config via brain.agents.create() with defaults (provider/model from env vars) and returns agentId+agentName in command:result data
- M5-007: Track per-session metrics (input/output/cache tokens, modelSwitches, messageCount, lastActivityAt) accumulated across turns; exposed via GET /api/sessions/:id metrics field
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- DB client: configure connection pool (max=20, idle_timeout=30s, connect_timeout=5s)
- DB schema: add missing indexes for auth sessions, accounts, conversations, agent_logs
- DB schema: promote preferences(user_id,key) to UNIQUE index for ON CONFLICT upsert
- Drizzle migration: 0003_p8003_perf_indexes.sql
- preferences.service: replace 2-query SELECT+INSERT/UPDATE with single-round-trip upsert
- conversations repo: add ORDER BY + LIMIT to findAll (200) and findMessages (500)
- session-gc.service: make onModuleInit fire-and-forget (removes cold-start TTFB block)
- next.config.ts: enable compress, productionBrowserSourceMaps:false, image avif/webp
- docs/PERFORMANCE.md: full profiling report and change impact notes