← Back to Pull requests

fix(cleanup): cap history lookups per query and catch stalled loads #1798

Closed
unknown closed this pull request without merging on Oct 22, 2026 19:49 UTC
View on GitHub
unknown unknown commented on Oct 22, 2026 16:29 UTC
Author

Related to #1075

Follow-up to two non-blocking review notes on #1796. Nothing calls this code yet.

Cap history lookups per query (note)
lastChanged built one query per batch of 50 repos, with one history(path:) field per policy, so a few repos with hundreds of policies could produce a query large enough to time out, and fail the same way every month. The lookups are now split into queries of at most 100 (historyPerQuery), regardless of how they're spread across repos. Cost doesn't change, about 1 point per 100 lookups.

Catch loads that stalled recently (note)
When today has no rows, the day walk starts at yesterday, so a load that stalled early yesterday went unnoticed. The days query now also returns each day's last exchange. History.Latest holds the newest one, and History.Start stays zero, which Decide refuses, when Latest is more than MaxStaleness (6 hours) old. The recorder loads every 15 minutes and the prober exchanges every few minutes, so 6 hours of silence means events stopped arriving. On staging the latest exchange was 14 minutes old.

What this still doesn't catch: the recorder loads each region separately, so a stall in one region still leaves fresh rows from the others.

Testing

  • A new test puts 280 policies in two repos and checks that they take three history queries and every date comes back right. The fake GitHub now fails any query with more than 100 lookups. With the cap raised to 1,000, the test fails.

  • New staleness tests cover fresh history, history exactly at the limit, a minute past it, and a stall that started early yesterday.

  • Coverage is 98.0% for pkg/cleanup and 96.9% for the BigQuery package, with -race. Lint is clean.
  • 🤖 Generated with Claude Code

    Diff: 239 lines (+179 / -60) across 2 files Reviewer: cpanato Review duration: 200m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.37) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 239 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.328
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1798"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 37.2% (MEDIUM) · Higher = larger blast radius
    37.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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 14.7% · Safe to merge
    14.7%
    Repository