Draft: Check a low Go module bump against what upstream ships before it can auto-approve
What does this MR do and why?
Part of #40, tasks B1 and B2. Today the deps flow rates a bump from its version number alone. A patch that breaks things, or a compromised release, still rates low and can be auto-approved. This MR adds a stage after approval_rules and raise_below_one that checks a low Go module bump against what the module actually ships. The stage can raise the tier but never lower it.
How it works
| Step | What it does |
|---|---|
fetch_upstream |
Runs only when the tier is still low. It:• takes the one Go module the bump moves; • fetches both versions' zips from proxy.golang.org;• checks their h1: hashes against sum.golang.org and the MR's go.sum;• diffs them with git and looks for red flags in what the new version adds;• works out whether any changed file can reach a consumer's build; • writes upstream.json and a route word. |
review_upstream |
A judge with no tools. It reads the fetch step's output, which is the release notes and the diff, and answers with one JSON object. It is reached only when the data is complete, the checksums match, nothing is flagged and a changed file is built. |
decide_labels |
Runs keep_higher_tier first, then labels as before. keep_higher_tier keeps the highest of the model's tier, the checks and the judge, and writes tier.txt back with the deciding reason first. The two are packed as one script, because a separate step costs bytes the catalog cap can't spare. DecideLabels.main runs in an ensure, so a bump is still labelled severe when keep_higher_tier raises. Without tier_model.txt, keep_higher_tier writes nothing. |
-
What goes to a person without a model:
- a checksum mismatch;
- a red flag: a new import of
os/exec,net/http,unsafe,pluginor cgo,//go:linkname, a newinit, a long encoded string, or a binary file; - incomplete data: a tool pin, more than one module, a redirected zip, a failed request, or judge input over 48 KB.
A malformed judge answer also goes to a person.
-
What keeps its
lowwithout the judge: a bump that changes nothing a consumer builds.- Built means:
- Go outside
_test.go,testdata/included; - any change to
go.modother than the versions of modules it already requires. That includes thegoline, indented or not, a new or removed requirement, and areplace.
- Go outside
- If the module has C, assembly, SWIG, Fortran or
.sysofiles, a//go:embed, or a quotedCin its non-test Go, every changed file counts as built. - Only an explicit
built: falseskips the judge, and only after the checksum and red-flag checks pass. A missing or garbledbuiltgoes to the judge.
- Built means:
-
The judge's rubric (
src/deps/prompts/review_upstream.system.md):- It rates the diff: "Notes can cover other modules: never rate what only they describe."
- High for code that runs on import, fetches or runs code, reads secrets, contacts a host or weakens security, or any file hiding its content.
- Medium for:
- a removed or changed export, changed
//go:or#cgolines, a new method or dependency, or new file, process, network or environment access; - any other change in what production code does that the notes omit, "even a small internal fix".
- a removed or changed export, changed
- "Otherwise low, even a new unused constant."
-
Fails closed.
- A
run_commandthat exits non-zero still routes as a success, so the stage does not rely on exit codes. fetch_upstreammovestier.txtaside first, and onlykeep_higher_tierwrites it back.- A failure before
keep_higher_tierraises alowtomedium. - A failure in
keep_higher_tierleaves notier.txt, whichdecide_labelslabelssevere. fetch_upstreamalso clearsjudge.txt.create_file_with_contentswon't overwrite, so ajudge.txtalready in the working directory would otherwise stand in for the judge's answer.
- A
-
48 KB cap. The Duo CLI passes a command's output on whole only up to 51,200 bytes, with stderr merged and an exit-code line in front. Past that it keeps only the head and tail. The judge's whole input is capped at 48 KB so the judge never reviews a cut diff.
-
Network. HTTPS GETs to two hard-coded hosts, with no credentials and no redirects followed. Each pilot has to allow
proxy.golang.organdsum.golang.orgin.gitlab/duo/agent-config.yml(task R1). Until then every request fails and everylowgoes to a person. -
The scripts' loader calls
Zlib.inflate, which isZlib::Inflate.inflateunder a shorter name, on every Ruby a runner may have.bin/compile'sscripttakesrun:, the steps whosemainit calls, and refuses a name it wasn't given.
Validation
make checkon this branch, which mergesmainat 4d4e7911, fails only onmain's own lint offense:- specs: 751 deps, 390 flow, 163 mr-risk and 130 eval examples, 0 failures. The
spec/evalupstream specs thatmainskips, because they needfetch_upstreamin the flow, run and pass here; - RuboCop, at the Ruby 2.7 target, reports only
main'sStyle/SelectByKindoffense insrc/mr-risk/scripts/payload.rb, which !106 (closed) fixes; - every flow in
flows/is current, and yamllint passes on the repository's YAML.
- specs: 751 deps, 390 flow, 163 mr-risk and 130 eval examples, 0 failures. The
- Two independent reviews.
- An adversarial review of the stage, through five lenses with three skeptics per finding. The confirmed findings are fixed, except one shared-step bug that predated this change, which !100 (merged) fixed.
- A review of the built rule, which found two ways round a first draft. Both are fixed, with specs:
- cgo imported as
import ("C"),import"C"orimport /**/ "C"; - a changed
goline that is indented, or that hides behind a decoy line in an unknown block.
- cgo imported as
fetch_upstreamrun for real, outside the sandbox, on the sixlowGo module cases in thedeps-pilotssuite thatapproval_rulesleaveslow. A rerun on all fourteendeps-pilotscases that save upstream output matches the saved files byte for byte,builtincluded.
| Case | Bump | Checksum | Route |
|---|---|---|---|
| zoekt-1073 | labkit v1.65.1 → v1.65.3 | ok | unbuilt: keeps low |
| zoekt-1059 | labkit v1.64.20 → v1.64.21 | ok | unbuilt: keeps low |
| zoekt-1038 | gopsutil/v4 v4.26.7 → v4.26.8 | ok | judge, 34 KB of input |
| es-indexer-890 | grpc v1.79.2 → v1.79.3 | ok | person: 68 KB diff |
| es-indexer-881 | go-enry/v2 v2.9.4 → v2.9.5 | ok | person: 4.3 MB diff, and a new unsafe import |
| es-indexer-855 | go-enry/v2 v2.9.3 → v2.9.4 | ok | person: 4.0 MB diff |
- B3.
bin/evalran both deps suites with three passes per case,git:origin/mainagainst this branch, and scored them with !104 (closed)'s scorecard. That was 294 Duo sessions, and 8 more to rerun one case. The flow it scored is this branch'sflows/deps.ymlfrom beforemainat 4d4e7911 came in. That merge changes only the packedapproval_rules, with !96 (merged)'s tool-key rules for bench, and leaves the stage as scored.deps-upstream, 72 sessions:- Judge as expected is 27/27, fetch as expected 9/9, and approvable cases approved 15/15.
- Every case labelled
raise,checkorincompletegoes to a person in every pass. That includes all four planted dangers and the over-the-cap case. - All 24 judge answers are one JSON object naming a tier.
deps-pilots, 222 sessions:- No run approves a case that has to go to a person.
- Judge as expected is 9/9: zoekt-1038 is judged
medium, and zoekt-1073 and zoekt-1059 are unbuilt and approved. Fetch as expected is 24/24.
- The stage lowers no run. The scorecard lists one case as less cautious than
main: es-indexer-863, labelledmediumin all three passes againsthighonmain.- The classifier answered
medium, and the stage skipped the case, since only alowreaches it. - Four more passes each gave
mainM1 H3 and this branch M2 H2. - Both tiers send the bump to a person.
- The classifier answered
- This run is the definitive B3, unless P3 changes the stage.
- How the rubric got here.
- The first B3 run, on an earlier prompt, kept es-indexer-865-upstream
lowin two passes of three. So two runs approved a fix the notes don't mention, which its label sends to a person. - Six candidate prompts were screened with real judge runs. The chosen one names the changes a release can hide behind, and raised 865 in every pass it was tried.
- It left two false alarms, recorded in #43 and fixed by !109 (merged), which merged into this branch:
- zoekt-1068-upstream was raised in 18 passes out of 18, across seven prompt wordings. Its diff changes CI, docs, a build script,
go.modversions andgo.sum, but no Go. The built rule now keeps it from the judge. - es-indexer-871-upstream was raised in two passes of three, for an added constant the notes announce. The rubric's last clause covers it.
- zoekt-1068-upstream was raised in 18 passes out of 18, across seven prompt wordings. Its diff changes CI, docs, a build script,
- The first B3 run, on an earlier prompt, kept es-indexer-865-upstream
- zoekt-1038's label. This MR changes its
upstreamlabel inevals/suites/deps-pilots.ymlfromkeeptoraise. The judge rates itmediumin every pass. The Windows command-line fallback in gopsutil v4.26.8 reads processes the module used to skip, and the rubric rates new process accessmediumwhether or not the release notes name it. The suite's labels follow the rubric. - Six new
deps-upstreamcases. A person labelled each of these pilot bumps, but none reaches the judge indeps-pilots, because the model orapproval_rulesrates it abovelow. Each<case>-upstreamcopy carries that case's own upstream output, unedited, on a pilot merge request the model rateslow. - Open: P3. This MR leaves draft once P3 confirms the sandbox assumptions: that
gitis present, and that a command's output reaches the next step whole up to 51,200 bytes.
Size
flows/deps.yml on main with |
Bytes | Under the 40,960 cap |
|---|---|---|
| this MR | 40,777 | 183 |
| this MR, !95 (closed) and !101 (closed) | about 40,938 | about 22 |
- The estimate adds the other two MRs' own change to
flows/deps.yml: 93 and 68 bytes.mainnow includes !96 (merged), whose 360 bytes this MR's row already counts. - Other flows. The shorter loader also makes
flows/flow.ymlandflows/mr-risk.ymlsmaller. - What comes next. Every row is past the 36,864-byte split threshold. The gem and npm work for gitlab-org/gitlab, release 2 and #42's facts step won't fit in the same flow, so the deps flow needs a split first.
Not in this MR
- What B3 can't show:
- the fetch in the sandbox, because a run replays saved fetch output (P3, R2);
- how the judge does on more real upstream changes than these suites hold;
- what the prompt's narrower rules cost. No case adds an exported function or type, changes a
#cgoor//go:line, or hides a short encoded string or atestdata/blob.
- Where the built rule can miss:
- Consumers below Go 1.17. Their
go.modneed not list every module the build selects. So a dependency'sgo.modthat raises another module's version can change what the consumer builds, without touching the consumer'sgo.mod. It shows only in the consumer'sgo.sum, which the model reads. - Code that reads its own module's files at run time, for example through
runtime.Callerpaths into the module cache. This can't happen in a binary built from the module, but it can under the consumer'sgo testorgo run.
- Consumers below Go 1.17. Their
- The judge's first reason is cut mid-word.
keep_higher_tierwrites it cut at 160 characters. The judge is asked for at most twenty words, and some of its reasons run longer. - R1: the
agent-config.ymlMRs in the two Go pilots. - Release 2: GitHub release downloads for tool pins, and crates.
- The elasticsearch-indexer
lows. The three Go modulelows that reach the stage go to a person under the 48 KB cap. Its gitaly bumps never reach it, becauseapproval_rulesraises them tomedium. Showing the judge only the Go code that ships could fit more of them in, which is a decision for #40.
How to set up and validate locally
- Run
make checkwith a UTF-8 locale. - Optional, with real network access: in a temp dir holding a saved
mr.json, anmr_diff.jsonand atier_model.txtcontaininglow, runruby -e 'require "<repo>/src/deps/scripts/fetch_upstream"; FetchUpstream.main'. Then readupstream.json,upstream_route.txtand stdout.
The commits skipped the pre-commit prettier hook with SKIP=prettier, because the hook's Node setup fails on the machine they were made on. Every other hook ran and passed.