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.
Monitored metrics
Section titled “Monitored metrics”Every N seconds:
| Metric | Source |
|---|---|
| Heap used | process.memoryUsage() |
| Heap total | process.memoryUsage() |
| RSS | process.memoryUsage() |
| External | process.memoryUsage() |
| CPU user | process.cpuUsage() |
| CPU system | process.cpuUsage() |
Limits
Section titled “Limits”| Limit | Default | Purpose |
|---|---|---|
maxMemoryMB | 1024 | Total RSS ceiling |
maxHeapMB | 512 | V8 heap ceiling |
maxCpuPercent | 80 | CPU ceiling |
gcThresholdMB | 256 | Heap size that triggers GC suggestion |
alertThresholdMB | 400 | Heap size that triggers first recovery |
Recovery ladder
Section titled “Recovery ladder”Each action has a cooldown and max retries to prevent thrashing. Actions run in priority order — the first applicable one fires.
| Priority | Action | Trigger | Cooldown | Max retries |
|---|---|---|---|---|
| 1 | Clear cache | Heap > alertThresholdMB | 30 s | 3 |
| 3 | Reduce batch size | Heap > 80% of alert AND indexing active | 60 s | 2 |
| 4 | Pause indexing | Heap > 90% of maxHeapMB AND indexing | 2 min | 1 |
| 5 | Restart worker | Heap > maxHeapMB AND indexing | 5 min | 1 |
| 6 | Emergency stop | RSS > maxMemoryMB | — | 1 |
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.
Circuit breaker
Section titled “Circuit breaker”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
Emergency stop
Section titled “Emergency stop”When RSS > maxMemoryMB:
emergencyStopActive = true- All subsequent
executeWithSafeguards()calls reject immediately - Requires manual recovery (
CodeBuddy: Reset Safeguards) or extension restart
Prevents the extension from OOM-killing the editor.
Related
Section titled “Related”- Performance profiler — the metrics this reacts to
- Self-healing — how these safeguards interact with agent-level safety