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
refactor(cli): evict every memoized failure and drop the unused list error
memoizeInProcess evicted a key only on typed failures, but Effect.cached stores the whole Exit, so a defect or an interrupted first caller was replayed for the rest of the process. Evict on any failure cause. ActiveConnectedAccountsListError was only ever unwrapped to its cause by both callers, so the shared list now fails with the raw rejection.
jkomyno committed
Sep 14, 2026 at 14:07 UTC
af573e5a15f747e1cedba175538f07c058a3c786
4 files changed
+31
-22
ts/packages/cli/src/services/connected-account-selection.ts
+7
-17
@@ -138,13 +138,6 @@ export const formatConnectedAccountChoices = (
138
): ReadonlyArray<string> =>
139
items.filter(isUsableConnectedAccount).sort(compareNewestFirst).map(formatConnectedAccountChoice);
140
141
-export class ActiveConnectedAccountsListError extends Data.TaggedError(
142
- 'services/ActiveConnectedAccountsListError'
143
-)<{
144
- readonly message: string;
145
- readonly cause: unknown;
146
-}> {}
147
-
141
// `Composio` clients come from `ComposioClientSingleton`, one instance per
142
// org/project, so identity is a sound cache key. Ids instead of the object
143
// itself keep the memo key a string.
@@ -166,12 +159,13 @@ const clientId = (client: Composio): number => {
159
* `composio execute` needs this list twice on every call, from two code paths
160
* that cannot see each other: `resolveConnectedAccountForToolkit` picks the
161
* account for the tool's toolkit, then `resolveToolRouterSessionConnections`
169
- * builds the session's connection context from the full list. Both used to
170
- * issue their own `GET /connected_accounts`, one toolkit-filtered and one not.
171
- * The per-toolkit view is a subset of this list, so both read from here.
162
+ * builds the session's connection context from the full list. The per-toolkit
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
174
- * active accounts than that was already truncated there.
167
+ * active accounts than that was already truncated there. Fails with the raw
168
+ * rejection; each caller wraps it in its own error.
169
*/
170
export const listActiveConnectedAccounts = memoizeInProcess({
171
keyOf: (input: { readonly client: Composio; readonly userId: string }) =>
@@ -184,11 +178,7 @@ export const listActiveConnectedAccounts = memoizeInProcess({
178
statuses: ['ACTIVE'],
179
limit: 1000,
180
}),
187
- catch: cause =>
188
- new ActiveConnectedAccountsListError({
189
- message: `Failed to list connected accounts for user "${userId}".`,
190
- cause,
191
- }),
181
+ catch: cause => cause,
182
}),
183
});
184
@@ -234,7 +224,7 @@ const listConnectedAccountsForToolkit = (params: {
224
const shared = yield* listActiveConnectedAccounts({
225
client: params.client,
226
userId: params.userId,
237
- }).pipe(Effect.mapError(error => error.cause));
227
+ });
228
const items = shared.items ?? [];
229
const complete = shared.next_cursor == null && shared.total_items <= items.length;
230
if (!complete) {
ts/packages/cli/src/services/tool-router-session-connections.ts
+2
-2
@@ -92,10 +92,10 @@ export const resolveToolRouterSessionConnections = (
92
// account picker, so it is fetched once per process and shared.
93
listActiveConnectedAccounts({ client, userId }).pipe(
94
Effect.mapError(
95
- error =>
95
+ cause =>
96
new ToolRouterSessionConnectionsError({
97
message: `Failed to list connected accounts for user "${userId}".`,
98
- cause: error.cause,
98
+ cause,
99
})
100
)
101
)
ts/packages/cli/src/utils/memoize-in-process.ts
+3
-3
@@ -2,8 +2,8 @@ import { Effect } from 'effect';
2
3
/**
4
* Memoizes an Effect per key for the lifetime of the process, sharing one run
5
- * between concurrent callers. A success stays cached; a failure is dropped so
6
- * the next caller retries instead of replaying the error.
5
+ * between concurrent callers. A success stays cached; a failure, defect, or
6
+ * interruption is dropped so the next caller retries instead of replaying it.
7
*
8
* Meant for reads that cannot change within one CLI invocation (a tool's
9
* latest version, the user's connected accounts) but were being fetched more
@@ -28,7 +28,7 @@ export const memoizeInProcess = <I, A, E, R>(options: {
28
// another fiber.
29
const cached = Effect.runSync(
30
Effect.cached(
31
- options.make(input).pipe(Effect.tapError(() => Effect.sync(() => cache.delete(key))))
31
+ options.make(input).pipe(Effect.onError(() => Effect.sync(() => cache.delete(key))))
32
)
33
);
34
cache.set(key, cached);
ts/packages/cli/test/src/utils/memoize-in-process.test.ts
+19
@@ -41,4 +41,23 @@ describe('memoizeInProcess', () => {
41
expect(calls).toBe(2);
42
})
43
);
44
+
45
+ it.effect('drops a defect so the next caller retries', () =>
46
+ Effect.gen(function* () {
47
+ let calls = 0;
48
+ const load = memoizeInProcess({
49
+ keyOf: (key: string) => key,
50
+ make: () =>
51
+ Effect.suspend(() =>
52
+ ++calls === 1 ? Effect.die('first call dies') : Effect.succeed(calls)
53
+ ),
54
+ });
55
+
56
+ const first = yield* Effect.exit(load('k'));
57
+ expect(Exit.isFailure(first)).toBe(true);
58
+
59
+ expect(yield* load('k')).toBe(2);
60
+ expect(calls).toBe(2);
61
+ })
62
+ );
63
});