fix(convex): prevent OOM by filtering large inventory fields

- Add INVENTORY_BLOCKLIST to filter 'software' and 'extended' fields
  from machine metadata (these fields can be 100KB+ each)
- Add compactMachineMetadata migration to clean existing large documents
- Preserve essential fields: metrics, postureAlerts, collaborator,
  inventory.os, cpu, memory, disks, network, services

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
esdrasrenan 2025-12-09 22:36:03 -03:00
parent 508f915cf9
commit cf28ad2ee4
2 changed files with 122 additions and 0 deletions

View file

@ -251,6 +251,10 @@ function isObject(value: unknown): value is Record<string, unknown> {
return Boolean(value) && typeof value === "object" && !Array.isArray(value)
}
// Campos do inventory que sao muito grandes e nao devem ser persistidos
// para evitar OOM no Convex (documentos de ~100KB cada)
const INVENTORY_BLOCKLIST = new Set(["software", "extended"])
function mergeInventory(current: unknown, patch: unknown): unknown {
if (!isObject(patch)) {
return patch
@ -258,6 +262,8 @@ function mergeInventory(current: unknown, patch: unknown): unknown {
const base: Record<string, unknown> = isObject(current) ? { ...(current as Record<string, unknown>) } : {}
for (const [key, value] of Object.entries(patch)) {
if (value === undefined) continue
// Filtrar campos volumosos que causam OOM
if (INVENTORY_BLOCKLIST.has(key)) continue
if (isObject(value) && isObject(base[key])) {
base[key] = mergeInventory(base[key], value)
} else {