← Back to Pull requests

feat(cleanup): load trust policies from GitHub and usage from BigQuery #1796

Closed
unknown closed this pull request without merging on Oct 22, 2026 16:00 UTC
View on GitHub
unknown unknown commented on Oct 22, 2026 13:56 UTC
Author

Related to #1075

Second of the policy cleanup PRs, after #1792. It adds read-only loaders for the inputs cleanup.Decide needs. Nothing calls them yet, and none of the deployed binaries (app, webhook, prober, negative-prober) imports them.

cleanup.ListPolicies (GitHub)

  • Lists the repositories the installation was granted, over REST (/installation/repositories, 100 per page), skipping archived repos and repos with a different owner. GraphQL's organization.repositories would also return public repos the App isn't installed on, where the job can't open PRs.

  • Reads the policy directories and each policy file's last change through GraphQL, in batches of 50 repos: one query for the directories (object(expression: "HEAD:<dir>")) and one for the last changes (history(first: 1, path: ...)). Each query costs about 1 point from GraphQL's quota, which is separate from REST. For a 2,000-repo org that's about 20 REST calls plus 40–80 points, rather than 2,000+ REST calls.

  • Only files named <identity>.sts.yaml count. A file with no history gets an unknown date, which Decide treats as "keep".

  • Forks are included: their policies are live, so they're standing access like any other. Archived repos are skipped because a cleanup PR can't land there.

  • A NOT_FOUND error, such as for a repo deleted since it was listed, leaves that repo without policies, so nothing is removed. Any other GraphQL error fails the run.
  • pkg/cleanup/bigquery

  • Load(since, now) returns each org's latest success, latest failure, and latest error per (scope, identity) since since. Scopes are resolved with path.Dir/path.Base, the same way the exchange does, so acme//svc and ./acme count as acme/svc and acme.

  • History.Start is the first exchange of the earliest day in the run of consecutive UTC days with exchanges that ends today or yesterday. Event delivery is best effort, so a missing or stale day moves Start past the gap, and Decide declines to run. This assumes at least one exchange per day, which the prober guarantees.

  • History.For(org) looks up an org's usage case-insensitively.

  • The exchange table is partitioned by ingestion time, so the usage query bounds _PARTITIONTIME. The days query reads only the time column.

  • New only accepts project.dataset.table, and the name goes inside backticks. Project and table names may contain hyphens (the real table is dev_octo-sts_exchange); datasets may not.
  • Testing

  • ListPolicies runs against a fake GitHub that serves the REST listing and answers GraphQL by parsing the aliased query. It covers two pages of repos; archived, other-owner, fork, empty and deleted repos; non-policy files, a subdirectory, an empty .sts.yaml name; batching across 120 repos (with the history query skipped for a batch with no policies); and both HTTP and GraphQL errors. 98.7% coverage.

  • Load runs against a fake BigQuery jobs.query endpoint. The gap logic has its own tests: unbroken history, today not loaded yet, a gap, and stale data. 96.7% coverage.

  • Checked against real systems, read-only:

  • - Both GraphQL queries, as the code builds them, ran against the octo-sts org at 1 point each. The dates match REST, and a nonexistent repo was tolerated.
    - The BigQuery queries ran against the staging table: 7 usage pairs, and 94 consecutive days with no gaps (the days query scans 3.9 MB).

    Dependency: adds cloud.google.com/go/bigquery v1.85.0 as a direct dependency. It was already in the module graph. Its minimum versions also bring in Arrow and a few golang.org/x modules as indirect dependencies.

    Next: the code that opens the cleanup PRs and the failing-policy issues, then the scheduled job in staging as a dry run.

    🤖 Generated with Claude Code

    Diff: 477 lines (+357 / -120) across 5 files Reviewer: cpanato Review duration: 124m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 477 lines diff across 5 files
    0.46
    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.369
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1796"
    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: 45.8% (MEDIUM) · Higher = larger blast radius
    45.8%
    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: 18.1% · Safe to merge
    18.1%
    Repository