@devries-cameron20 / composio-1 / commits / ac9c7edda
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

perf(cli): list connected accounts once per execute (#4475)

## Summary `composio execute` made eight backend requests. Two of them were the same list of the user's connected accounts, fetched by two code paths that cannot see each other. It is fetched once now. Interleaved A/B against #4469, compiled binaries, 15 runs each on a small response: 1735ms to 1636ms best, 1934ms to 1845ms median. That is one round trip (~140ms) off the critical path. Results are identical to before in every case. The picker derives its toolkit subset from the shared list with the exact semantics of its old query, and falls back to that query when the shared list is truncated. Fifth PR in the stack. Stacked on #4469; review #4463, #4464, #4468 and #4469 first. #4483 builds on this one. ## Changes 1. `src/utils/memoize-in-process.ts` (new). Memoizes an Effect per key for the process lifetime, shares one run between concurrent callers, and drops a failure, defect or interruption so the next caller retries. 2. `listActiveConnectedAccounts` in `connected-account-selection.ts`: the unfiltered `GET /connected_accounts` for a user, memoized by client identity and user id. It fails with the raw rejection, and each caller wraps that in its own error. `resolveToolRouterSessionConnections` reads from it when it has no toolkit filter, which is the execute path. With a filter it keeps its own request. 3. `resolveConnectedAccountForToolkit` used to issue its own request, toolkit-filtered, `limit: 100`. It now derives that from the shared list: same slug match, server order preserved, first 100. If the shared list has a `next_cursor` or `total_items` above what it holds, the toolkit's accounts may sit past the cut, so the original filtered request runs instead. 4. `get_latest_version` goes through the same memo. The definition refresh fetched it twice with identical headers on the stale path; that is one request now. The executor's own version lookup sends no org or project headers and stays a separate request. Scoping it would change which definition it resolves under, which is a semantics decision, not a perf one. What does not change: the request list on a normal execute is now `project/resolve`, `connected_accounts`, `get_latest_version` twice, `consumer/config`, `session`, `execute`. Error messages are unchanged; the fallback passes the raw rejection through so the picker's message reads as before. ## Type of change - [ ] Bug fix - [ ] New feature - [x] Refactor/Chore - [ ] Documentation - [ ] Breaking change ## How Has This Been Tested? Bun 1.4.1+4661e494f, Node 24.20.0, pnpm 11.8.0, linux-x64. 1. `cd ts/packages/cli && pnpm run typecheck && pnpm run validate:boundaries` 2. `pnpm exec vitest run`: 131 files, 1341 passed, 1 skipped (whole stack). New tests cover the memo sharing one run per key and retrying after a failure or a defect. The execute suite already covers account selection with and without a selector and passes unchanged. The test layer builds a fresh client per test, so the client-keyed memo does not bleed between tests. 3. Request count: hooked `fetch` while running `execute HACKERNEWS_GET_ITEM_WITH_ID` from source. `connected_accounts` appears once, the rest of the list as before. 4. Timing: `pnpm build:binary`, then the interleaved A/B above against #4469's binary. A second round of 12 gave 1788 to 1621ms best, 2045 to 1963ms median. ## Screenshots (if applicable) Not applicable. ## Checklist - [x] I have read the Code of Conduct and this PR adheres to it - [x] I ran linters/tests locally and they passed - [ ] I updated documentation as needed - [x] I added tests or explain why not applicable - [ ] I added a changeset if this change affects published packages No docs describe the request sequence. `@composio/cli` is private, so no changeset. ## Additional context The rest of an execute, from the same trace: `project/resolve` 140 to 640ms with no cache, `tool_router/session` 385 to 655ms created per invocation, and the execute call itself 500 to 730ms. The connected-account cache in `consumer-short-term-cache.ts` would take `connected_accounts` off the path entirely, but `DISABLE_CONNECTED_ACCOUNT_CACHE` defaults to on, and enabling it fails no-auth toolkits with "not connected" because the cached list does not include them. Both are separate changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Wx9gEjuiHux2weiHjdNcDs

Daksh committed Sep 15, 2026 at 00:10 UTC ac9c7edda6b67b786a7462bccb882cc7f569dfd4

No changes.