Skip to content

Production Safeguards

Monitors memory + CPU during heavy operations (indexing, vector DB). Intervenes when thresholds are exceeded via a graduated recovery ladder before falling back to a hard emergency stop.

Every N seconds:

MetricSource
Heap usedprocess.memoryUsage()
Heap totalprocess.memoryUsage()
RSSprocess.memoryUsage()
Externalprocess.memoryUsage()
CPU userprocess.cpuUsage()
CPU systemprocess.cpuUsage()
LimitDefaultPurpose
maxMemoryMB1024Total RSS ceiling
maxHeapMB512V8 heap ceiling
maxCpuPercent80CPU ceiling
gcThresholdMB256Heap size that triggers GC suggestion
alertThresholdMB400Heap size that triggers first recovery

Each action has a cooldown and max retries to prevent thrashing. Actions run in priority order — the first applicable one fires.

PriorityActionTriggerCooldownMax retries
1Clear cacheHeap > alertThresholdMB30 s3
3Reduce batch sizeHeap > 80% of alert AND indexing active60 s2
4Pause indexingHeap > 90% of maxHeapMB AND indexing2 min1
5Restart workerHeap > maxHeapMB AND indexing5 min1
6Emergency stopRSS > maxMemoryMB1

Context-awareness: REDUCE_BATCH_SIZE, PAUSE_INDEXING, RESTART_WORKER only fire when indexing is actually in progress (checked via ServiceStatusChecker). CLEAR_CACHE always fires — safe regardless of state.

Operations wrapped in executeWithSafeguards() go through a circuit breaker:

graph LR A[CLOSED<br/>Normal] -->|Failures ≥ threshold| B[OPEN<br/>All rejected] B -->|Timeout expires| C[HALF_OPEN<br/>Single probe] C -->|Success| A C -->|Failure| B

Wrapped operations also get:

  • Timeout — killed after a deadline
  • Retry — configurable count
  • Bypass flag — skip the circuit breaker for critical ops

When RSS > maxMemoryMB:

  1. emergencyStopActive = true
  2. All subsequent executeWithSafeguards() calls reject immediately
  3. Requires manual recovery (CodeBuddy: Reset Safeguards) or extension restart

Prevents the extension from OOM-killing the editor.