osvm 0.8.3

OpenSVM CLI tool for managing SVM nodes and deployments
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
# Self-Repair System

The Self-Repair System provides automated error detection, diagnosis, and repair capabilities for OSVM CLI managed infrastructure. It continuously monitors system health and automatically resolves common issues.

## Overview

The OSVM Self-Repair System is a comprehensive automated maintenance solution that monitors multi-level dependencies, detects issues through pattern analysis, and applies targeted fixes with full rollback capabilities.

## Quick Start

```bash
# Run system health check
osvm doctor

# Enable automatic repair mode
osvm doctor --auto-repair

# Detailed diagnostic with verbose output
osvm doctor --detailed --verbose

# Manual repair for specific issue
osvm repair --issue dependency-missing --component rust-toolchain
```

## Architecture

```mermaid
flowchart TD
    subgraph "Self-Repair System Architecture"
        MONITOR[Health Monitor]
        
        subgraph "Detection Layer"
            ERROR[Error Detection]
            PATTERN[Pattern Analysis]
            CLASSIFY[Issue Classification]
        end
        
        subgraph "Diagnostic Layer"
            SYSTEM[System Assessment]
            USER[User Dependencies]
            APP[Application Dependencies]
        end
        
        subgraph "Repair Layer"
            PLAN[Repair Planning]
            EXEC[Repair Execution]
            VERIFY[Verification]
            ROLLBACK[Rollback System]
        end
        
        subgraph "Safety Systems"
            SNAPSHOT[System Snapshots]
            CHECKPOINT[Checkpoints]
            VALIDATION[Health Validation]
        end
    end
    
    MONITOR --> ERROR
    ERROR --> PATTERN
    PATTERN --> CLASSIFY
    
    CLASSIFY --> SYSTEM
    CLASSIFY --> USER
    CLASSIFY --> APP
    
    SYSTEM --> PLAN
    USER --> PLAN
    APP --> PLAN
    
    PLAN --> SNAPSHOT
    SNAPSHOT --> EXEC
    EXEC --> VERIFY
    VERIFY --> VALIDATION
    VALIDATION --> ROLLBACK
    
    classDef techDebt fill:#f6f6f6,stroke:#d9534f,color:#d9534f,font-family:Consolas,monospace,font-weight:bold
```

## Core Components

### Health Monitor

Continuous monitoring of system components and dependencies.

**Monitored Components:**
- System packages and dependencies
- Rust toolchain and cargo
- Solana CLI and tools
- Network connectivity
- Configuration files
- Service status

### Error Detection Engine

Intelligent error pattern recognition and classification.

```mermaid
sequenceDiagram
    participant CMD as Command
    participant DETECT as Error Detector
    participant ANALYZE as Pattern Analyzer
    participant CLASSIFY as Classifier
    participant REPAIR as Repair Engine
    
    CMD->>DETECT: Command execution error
    DETECT->>ANALYZE: Extract error patterns
    ANALYZE->>CLASSIFY: Categorize issue type
    CLASSIFY->>REPAIR: Determine repair strategy
    REPAIR->>CMD: Apply fix automatically
    
    classDef techDebt fill:#f6f6f6,stroke:#d9534f,color:#d9534f,font-family:Consolas,monospace,font-weight:bold
```

### Repair Strategies

Multi-level repair approach with safety checkpoints.

**System Level Repairs:**
- Package manager updates
- Dependency installation
- Environment configuration
- Service restarts

**User Level Repairs:**
- Solana CLI updates
- Configuration fixes
- Keypair validation
- Network settings

**Application Level Repairs:**
- Binary updates
- Configuration validation
- Cache clearing
- State reset

## Doctor Command

The doctor command provides comprehensive system diagnostics and repair capabilities.

### Basic Usage

```bash
# Quick health check
osvm doctor

# Detailed diagnostic report
osvm doctor --detailed

# Auto-repair mode
osvm doctor --auto-repair

# Verbose output with debug information
osvm doctor --verbose

# Check specific component
osvm doctor --component rust-toolchain

# Dry run to see what would be repaired
osvm doctor --dry-run --auto-repair
```

### Command Options

```bash
osvm doctor [OPTIONS]
```

**Options:**
- `--auto-repair` - Automatically apply repairs
- `--detailed` - Show detailed diagnostic information
- `--verbose` - Enable verbose logging
- `--component <COMPONENT>` - Check specific component
- `--dry-run` - Show repair plan without executing
- `--force` - Force repairs even if risky
- `--backup` - Create backup before repairs

## Supported Issue Types

### System Dependencies

**Missing Packages:**
- Build tools (gcc, make, cmake)
- System libraries
- Development headers
- Package manager issues

**Detection:**
```bash
Error: linker `cc` not found
```

**Automatic Fix:**
```bash
# Ubuntu/Debian
sudo apt update && sudo apt install build-essential

# CentOS/RHEL
sudo yum groupinstall "Development Tools"

# macOS
xcode-select --install
```

### Rust Toolchain Issues

**Outdated Toolchain:**
- Rust version compatibility
- Missing components
- Corrupted installation

**Detection:**
```bash
error: rustc 1.60.0 is too old for this crate
```

**Automatic Fix:**
```bash
rustup update stable
rustup component add rustfmt clippy
```

### Solana CLI Problems

**Version Mismatches:**
- CLI version incompatibility
- Missing features
- Configuration errors

**Detection:**
```bash
Error: Unknown subcommand 'feature'
```

**Automatic Fix:**
```bash
solana-install update
solana config set --url https://api.mainnet-beta.solana.com
```

### Network Connectivity

**RPC Endpoint Issues:**
- Unreachable endpoints
- Timeout problems
- Authentication failures

**Detection:**
```bash
Error: RPC request failed: Connection timeout
```

**Automatic Fix:**
```bash
# Test alternative endpoints
# Update configuration
# Setup ngrok tunnels if needed
```

## Multi-Stage Repair Process

```mermaid
stateDiagram-v2
    [*] --> Assessment
    Assessment --> Planning: Issues found
    Assessment --> Complete: No issues
    
    Planning --> Snapshot: Create safety point
    Snapshot --> SystemRepair: Start repairs
    
    SystemRepair --> SystemValidation: System update complete
    SystemValidation --> RustRepair: Validation passed
    SystemValidation --> RollbackSystem: Validation failed
    
    RustRepair --> RustValidation: Rust update complete
    RustValidation --> UserDepsRepair: Validation passed
    RustValidation --> RollbackRust: Validation failed
    
    UserDepsRepair --> UserValidation: User deps complete
    UserValidation --> Complete: Validation passed
    UserValidation --> RollbackUserDeps: Validation failed
    
    RollbackSystem --> Complete: System restored
    RollbackRust --> Complete: Rust restored
    RollbackUserDeps --> Complete: User deps restored
    
    Complete --> [*]
    
    classDef techDebt fill:#f6f6f6,stroke:#d9534f,color:#d9534f,font-family:Consolas,monospace,font-weight:bold
```

## Safety Systems

### System Snapshots

Automatic creation of system state snapshots before repairs.

**Snapshot Contents:**
- Package versions
- Configuration files
- Environment variables
- Service states

**Snapshot Management:**
```bash
# List available snapshots
osvm doctor --list-snapshots

# Restore from snapshot
osvm doctor --restore-snapshot <SNAPSHOT_ID>

# Clean old snapshots
osvm doctor --cleanup-snapshots
```

### Rollback Capabilities

Comprehensive rollback system for failed repairs.

**Rollback Triggers:**
- Repair verification failure
- System instability detection
- User-initiated rollback
- Timeout during repair

**Rollback Process:**
1. Stop current repair process
2. Restore previous package versions
3. Revert configuration changes
4. Restart affected services
5. Validate system health

### Health Validation

Post-repair validation ensures system stability.

**Validation Tests:**
- Basic command execution
- Network connectivity
- Service functionality
- Performance benchmarks

## Error Pattern Detection

### Log Pattern Analysis

Intelligent analysis of error logs and output patterns.

```mermaid
flowchart LR
    subgraph "Pattern Detection Pipeline"
        LOGS[Log Sources]
        EXTRACT[Pattern Extraction]
        MATCH[Pattern Matching]
        CONTEXT[Context Analysis]
        ACTION[Action Determination]
    end
    
    LOGS --> EXTRACT
    EXTRACT --> MATCH
    MATCH --> CONTEXT
    CONTEXT --> ACTION
    
    classDef techDebt fill:#f6f6f6,stroke:#d9534f,color:#d9534f,font-family:Consolas,monospace,font-weight:bold
```

**Supported Patterns:**
- Compilation errors
- Runtime exceptions
- Network timeouts
- Permission issues
- Configuration problems

### Machine Learning Integration

Advanced pattern recognition using historical data.

**Learning Components:**
- Error classification
- Repair success prediction
- Performance impact analysis
- Risk assessment

## Configuration

### Auto-Repair Settings

```yaml
self_repair:
  enabled: true
  auto_repair: false
  backup_before_repair: true
  max_repair_attempts: 3
  rollback_on_failure: true
  
monitoring:
  interval_seconds: 300
  health_check_timeout: 30
  log_analysis: true
  
safety:
  create_snapshots: true
  max_snapshots: 10
  require_confirmation: true
  dangerous_repairs_allowed: false
```

### Component-Specific Settings

```yaml
components:
  rust_toolchain:
    auto_update: true
    required_version: ">=1.70.0"
    components: ["rustfmt", "clippy"]
    
  solana_cli:
    auto_update: false
    version_check: true
    config_validation: true
    
  system_packages:
    auto_install: true
    package_manager: "auto"
    update_repos: true
```

## Emergency Recovery Mode

Special recovery mode for severe system issues.

### Activation

```bash
# Enter emergency recovery mode
osvm emergency-recovery

# Recovery with minimal dependencies
osvm emergency-recovery --minimal

# Factory reset mode
osvm emergency-recovery --reset
```

### Recovery Capabilities

**Minimal Bootstrap:**
- Clean Rust installation
- Basic Solana CLI setup
- Essential system dependencies
- Default configurations

**State Recovery:**
- Restore from backups
- Rebuild corrupted state
- Reset to known good configuration
- Preserve user data

## Monitoring and Alerting

### Health Metrics

Continuous collection of health indicators:

- **System Health Score:** Overall system status (0-100)
- **Component Status:** Individual component health
- **Repair Success Rate:** Historical repair effectiveness
- **Performance Impact:** System performance after repairs

### Alert Configuration

```yaml
alerts:
  health_score_threshold: 70
  component_failure_threshold: 2
  repair_failure_threshold: 3
  
notifications:
  email:
    enabled: true
    recipients: ["admin@example.com"]
  slack:
    enabled: false
    webhook_url: ""
  logs:
    enabled: true
    level: "warn"
```

## Best Practices

### Preventive Maintenance

1. **Regular Health Checks**
   ```bash
   # Schedule daily health checks
   crontab -e
   0 9 * * * /usr/local/bin/osvm doctor --auto-repair
   ```

2. **Monitoring Setup**
   ```bash
   # Enable continuous monitoring
   osvm doctor --enable-monitoring
   ```

3. **Backup Strategy**
   ```bash
   # Configure automatic backups
   osvm doctor --configure-backups
   ```

### Repair Strategy

1. **Start Conservative**
   - Begin with detailed diagnostics
   - Use dry-run mode first
   - Enable manual confirmation

2. **Gradual Automation**
   - Enable auto-repair for safe issues
   - Monitor repair success rates
   - Gradually increase automation scope

3. **Safety First**
   - Always create snapshots
   - Enable rollback capabilities
   - Monitor system stability

## Troubleshooting

### Common Issues

**Auto-Repair Fails:**
```bash
# Check repair logs
osvm doctor --show-logs

# Manual diagnostic
osvm doctor --detailed --verbose

# Force repair with override
osvm doctor --auto-repair --force
```

**Rollback Issues:**
```bash
# List available snapshots
osvm doctor --list-snapshots

# Manual rollback
osvm doctor --rollback --snapshot <ID>

# Emergency recovery
osvm emergency-recovery
```

**Performance Degradation:**
```bash
# Check system health
osvm doctor --performance-check

# Analyze repair impact
osvm doctor --repair-analysis

# Optimize configuration
osvm doctor --optimize
```

## Integration with Other Systems

### CI/CD Integration

```yaml
# GitHub Actions example
- name: OSVM Health Check
  run: |
    osvm doctor --auto-repair
    if [ $? -ne 0 ]; then
      echo "Health check failed"
      exit 1
    fi
```

### Monitoring Integration

```bash
# Prometheus metrics endpoint
curl http://localhost:9090/metrics | grep osvm_health

# Grafana dashboard integration
osvm doctor --export-metrics --format grafana
```

## Related Documentation

- [Log Monitoring]log-monitoring.md - Real-time log analysis
- [Node Management]node-management.md - Node health monitoring
- [Configuration]configuration.md - System configuration
- [Installation]installation.md - Initial system setup