← Back to Pull requests

refactor: `validation` module rewrite #40

Open
unknown opened this pull request with 334 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 20, 2026 11:18 UTC
Author

About


This PR contains a completely rewritten validation logic.
The validation can be divided into several types:
  • Dummy validation, when you don’t need internet access to validate data.

  • fn verify_image_url(image_url: &str) -> bool {
        if image_url.is_empty() {
            return true;
        }
    
        let Ok(url) = url::Url::parse(image_url) else {
            return false;
        };
    
        let Some(host) = url.host_str() else {
            return false;
        };
    
        for thumbnail_domain in ALLOWED_THUMBNAIL_DOMAINS {
            if host.ends_with(thumbnail_domain) {
                return true;
            }
        }
    
        false
    }
    

  • Validating with a database where you just check if this value already exists or not

  • async fn is_channel_validation_required(conn: &mut DbConnection, channel: &Channel) -> bool {
        if !CONFIG.validate_submitted_metadata {
            return false;
        }
    
        // verification is only required if the channel doesn't exist yet or has changed since then
        if let Some(existing_channel) = get_channel_by_id(conn, &channel.id).await.ok().flatten()
            && *channel == existing_channel
        {
            return false;
        }
    
        true
    }
    

  • Validation using Ytrss, which uses data from YouTube.

  • pub async fn validate_channel_information_if_changed(
        conn: &mut DbConnection,
        channel: &mut Channel,
    ) -> HandlerResult<()> {
        if !is_channel_validation_required(conn, channel).await {
            return Ok(());
        }
    
        let rss_channel = RssChannel::fetch_from_channel_id(&channel.id)
            .await
            .map_err(|_| HandlerError::YouTubeConnectError)?;
    
        validate_channel_information(channel.clone(), &rss_channel)
            .map_err(|_| HandlerError::ValidationError)?;
    
        Ok(())
    }
    

    All three types were mixed into one. To fix this, a trait Validation was implemented, containing functions for validating the channel, video or playlist. Functions return ValidationResult

    pub enum ValidationResult<T> {
        Valid,
        ValidAfterChanges(T),
        UnableToValidate,
        Invalid(ValidationError),
    }
    

    The CompositeValidator structure combines impl Validation into a chain and continues it until impl Validator returns Valid, ValidAfterChanges or Invalid.

    In addition to DummyValidator, DbValidator and YtrssValidator was created InnertubeValidator. It uses crate for parsing metadata from YouTube and can be useful if YouTube RSS does not respond or cannot validate.

    ValidAfterChanges(T) is used to pass metadata that has been modified by the validator. This helps prevent data from being overwritten as invalid.

    Closed issues


    #25 #38 #39

    Diff: 334 lines (+250 / -84) across 4 files Reviewer: Bnyro Review duration: 10966m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.42) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 334 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.348
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #40"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.2% (MEDIUM) · Higher = larger blast radius
    42.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%