-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix(memory): prune unbounded server-side caches causing heap growth #4651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import { isPaid } from '@/lib/billing/plan-helpers' | |
| import { getToolEntry } from '@/lib/copilot/tool-executor/router' | ||
| import { getCopilotToolDescription } from '@/lib/copilot/tools/descriptions' | ||
| import { isHosted } from '@/lib/core/config/feature-flags' | ||
| import { registerCache } from '@/lib/monitoring/cache-registry' | ||
| import { buildMothershipToolsForRequest } from '@/lib/mothership/settings/runtime' | ||
| import { trackChatUpload } from '@/lib/uploads/contexts/workspace/workspace-file-manager' | ||
| import { tools } from '@/tools/registry' | ||
|
|
@@ -21,6 +22,15 @@ type ToolSchemaCacheEntry = { | |
|
|
||
| const toolSchemaCache = new Map<string, ToolSchemaCacheEntry>() | ||
|
|
||
| setInterval(() => { | ||
| const now = Date.now() | ||
| for (const [key, entry] of toolSchemaCache) { | ||
| if (entry.expiresAt <= now) toolSchemaCache.delete(key) | ||
| } | ||
| }, TOOL_SCHEMA_CACHE_TTL_MS).unref() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing promise guard in toolSchemaCache sweep causes deduplication bypassMedium Severity The Additional Locations (1)Reviewed by Cursor Bugbot for commit 6766bd2. Configure here. |
||
|
|
||
| registerCache('toolSchemaCache', () => toolSchemaCache.size) | ||
|
|
||
| interface BuildPayloadParams { | ||
| message: string | ||
| workflowId?: string | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,13 @@ | ||||||||||||||||||||||||||||||||||||||
| const registry = new Map<string, () => number>() | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| export function registerCache(name: string, getSize: () => number): void { | ||||||||||||||||||||||||||||||||||||||
| registry.set(name, getSize) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| export function getCacheSizes(): Record<string, number> { | ||||||||||||||||||||||||||||||||||||||
| const sizes: Record<string, number> = {} | ||||||||||||||||||||||||||||||||||||||
| for (const [name, getSize] of registry) { | ||||||||||||||||||||||||||||||||||||||
| sizes[name] = getSize() | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| return sizes | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+7
to
+13
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toolSchemaCachesweep lacks the!entry.promiseguard that the paralleleffectiveEnvCachesweep inutils.tscorrectly includes. When a schema-build request is in-flight and the 30s interval fires before the async work completes (e.g. cold DB connection, slow permission lookup), the promise-only cache entry is deleted. Any new caller arriving after that deletion creates a second parallel fetch for the same key, causing a thundering-herd on exactly the large, expensive computation this cache is meant to deduplicate.