ruvnet/RuView · error · ValueError

window_size must be positive

Error message

window_size must be positive

What it means

Raised by CSIProcessor._validate_config during __init__ when window_size is present but <= 0. window_size controls the sliding window length in samples for feature extraction; zero or negative windows would produce empty slices and broken FFT outputs, so construction is rejected immediately.

Source

Thrown at archive/v1/src/core/csi_processor.py:114

        """Validate configuration parameters.
        
        Args:
            config: Configuration to validate
            
        Raises:
            ValueError: If configuration is invalid
        """
        required_fields = ['sampling_rate', 'window_size', 'overlap', 'noise_threshold']
        missing_fields = [field for field in required_fields if field not in config]
        
        if missing_fields:
            raise ValueError(f"Missing required configuration: {missing_fields}")
        
        if config['sampling_rate'] <= 0:
            raise ValueError("sampling_rate must be positive")
        
        if config['window_size'] <= 0:
            raise ValueError("window_size must be positive")
        
        if not 0 <= config['overlap'] < 1:
            raise ValueError("overlap must be between 0 and 1")
    
    def preprocess_csi_data(self, csi_data: CSIData) -> CSIData:
        """Preprocess CSI data for feature extraction.
        
        Args:
            csi_data: Raw CSI data
            
        Returns:
            Preprocessed CSI data
            
        Raises:
            CSIProcessingError: If preprocessing fails
        """
        if not self.enable_preprocessing:
            return csi_data

View on GitHub (pinned to 4685618388)

Solutions

  1. Set window_size to a positive number of samples, typically 64–256 for CSI windows.
  2. If window_size is computed from data, guard: `window_size = max(1, min(available_samples, desired))` and skip processing when too few samples exist.
  3. Do not use 0 to mean auto; the validator rejects it — pick an explicit positive value.
  4. Check units: window_size is in samples, not seconds; convert `seconds * sampling_rate` before passing.

Example fix

# before
window = int(0.5 * 0)  # duration misparsed as 0
config = {'sampling_rate': 100, 'window_size': window, 'overlap': 0.5, 'noise_threshold': 0.1}

# after
window = max(1, int(0.5 * 100))  # 50 samples for 0.5 s at 100 Hz
config = {'sampling_rate': 100, 'window_size': window, 'overlap': 0.5, 'noise_threshold': 0.1}
Defensive patterns

Strategy: validation

Validate before calling

window = int(config.get('window_size', 0))
if window < 1:
    window = max(1, min(desired_window, available_samples))
config['window_size'] = window

Try / catch

try:
    processor = CSIProcessor(config)
except ValueError as e:
    if 'window_size must be positive' in str(e):
        config['window_size'] = 64  # sane default
        processor = CSIProcessor(config)
    else:
        raise

Prevention

When it happens

Trigger: Constructing CSIProcessor with window_size=0 or negative, e.g. CSIProcessor({'sampling_rate': 100, 'window_size': 0, 'overlap': 0.5, 'noise_threshold': 0.1}). Also fires when window_size is computed as a fraction of a buffer that is empty.

Common situations: Deriving window_size from packet count on a cold start with zero packets captured; config templates with 0 placeholders; tuning scripts that sweep values and include 0; window_size derived as `int(duration * rate)` where duration or rate is 0; mismatch between samples-per-burst config and expected window units.

Related errors


AI-assisted analysis of ruvnet/RuView@4685618388 (2026-08-16). Data as JSON: /api/errors/8a3a4208cc1faf28. Report an issue: GitHub.