Skip to content

Commit 8884662

Browse files
Merge pull request #79 from Agent-Hellboy/fix-54
Improve docs
2 parents 6fe3424 + 6df0f65 commit 8884662

File tree

14 files changed

+3392
-160
lines changed

14 files changed

+3392
-160
lines changed

docs/architecture.md

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,28 @@ The fuzzing engine orchestrates the testing process and manages test execution.
256256
5. **Invariant Verification**: Verify responses against property-based invariants
257257
6. **Analysis**: Analyze results and generate reports
258258

259-
### 4. Strategy System
259+
### 4. Runtime Management System
260+
261+
The runtime management system provides robust, asynchronous subprocess lifecycle management for transports and target servers under test.
262+
263+
**Key Components:**
264+
265+
- `manager.py`: Fully async ProcessManager for start/stop processes, send signals, await exit, collect stats
266+
- `watchdog.py`: ProcessWatchdog for monitoring registered PIDs for hangs/inactivity and terminating them based on policy
267+
- `executor.py`: AsyncFuzzExecutor providing concurrency control, error handling, and result aggregation
268+
269+
**Runtime Features:**
270+
271+
- **Fully Async API**: All operations use native asyncio; blocking calls run in thread executors
272+
- **Process-Group Signaling**: On POSIX systems, uses process-group signaling to prevent orphan children
273+
- **Safe Stop Flow**: TERM (grace window) → KILL on timeout if needed
274+
- **Watchdog Auto-Management**: Auto-starts on first registration/start; auto-unregisters on stop
275+
- **Activity Monitoring**: Supports activity callbacks for hang detection
276+
- **Concurrency Control**: Bounded concurrency with semaphore-based limiting
277+
- **Retry Mechanisms**: Configurable retry with exponential backoff
278+
- **Batch Operations**: Execute multiple operations concurrently with result collection
279+
280+
### 5. Strategy System
260281

261282
The strategy system generates test data using different approaches.
262283

@@ -318,7 +339,7 @@ The safety system provides multiple layers of protection against dangerous opera
318339
- **Process Isolation**: Safe subprocess handling with timeouts
319340
- **Input Sanitization**: Filters potentially dangerous input
320341

321-
### 6. Authentication System
342+
### 7. Authentication System
322343

323344
The authentication system manages various authentication methods for MCP servers.
324345

@@ -335,7 +356,7 @@ The authentication system manages various authentication methods for MCP servers
335356
- **OAuth token authentication**
336357
- **Custom header authentication**
337358

338-
### 7. Reporting System
359+
### 8. Reporting System
339360

340361
The reporting system provides centralized output management and comprehensive result reporting.
341362

@@ -365,6 +386,79 @@ The reporting system provides centralized output management and comprehensive re
365386
- **Safety Reports**: Detailed safety system data and blocked operations
366387
- **Session Reports**: Metadata, configuration, and execution statistics
367388

389+
## Runtime Management Details
390+
391+
### ProcessManager
392+
393+
The `ProcessManager` provides fully asynchronous subprocess lifecycle management with the following capabilities:
394+
395+
**Core Features:**
396+
- **Async Process Creation**: Uses `asyncio.create_subprocess_exec` for non-blocking process spawning
397+
- **Process Registration**: Automatically registers processes with the watchdog for monitoring
398+
- **Signal Handling**: Supports graceful termination (SIGTERM) and force kill (SIGKILL) with process-group signaling
399+
- **Status Tracking**: Maintains comprehensive process state including start time, status, and configuration
400+
- **Cleanup Management**: Automatic cleanup of finished processes to prevent resource leaks
401+
402+
**Process Lifecycle:**
403+
1. **Start**: Process is created with asyncio, registered with watchdog, and tracked in manager
404+
2. **Monitor**: Watchdog monitors for hangs and inactivity using activity callbacks
405+
3. **Stop**: Graceful termination with escalation to force kill if needed
406+
4. **Cleanup**: Process is unregistered from watchdog and removed from tracking
407+
408+
**Configuration Options:**
409+
- `command`: List of command and arguments
410+
- `cwd`: Working directory for the process
411+
- `env`: Environment variables (merged with current environment)
412+
- `timeout`: Default timeout for process operations
413+
- `auto_kill`: Whether to automatically kill hanging processes
414+
- `name`: Human-readable name for logging and identification
415+
- `activity_callback`: Optional callback to report process activity
416+
417+
### ProcessWatchdog
418+
419+
The `ProcessWatchdog` provides automated monitoring and termination of hanging processes:
420+
421+
**Monitoring Features:**
422+
- **Activity Tracking**: Monitors process activity through callbacks or timestamps
423+
- **Hang Detection**: Identifies processes that haven't been active for configured timeout periods
424+
- **Automatic Termination**: Can automatically kill hanging processes based on policy
425+
- **Configurable Thresholds**: Separate thresholds for warning, timeout, and force kill
426+
427+
**Configuration Options:**
428+
- `check_interval`: How often to check processes (default: 1.0 seconds)
429+
- `process_timeout`: Time before process is considered hanging (default: 30.0 seconds)
430+
- `extra_buffer`: Extra time before auto-kill (default: 5.0 seconds)
431+
- `max_hang_time`: Maximum time before force kill (default: 60.0 seconds)
432+
- `auto_kill`: Whether to automatically kill hanging processes (default: true)
433+
434+
**Activity Callbacks:**
435+
Processes can register activity callbacks that return timestamps indicating when they were last active. This allows for more sophisticated hang detection based on actual process activity rather than just time elapsed.
436+
437+
### AsyncFuzzExecutor
438+
439+
The `AsyncFuzzExecutor` provides controlled concurrency and robust error handling for fuzzing operations:
440+
441+
**Concurrency Control:**
442+
- **Bounded Concurrency**: Uses semaphore to limit concurrent operations
443+
- **Task Tracking**: Maintains set of running tasks for proper shutdown
444+
- **Batch Operations**: Execute multiple operations concurrently with result collection
445+
446+
**Error Handling:**
447+
- **Timeout Management**: Configurable timeouts for individual operations
448+
- **Retry Logic**: Exponential backoff retry mechanism for failed operations
449+
- **Exception Collection**: Collects and categorizes errors from batch operations
450+
451+
**Configuration Options:**
452+
- `max_concurrency`: Maximum number of concurrent operations (default: 5)
453+
- `timeout`: Default timeout for operations (default: 30.0 seconds)
454+
- `retry_count`: Number of retries for failed operations (default: 1)
455+
- `retry_delay`: Delay between retries (default: 1.0 seconds)
456+
457+
**Usage Patterns:**
458+
- **Single Operations**: Execute individual operations with timeout and error handling
459+
- **Retry Operations**: Execute operations with automatic retry on failure
460+
- **Batch Operations**: Execute multiple operations concurrently with bounded concurrency
461+
368462
## Execution Flow
369463

370464
### Tool Fuzzing Flow

0 commit comments

Comments
 (0)