Skip to content

perf: fix N+1 queries in session list API#410

Merged
yaojin3616 merged 1 commit intomainfrom
bugfix
Apr 15, 2026
Merged

perf: fix N+1 queries in session list API#410
yaojin3616 merged 1 commit intomainfrom
bugfix

Conversation

@yaojin3616
Copy link
Copy Markdown
Collaborator

scope=all was issuing 1+2N DB queries (1 count + 2 agent-name lookups per session). scope=mine was issuing 2N queries (1 user-count + 1 total per session). Both are now replaced with 3-4 bulk queries total, regardless of session count.

Affected endpoint: GET /api/agents/{id}/sessions?scope=all|mine

Summary

Checklist

  • Tested locally
  • No unrelated changes included

scope=all was issuing 1+2N DB queries (1 count + 2 agent-name lookups
per session). scope=mine was issuing 2N queries (1 user-count + 1 total
per session). Both are now replaced with 3-4 bulk queries total,
regardless of session count.

Affected endpoint: GET /api/agents/{id}/sessions?scope=all|mine
@yaojin3616 yaojin3616 merged commit 15de6e8 into main Apr 15, 2026
up-guillaume pushed a commit to lesmoires/Clawith that referenced this pull request Apr 20, 2026
Upstream changes integrated:
- v1.8.3-beta.2: A2A async communication (notify/consult/task_delegate)
- v1.8.3-beta.2: Multimodal image context persistence
- v1.8.3-beta.2: New search tools (Exa, DuckDuckGo, Tavily, Google, Bing)
- v1.8.3-beta.2: Drag-and-drop file upload UI
- dataelement#246: Security patches (4 critical vulnerabilities)
- dataelement#410: N+1 query fix for session list API
- dataelement#416: Tool call message pair preservation
- dataelement#437: Idempotent alembic migrations
- LLM refactoring (call_llm moved to services/llm/)

Fork customizations preserved:
- SSO relaxation in tenants.py
- Tuple guards in gateway.py
- session_id removal from execute_tool (caller.py)
- Hetzner Cloud tools in tool_seeder.py
- Infisical/AgentMail integrations
- LiteLLM MCP wrappers
- AgentBay multi-region + browser_latest fixes
- Custom extensions loader
- Agent credentials router

Conflict resolutions:
- agentbay_control.py: upstream 3-phase _get_client + our browser_latest fix
- agent_tools.py: our fork base + upstream A2A strip helper + search tools
- caller.py: removed session_id=session_id (NameError fix)
- websocket.py: retained our session_id removal
- tool_seeder.py: added parameters_schema + new search tools
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants