feat(cleanup): load trust policies from GitHub and usage from BigQuery #1796
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
cpanato
Related to #1075
Second of the policy cleanup PRs, after #1792. It adds read-only loaders for the inputs
cleanup.Decideneeds. Nothing calls them yet, and none of the deployed binaries (app,webhook,prober,negative-prober) imports them.cleanup.ListPolicies(GitHub)/installation/repositories, 100 per page), skipping archived repos and repos with a different owner. GraphQL'sorganization.repositorieswould also return public repos the App isn't installed on, where the job can't open PRs.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.<identity>.sts.yamlcount. A file with no history gets an unknown date, whichDecidetreats as "keep".NOT_FOUNDerror, 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/bigqueryLoad(since, now)returns each org's latest success, latest failure, and latest error per (scope, identity) sincesince. Scopes are resolved withpath.Dir/path.Base, the same way the exchange does, soacme//svcand./acmecount asacme/svcandacme.History.Startis 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 movesStartpast the gap, andDecidedeclines 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._PARTITIONTIME. The days query reads only thetimecolumn.Newonly acceptsproject.dataset.table, and the name goes inside backticks. Project and table names may contain hyphens (the real table isdev_octo-sts_exchange); datasets may not.Testing
ListPoliciesruns 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.yamlname; batching across 120 repos (with the history query skipped for a batch with no policies); and both HTTP and GraphQL errors. 98.7% coverage.Loadruns against a fake BigQueryjobs.queryendpoint. The gap logic has its own tests: unbroken history, today not loaded yet, a gap, and stale data. 96.7% coverage.- Both GraphQL queries, as the code builds them, ran against the
octo-stsorg 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/bigqueryv1.85.0 as a direct dependency. It was already in the module graph. Its minimum versions also bring in Arrow and a fewgolang.org/xmodules 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