backpressure

package
v0.3.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package backpressure provides quality validation implementations

Package backpressure provides adaptive concurrency control for Drover

Package backpressure provides quality validation and backpressure mechanisms

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Check

type Check struct {
	ID          string                 `json:"id"`
	Name        string                 `json:"name"`
	Type        CheckType              `json:"type"`
	Description string                 `json:"description"`
	Enabled     bool                   `json:"enabled"`
	Config      map[string]interface{} `json:"config"`
	CreatedAt   int64                  `json:"created_at"`
	UpdatedAt   int64                  `json:"updated_at"`
}

Check defines a validation check

type CheckResult

type CheckResult struct {
	CheckID   string        `json:"check_id"`
	Passed    bool          `json:"passed"`
	Message   string        `json:"message"`
	Duration  time.Duration `json:"duration"`
	Timestamp int64         `json:"timestamp"`
	Metadata  interface{}   `json:"metadata,omitempty"`
}

CheckResult is the result of a validation check

type CheckType

type CheckType string

CheckType defines the type of validation check

const (
	CheckTypeCommand CheckType = "command" // Run shell command
	CheckTypeLLM     CheckType = "llm"     // LLM-based validation
	CheckTypeFile    CheckType = "file"    // File existence check
	CheckTypeRegex   CheckType = "regex"   // Regex pattern matching
)

type Config

type Config struct {
	ConfigPath string
	Logger     *log.Logger
}

Config holds manager configuration

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

Controller manages adaptive concurrency based on downstream health

func NewController

func NewController(cfg ControllerConfig) *Controller

NewController creates a new backpressure controller

func (*Controller) CanSpawn

func (c *Controller) CanSpawn() bool

CanSpawn checks if a new worker can be spawned based on backpressure state

func (*Controller) GetBackoffDeadline

func (c *Controller) GetBackoffDeadline() time.Time

GetBackoffDeadline returns when the backoff period ends

func (*Controller) GetCurrentConcurrency

func (c *Controller) GetCurrentConcurrency() int

GetCurrentConcurrency returns the current max concurrency

func (*Controller) GetCurrentInFlight

func (c *Controller) GetCurrentInFlight() int

GetCurrentInFlight returns the current number of in-flight workers

func (*Controller) GetStats

func (c *Controller) GetStats() Stats

GetStats returns current statistics

func (*Controller) IsInBackoff

func (c *Controller) IsInBackoff() bool

IsInBackoff returns true if currently in backoff period

func (*Controller) OnWorkerSignal

func (c *Controller) OnWorkerSignal(signal WorkerSignal)

OnWorkerSignal processes a worker signal and adjusts backpressure state

func (*Controller) Reset

func (c *Controller) Reset()

Reset resets the controller to initial state

func (*Controller) WorkerFinished

func (c *Controller) WorkerFinished()

WorkerFinished decrements the in-flight counter

func (*Controller) WorkerStarted

func (c *Controller) WorkerStarted()

WorkerStarted increments the in-flight counter

type ControllerConfig

type ControllerConfig struct {
	InitialConcurrency int           // Starting concurrency level
	MinConcurrency     int           // Minimum concurrency (never go below)
	MaxConcurrency     int           // Maximum concurrency (never exceed)
	RateLimitBackoff   time.Duration // Initial backoff on rate limit
	MaxBackoff         time.Duration // Maximum backoff duration
	SlowThreshold      time.Duration // Response time considered slow
	SlowCountThreshold int           // Consecutive slow responses before reducing

	// Memory-aware settings (drover-mem-6)
	MemoryAwareEnabled bool  // Enable memory-aware spawning
	MemoryThresholdMB  int64 // Minimum available MB before throttling
	MemoryCriticalMB   int64 // Critical memory threshold - stop spawning
	WorkerRSSLimitMB   int64 // Per-worker RSS limit in MB
}

ControllerConfig holds backpressure controller configuration

func DefaultControllerConfig

func DefaultControllerConfig() ControllerConfig

DefaultControllerConfig returns default backpressure controller configuration

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager manages backpressure checks and rules

func NewManager

func NewManager(cfg Config) (*Manager, error)

NewManager creates a new backpressure manager

func (*Manager) CreateRule

func (m *Manager) CreateRule(rule *Rule) error

CreateRule creates a new rule

func (*Manager) EnableCheck

func (m *Manager) EnableCheck(id string, enabled bool) error

EnableCheck enables a check

func (*Manager) EnableRule

func (m *Manager) EnableRule(id string, enabled bool) error

EnableRule enables or disables a rule

func (*Manager) GetCheck

func (m *Manager) GetCheck(id string) (*Check, bool)

GetCheck retrieves a check by ID

func (*Manager) GetRule

func (m *Manager) GetRule(id string) (*Rule, bool)

GetRule retrieves a rule by ID

func (*Manager) ListChecks

func (m *Manager) ListChecks() []*Check

ListChecks returns all checks

func (*Manager) ListRules

func (m *Manager) ListRules() []*Rule

ListRules returns all rules

func (*Manager) LoadFromFile

func (m *Manager) LoadFromFile(path string) error

LoadFromFile loads checks and rules from a JSON file

func (*Manager) RegisterCheck

func (m *Manager) RegisterCheck(check *Check) error

RegisterCheck registers a new validation check

func (*Manager) SaveToFile

func (m *Manager) SaveToFile(path string) error

SaveToFile saves checks and rules to a JSON file

func (*Manager) SetLogger

func (m *Manager) SetLogger(logger *log.Logger)

SetLogger sets the logger for the manager

func (*Manager) Validate

func (m *Manager) Validate(ctx context.Context, ruleID string, input *ValidateInput) (*RuleResult, error)

Validate runs all enabled checks in a rule and returns the result

type Rule

type Rule struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Enabled     bool     `json:"enabled"`
	CheckIDs    []string `json:"check_ids"` // Checks to run
	Mode        string   `json:"mode"`      // "all" (all must pass) or "any" (one must pass)
	CreatedAt   int64    `json:"created_at"`
	UpdatedAt   int64    `json:"updated_at"`
}

Rule defines a backpressure rule

type RuleResult

type RuleResult struct {
	RuleID       string         `json:"rule_id"`
	Passed       bool           `json:"passed"`
	CheckResults []*CheckResult `json:"check_results"`
	Timestamp    int64          `json:"timestamp"`
}

RuleResult is the result of a rule evaluation

type Stats

type Stats struct {
	MaxInFlight     int       // Current max concurrency
	CurrentInFlight int       // Currently active workers
	BackoffUntil    time.Time // When backoff ends
	InBackoff       bool      // Currently in backoff
	ConsecutiveSlow int       // Count of slow responses
}

GetStats returns current controller statistics

type ValidateInput

type ValidateInput struct {
	TaskID      string                 `json:"task_id"`
	Title       string                 `json:"title"`
	Description string                 `json:"description"`
	Output      string                 `json:"output"`
	ProjectDir  string                 `json:"project_dir"`
	Metadata    map[string]interface{} `json:"metadata"`
}

ValidateInput is input for validation

type WorkerSignal

type WorkerSignal string

WorkerSignal represents downstream health signals from workers

const (
	SignalOK           WorkerSignal = "ok"            // Normal execution
	SignalRateLimited  WorkerSignal = "rate_limited"  // Rate limit detected
	SignalSlowResponse WorkerSignal = "slow_response" // Slow response
	SignalAPIError     WorkerSignal = "api_error"     // Transient API error
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL