@devries-cameron20 / composio Mirror · read-only / commits / be9f3fc4c
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.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 12:15 UTC

fix(cli): judge the shared account page complete by its size, not total_items

Whether `total_items` honors the `statuses` filter is a server detail. A count that did not would make the shared list look truncated on every call and quietly route the account picker onto the second request forever. Take a page as complete when it is shorter than the requested size and carries no cursor, and cover both the short-page and full-page cases. Claude-Session: https://claude.ai/code/session_01MTb47vexN35pLGsSZwBmrJ

jkomyno committed Sep 14, 2026 at 21:02 UTC be9f3fc4ca0f6ab9165429b5d92e0fd9f732175c
2 files changed +54 -6
ts/packages/cli/src/services/connected-account-selection.ts
+12 -6
@@ -163,10 +163,12 @@ const clientId = (client: Composio): number => {
163 * view is a subset of this list, so both read from here instead of issuing
164 * their own `GET /connected_accounts`.
165 *
166 - * `limit: 1000` is the session path's existing page size; a user with more
167 - * active accounts than that was already truncated there. Fails with the raw
166 + * The page size is the session path's existing one; a user with more active
167 + * accounts than that was already truncated there. Fails with the raw
168 * rejection; each caller wraps it in its own error.
169 */
170 +const ACTIVE_ACCOUNTS_PAGE_SIZE = 1000;
171 +
172 export const listActiveConnectedAccounts = memoizeInProcess({
173 keyOf: (input: { readonly client: Composio; readonly userId: string }) =>
174 `${clientId(input.client)}\u0000${input.userId}`,
@@ -176,7 +178,7 @@ export const listActiveConnectedAccounts = memoizeInProcess({
178 client.connectedAccounts.list({
179 user_ids: [userId],
180 statuses: ['ACTIVE'],
179 - limit: 1000,
181 + limit: ACTIVE_ACCOUNTS_PAGE_SIZE,
182 }),
183 catch: cause => cause,
184 }),
@@ -211,9 +213,13 @@ const fetchConnectedAccountsForToolkit = (params: {
213 * needs anyway.
214 *
215 * Derivation reproduces the server query: same slug match, server order
214 - * preserved, first 100. If the shared list was truncated (more active
216 + * preserved, first 100. If the shared list may be truncated (more active
217 * accounts than its page holds), the toolkit's accounts may sit past the cut,
216 - * so the original filtered request runs instead.
218 + * so the original filtered request runs instead. A page is taken as complete
219 + * when it is shorter than the requested size and carries no cursor.
220 + * `total_items` is deliberately not consulted: whether it honors the status
221 + * filter is a server detail, and a count that did not would make the derived
222 + * path look truncated on every call and silently fall back forever.
223 *
224 * The slug is trimmed and lower-cased the way the grouping helpers above
225 * normalize toolkit slugs, and the trimmed slug is what the fallback sends,
@@ -231,7 +237,7 @@ export const listConnectedAccountsForToolkit = (params: {
237 userId: params.userId,
238 });
239 const items = shared.items;
234 - const complete = shared.next_cursor == null && shared.total_items <= items.length;
240 + const complete = shared.next_cursor == null && items.length < ACTIVE_ACCOUNTS_PAGE_SIZE;
241 if (!complete) {
242 return yield* fetchConnectedAccountsForToolkit({ ...params, toolkitSlug });
243 }
ts/packages/cli/test/src/services/connected-account-selection.test.ts
+42
@@ -162,4 +162,46 @@ describe('listConnectedAccountsForToolkit', () => {
162 expect(fallback.calls[1]?.toolkit_slugs).toEqual(['github']);
163 })
164 );
165 +
166 + effectIt.effect('derives from a short page even when total_items counts more', () =>
167 + Effect.gen(function* () {
168 + // A server that reports the all-status count must not push every call
169 + // onto the filtered request.
170 + const { client, calls } = makeListClient(
171 + [makeAccount({ id: 'con_gmail', toolkit: { slug: 'gmail' } })],
172 + { total_items: 7 }
173 + );
174 +
175 + const accounts = yield* listConnectedAccountsForToolkit({
176 + client,
177 + userId: 'default',
178 + toolkitSlug: 'gmail',
179 + });
180 +
181 + expect(accounts.map(item => item.id)).toEqual(['con_gmail']);
182 + expect(calls).toHaveLength(1);
183 + })
184 + );
185 +
186 + effectIt.effect('falls back to the filtered request when the shared page is full', () =>
187 + Effect.gen(function* () {
188 + const items = Array.from({ length: 1000 }, (_, index) =>
189 + makeAccount({ id: `con_slack_${index}`, toolkit: { slug: 'slack' } })
190 + );
191 + const { client, calls } = makeListClient([
192 + ...items,
193 + makeAccount({ id: 'con_gmail', toolkit: { slug: 'gmail' } }),
194 + ]);
195 +
196 + const accounts = yield* listConnectedAccountsForToolkit({
197 + client,
198 + userId: 'default',
199 + toolkitSlug: 'gmail',
200 + });
201 +
202 + expect(accounts.map(item => item.id)).toEqual(['con_gmail']);
203 + expect(calls).toHaveLength(2);
204 + expect(calls[1]?.toolkit_slugs).toEqual(['gmail']);
205 + })
206 + );
207 });