Repository navigation
Closed
Labels
Description
Problem
Dashboard load time is ~15 seconds with 12+ agents due to N+1 permission fetching. The fetchPermissionEdges() function in stores/network.js:152-219 makes N separate API calls — one GET /api/agents/{name}/permissions per agent.
Each call:
- Does Docker container lookup (
get_agent_container()) - Queries DB for permissions (
db.get_permitted_agents()) - Returns all accessible agents (redundant data repeated N times)
With 12 agents = 12 HTTP round trips, even when parallelized.
Root Cause
Issue #87 introduced permission edges on the graph dashboard but no bulk endpoint was created. The PERF-269 optimizations (issue #269) addressed context-stats N+1 but not permissions.
Proposed Solution
Backend: Add bulk endpoint
GET /api/agents/permissions-edges — returns all permission edges in a single query:
# db/permissions.py
def get_all_permission_edges(self) -> List[dict]:
"""Get all permission edges for graph visualization."""
with get_db_connection() as conn:
cursor = conn.cursor()
cursor.execute("""
SELECT source_agent, target_agent FROM agent_permissions
""")
return [{"source": r["source_agent"], "target": r["target_agent"]}
for r in cursor.fetchall()]# routers/agents.py (or agent_files.py)
@router.get("/permissions-edges")
async def get_all_permission_edges(current_user: User = Depends(get_current_user)):
"""Get all permission edges for dashboard graph (bulk endpoint)."""
edges = db.get_all_permission_edges()
# Filter to only edges where user can access both agents
accessible = {a['name'] for a in get_accessible_agents(current_user)}
return {
"edges": [e for e in edges if e["source"] in accessible and e["target"] in accessible]
}Frontend: Replace N fetches with 1
// stores/network.js
async function fetchPermissionEdges() {
const response = await axios.get('/api/agents/permissions-edges')
const edges = response.data.edges
// Build edge map from flat list...
}Frontend: Decouple from agent refresh
Move fetchPermissionEdges() out of fetchAgents(). Call once on mount, update only when:
- WebSocket notification of permission change (future)
- Manual refresh button
Files Affected
| File | Change |
|---|---|
src/backend/db/permissions.py |
Add get_all_permission_edges() |
src/backend/database.py |
Expose new method |
src/backend/routers/agents.py |
Add /permissions-edges endpoint |
src/frontend/src/stores/network.js |
Replace N fetches with bulk call |
Expected Impact
- API calls: 12+ → 1 (92% reduction)
- Load time: ~15s → ~3-5s estimated
- Data transfer: Eliminates redundant
available_agentspayload
Acceptance Criteria
- New
GET /api/agents/permissions-edgesendpoint returns all edges in one query - Frontend uses bulk endpoint instead of per-agent fetches
- Permission edges load in < 500ms with 30+ agents
- Dashboard initial load < 5 seconds with 12+ agents
Related
- perf: Backend CPU saturation at 45% with ~30 agents due to WebSocket churn and polling storms #73 — Backend CPU saturation (open, broader performance issue)
- perf: Frontend polling storm + backend N+1 causing production sluggishness #269 — Frontend polling storm (closed, addressed context-stats but not permissions)
- Graph dashboard: Connect agents by communication permissions #87 — Graph dashboard permission edges (closed, introduced the N+1 pattern)
Activity
perf(dashboard): bulk permissions endpoint eliminates N+1 API calls (#…
docs(flows): update agent-network for bulk permissions endpoint (#359)
docs(tests): add bulk permissions endpoint tests to catalog (#359)
perf(dashboard): bulk permissions endpoint eliminates N+1 API calls (#…
feat(permissions): fleet-wide agent-to-agent permissions matrix in Se…