Repository navigation
Closed
Labels
Description
Problem
Production UI is sluggish — pages load but content takes seconds to appear, and navigation feels stuck/unresponsive. Root cause investigation identified compounding bottlenecks across frontend polling, backend API design, and database contention.
Key Metrics (Current State)
- 64+ API requests/minute from frontend polling alone (Dashboard + AgentDetail + NavBar)
- 12 sequential API calls on AgentDetail mount before anything renders
- N+1 Docker + HTTP + DB queries on every
/api/agents/context-statspoll (every 5s) - 100ms artificial delay on every route navigation
- SQLite single-writer contention from 3 concurrent background services
High-Impact Fixes
Quick Wins (1-2 hours total)
- Cache
context-statswith 10-30s TTL on backend — eliminates repeated N+1 Docker lookups, HTTP calls to every agent, and DB queries that fire every 5 seconds - Parallelize mount API calls with
Promise.all()— Dashboard (6 sequential calls) and AgentDetail (12 sequential calls) should batch independent requests. Expected: 60-70% faster initial page load - Remove 100ms
setTimeoutin router guard (src/frontend/src/router/index.js~line 210) — artificial delay on every navigation - Add
document.hiddenchecks to skip polling when tab is backgrounded — cuts background load by ~50% - Set axios request timeout (30s) — prevents UI freeze when backend is slow; currently no timeout configured
Medium Effort (half day)
- Reduce polling frequencies — context polling 5s→15s, agent refresh 10s→30s. Reduces request volume by ~70%
- Batch Docker lookups in
context-stats— replace per-agentcontainers.get()(sync, blocks event loop) with singlecontainers.list(filters=...)call - Wrap Docker SDK calls in
run_in_executorinsrc/backend/services/agent_service/stats.py— Docker SDK is synchronous, currently blocking the async event loop - Stagger background services — cleanup service (5min) and operator queue (5s) both write to SQLite; stagger to reduce lock contention
- Fix KeepAlive polling leak —
AgentDetailuses<KeepAlive>in App.vue; switching agents can accumulate polling timers that don't get properly cleaned up inonDeactivated
Larger Effort (1-2 days)
- Push agent stats via WebSocket instead of polling — single connection replaces dozens of polling intervals; would reduce request volume by ~90%
- Switch to
aiosqliteor PostgreSQL — eliminates single-writer contention from concurrent background services and HTTP handlers
Files Affected
| File | Issue |
|---|---|
src/frontend/src/views/Dashboard.vue (lines 573-622) |
Waterfall mount + 3 polling intervals |
src/frontend/src/views/AgentDetail.vue (lines 937-1008) |
12 sequential mount calls + 3 polling intervals |
src/frontend/src/stores/network.js (lines 1072-1164) |
Context/agent/activity polling |
src/frontend/src/stores/agents.js (lines 677-704) |
Context polling (5s) |
src/frontend/src/components/NavBar.vue (lines 258-275) |
Global alert/notification polling |
src/frontend/src/router/index.js (~line 210) |
100ms navigation delay |
src/backend/services/agent_service/stats.py (lines 22-82) |
N+1 Docker lookups, sync blocking |
src/backend/db/connection.py (lines 16-28) |
No connection pooling, 30s timeout |
src/backend/main.py (lines 292-303) |
3 competing background services |
Acceptance Criteria
- Dashboard initial load < 2 seconds (currently 5-10s+)
- Background API request volume < 15 req/min (currently 64+)
- No UI freeze during cleanup service sweeps
- Navigation between pages feels instant (no perceptible delay)
Activity
perf: eliminate polling storm + parallelize mounts + cache context-st…
perf: eliminate polling storm + parallelize mounts + cache context-st…