@devries-cameron20 / composio-1 / commits / 5ff344bc3
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.

fix(docs): bound toolkit miss cache

jkomyno committed Aug 25, 2026 at 03:42 UTC 5ff344bc3407e1cc776d1c2316d6f514089a0d0b
2 files changed +28 -1
docs/lib/toolkit-api.ts
+13 -1
@@ -3,6 +3,7 @@ import { PRODUCTION_API_V3_URL } from '@/scripts/production-api.mjs';
3 import type { AuthConfigDetail, AuthConfigField, Toolkit } from '@/types/toolkit';
4
5 const NEGATIVE_CACHE_TTL_MS = 60_000;
6 +const NEGATIVE_CACHE_MAX_ENTRIES = 1_024;
7 const TOOLKIT_SLUG_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/;
8
9 const negativeCache = new Map<string, number>();
@@ -192,7 +193,18 @@ function toolkitFromRaw(raw: RawToolkit, slug: string): Toolkit {
193 }
194
195 function recordNegative(slug: string) {
195 - negativeCache.set(slug, Date.now() + NEGATIVE_CACHE_TTL_MS);
196 + const now = Date.now();
197 + for (const [cachedSlug, expiresAt] of negativeCache) {
198 + if (expiresAt > now) break;
199 + negativeCache.delete(cachedSlug);
200 + }
201 +
202 + negativeCache.delete(slug);
203 + if (negativeCache.size >= NEGATIVE_CACHE_MAX_ENTRIES) {
204 + const oldestSlug = negativeCache.keys().next().value;
205 + if (oldestSlug !== undefined) negativeCache.delete(oldestSlug);
206 + }
207 + negativeCache.set(slug, now + NEGATIVE_CACHE_TTL_MS);
208 }
209
210 /** Fetch one toolkit's metadata from production after a checked-in snapshot miss. */
docs/tests/static/toolkit-api.test.ts
+15
@@ -284,6 +284,21 @@ describe('fetchToolkitFromProduction', () => {
284 expect(warning).toHaveBeenCalledTimes(2);
285 });
286
287 + test('bounds negative-cache entries for unique missing slugs', async () => {
288 + useApiKey();
289 + const fetcher = mock(async () => new Response(null, { status: 404 }));
290 + globalThis.fetch = fetcher;
291 + spyOn(console, 'warn').mockImplementation(() => {});
292 +
293 + for (let index = 0; index <= 1_024; index += 1) {
294 + expect(await fetchToolkitFromProduction(`bounded-miss-${index}`)).toBeNull();
295 + }
296 + expect(fetcher).toHaveBeenCalledTimes(1_025);
297 +
298 + expect(await fetchToolkitFromProduction('bounded-miss-0')).toBeNull();
299 + expect(fetcher).toHaveBeenCalledTimes(1_026);
300 + });
301 +
302 test.each([
303 ['500 response', async () => new Response(null, { status: 500 })],
304 ['network error', async () => Promise.reject(new Error('offline'))],