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, 18:30 UTC
fix(cli): key identity stitch throttle by credential
Kshitij Jhunjhunwala committed
Jul 29, 2026 at 16:36 UTC
0f37be91e5be1685761c1d71fea3bb0fe1c6c6db
2 files changed
+48
-2
ts/packages/cli/src/analytics/dispatch.ts
+8
-1
@@ -184,6 +184,7 @@ type AnalyticsState = {
184
readonly aliased_apollo_user_id?: string;
185
readonly api_key_fingerprint?: string;
186
readonly stitch_attempted_at?: string;
187
+ readonly stitch_attempted_api_key_fingerprint?: string;
188
readonly created_at?: string;
189
};
190
@@ -845,7 +846,12 @@ export const ensureAnalyticsIdentity = (params: {
846
847
const lastAttemptMs = Date.parse(state?.stitch_attempted_at ?? '');
848
const nowMs = yield* Clock.currentTimeMillis;
848
- if (Number.isFinite(lastAttemptMs) && nowMs - lastAttemptMs < STITCH_ATTEMPT_INTERVAL_MS) {
849
+ const sameCredentialAttempt = state?.stitch_attempted_api_key_fingerprint === fingerprint;
850
+ if (
851
+ sameCredentialAttempt &&
852
+ Number.isFinite(lastAttemptMs) &&
853
+ nowMs - lastAttemptMs < STITCH_ATTEMPT_INTERVAL_MS
854
+ ) {
855
return false;
856
}
857
@@ -853,6 +859,7 @@ export const ensureAnalyticsIdentity = (params: {
859
const installId = yield* getOrCreateInstallIdUnlocked;
860
yield* mergeAnalyticsStateUnlocked(installId, {
861
stitch_attempted_at: DateTime.formatIso(yield* DateTime.now),
862
+ stitch_attempted_api_key_fingerprint: fingerprint,
863
});
864
return true;
865
})
ts/packages/cli/test/src/analytics.dispatch.test.ts
+40
-1
@@ -1104,8 +1104,12 @@ describe('CLI analytics dispatch', () => {
1104
1105
const persisted = JSON.parse(
1106
yield* fs.readFileString(path.join(home, '.composio', 'analytics.json'), 'utf8')
1107
- ) as { stitch_attempted_at?: string };
1107
+ ) as {
1108
+ stitch_attempted_at?: string;
1109
+ stitch_attempted_api_key_fingerprint?: string;
1110
+ };
1111
expect(typeof persisted.stitch_attempted_at).toBe('string');
1112
+ expect(typeof persisted.stitch_attempted_api_key_fingerprint).toBe('string');
1113
1114
// Identity is still unlinked, but the attempt is throttled for 24h.
1115
yield* ensureAnalyticsIdentity({
@@ -1116,5 +1120,40 @@ describe('CLI analytics dispatch', () => {
1120
expect(fetchSessionInfo).toHaveBeenCalledTimes(1);
1121
}).pipe(Effect.provide(makePlatformLayer(home)));
1122
});
1123
+
1124
+ it.effect('bootstrap stitch retries immediately when the credential changes', () => {
1125
+ const home = tempy.temporaryDirectory();
1126
+ const scriptPath = `${home}/composio.ts`;
1127
+ enableTelemetry('uak_first');
1128
+ process.argv[1] = scriptPath;
1129
+ const failedFetch = vi.fn(() => Effect.fail(new Error('offline')));
1130
+ const changedCredentialFetch = vi.fn(() =>
1131
+ Effect.succeed({ org_member: { id: 'om_changed' } })
1132
+ );
1133
+
1134
+ return Effect.gen(function* () {
1135
+ const fs = yield* FileSystem.FileSystem;
1136
+ yield* fs.writeFileString(scriptPath, '');
1137
+
1138
+ yield* ensureAnalyticsIdentity({
1139
+ apiKey: 'uak_first',
1140
+ baseURL: 'https://backend.example.test',
1141
+ fetchSessionInfo: failedFetch,
1142
+ });
1143
+ yield* ensureAnalyticsIdentity({
1144
+ apiKey: 'uak_second',
1145
+ baseURL: 'https://backend.example.test',
1146
+ fetchSessionInfo: changedCredentialFetch,
1147
+ });
1148
+
1149
+ expect(failedFetch).toHaveBeenCalledTimes(1);
1150
+ expect(changedCredentialFetch).toHaveBeenCalledTimes(1);
1151
+ expect(childProcessMocks.spawn).toHaveBeenCalledTimes(1);
1152
+ const args = childProcessMocks.spawn.mock.calls[0]![1] as string[];
1153
+ const payload = decodeWorkerPayload<{ event: string; distinctId: string }>(args[2]!);
1154
+ expect(payload.event).toBe('$create_alias');
1155
+ expect(payload.distinctId).toBe('om_changed');
1156
+ }).pipe(Effect.provide(makePlatformLayer(home)));
1157
+ });
1158
});
1159
});