Module backpressure

Module backpressure 

Source
Expand description

Backpressure validation for maintaining code quality during automated execution.

Runs programmatic validation (build, test, lint) after task completion. See backpressure::run_validation for the main entry point. Backpressure validation for maintaining code quality during automated execution.

§Overview

Backpressure is a quality gate mechanism that runs programmatic validation after each wave of task execution. It prevents bad code from accumulating by catching issues early - if validation fails, the affected tasks are marked as Failed so they can be re-attempted or debugged.

§What Backpressure Validates

  • Build/compile checks - Ensures code compiles successfully
  • Linting - Catches style issues and common mistakes
  • Type checking - Validates type correctness (for typed languages)
  • Tests - Runs the test suite to catch regressions

§Workflow Integration

In swarm mode, backpressure runs after each wave completes:

Wave 1: [Task A, Task B] -> Backpressure Check -> Pass? -> Wave 2
                                   |
                                   v
                            Fail? -> Mark tasks as Failed

This creates a feedback loop where AI agents can see which tasks caused validation failures and attempt repairs.

§Configuration

Backpressure commands are configured in .scud/config.toml:

[swarm.backpressure]
commands = ["cargo build", "cargo test", "cargo clippy -- -D warnings"]
stop_on_failure = true  # Stop at first failure (default: true)
timeout_secs = 300      # Per-command timeout (default: 300 = 5 minutes)

If no configuration is found, backpressure auto-detects commands based on project type (Rust, Node.js, Python, Go).

§Example

use std::path::Path;
use scud::backpressure::{BackpressureConfig, run_validation};

// Load configuration (auto-detects if not configured)
let config = BackpressureConfig::load(None).expect("Failed to load config");

// Or create a custom configuration
let custom_config = BackpressureConfig {
    commands: vec![
        "cargo build".to_string(),
        "cargo test".to_string(),
    ],
    stop_on_failure: true,
    timeout_secs: 300,
};

// Run validation in a working directory
let working_dir = Path::new(".");
let result = run_validation(working_dir, &custom_config).expect("Validation failed");

if result.all_passed {
    println!("All checks passed!");
} else {
    println!("Failures: {:?}", result.failures);
    for cmd_result in &result.results {
        if !cmd_result.passed {
            println!("  {} failed with code {:?}", cmd_result.command, cmd_result.exit_code);
            println!("  stderr: {}", cmd_result.stderr);
        }
    }
}

§Auto-Detection

When no explicit configuration exists, backpressure detects project type:

Project TypeDetected ByDefault Commands
RustCargo.tomlcargo build, cargo test
Node.jspackage.jsonScripts: build, test, lint, typecheck
Pythonpyproject.toml or setup.pypytest
Gogo.modgo build ./..., go test ./...

Structs§

BackpressureConfig
Backpressure configuration
CommandResult
Result of a single command
ValidationResult
Result of running validation

Functions§

run_validation
Run backpressure validation