diff --git a/docs/rfcs/0035-pr-runtime-per-candidate-environments.md b/docs/rfcs/0035-pr-runtime-per-candidate-environments.md new file mode 100644 index 00000000..b6ff35ba --- /dev/null +++ b/docs/rfcs/0035-pr-runtime-per-candidate-environments.md @@ -0,0 +1,169 @@ +--- +title: "RFC 0035: pr_runtime per-candidate environments" +navTitle: "0035 · pr_runtime per-candidate environments" +--- + +**Status:** draft +**Author:** `rycerzes` +**Created:** 2026-11-27 · **Revised:** 2026-12-02 + +## Summary + +Build each candidate's environment at its base commit, on a clean toolchain image, and validate in the image the +task ships. Tracked in #253. + +## Today + +On `main` (62f1966): + +- Bootstrap installs dependencies once, at the bootstrap ref. Validation and the task Dockerfile reset Git to the + base and keep those dependencies (`BOOTSTRAP.md`, corrected in #281). +- `rebuild_cmds` is saved by bootstrap but never run by `pr_runtime`. A gold patch or agent diff that edits a native + extension (for example `pydantic-core`) is tested against the extension built at the bootstrap ref. +- #279 can run each validation stage in a fresh container. It does not change the network. +- Validation containers use Docker's default network (`DockerSandbox.start` has no network argument). The shipped + task sets no `network_mode`; the agent runs under the #257 host denylist plus offline settings. +- LLM spend is capped per bootstrap (`max_llm_spend_usd`). There is no run-wide cap. + +## Motivation + +Contributor measurements, not maintainer-verified; revisions and commands are in [Measurements](#measurements). + +- hugo, one bootstrap: 2 tasks from 185 candidates. Re-anchoring the bootstrap per two-week window: 19. The same plus + `go mod download` at each base: 54, with all 70 validations running tests. +- pydantic: 0 of 360 candidates. +- Grouping candidates by dependency files saves little. hugo's 55 bases have 26 distinct `go.mod`/`go.sum` pairs. + pydantic's 113 bases have 43 distinct manifest sets and 54 distinct `pydantic-core/src` trees. +- uv does not rebuild `pydantic-core` when only its Rust sources change. Of 112 consecutive pydantic base pairs, 31 + change `pydantic-core/src` with identical manifests and lockfiles. On one such pair, `uv sync --frozen` after the + checkout reported `Checked 42 packages in 2ms` and kept the old extension; it rejected the new base's + `named-tuple` schema. This matches uv's documented [cache keys](https://docs.astral.sh/uv/concepts/cache/). + +## Design (proposed) + +Opt-in: `--pipeline-opt environment=candidate`. The default stays `head` until the rollout below. + +1. **Bootstrap recipe.** Bootstrap saves three command lists: `system_cmds` (OS packages and toolchain installs), + `install_cmds` (locked dependency install) and `rebuild_cmds` (build of in-repo packages). A recipe is accepted + only if it replays from the clean base image in a fresh container and reports at least one test. +2. **Toolchain image.** `FROM` the base image pinned by digest, plus `system_cmds`. It never contains source, + project dependencies or build output. Key: base image digest, platform, hash of `system_cmds`, toolchain + version. Go: a base is compatible if its `go` line is at most the image's toolchain; otherwise a matching + toolchain image is built where an installer exists, else the candidate is dropped as `toolchain_unsupported`. +3. **Candidate image**, `FROM` the toolchain image: + - *Dependency layer:* copy only the base's dependency files (for uv, the lockfile plus every workspace + member's `pyproject.toml`) and run `install_cmds` with network. Locked resolution only: + `uv sync --frozen --no-install-workspace`, `go mod download` (at `go 1.17`+, `go.mod` lists modules imported + only by tests too), `cargo fetch --locked`, `npm ci`. A repository with no lockfile is resolved into the empty + environment with `uv pip install --exclude-newer `; nothing is preinstalled, so uv's + installed-package limitation does not apply. + - *Source layer:* copy the source at the base, install in-repo packages and run `rebuild_cmds`, always forcing a + rebuild of local packages (`--reinstall-package` for each workspace member). Correctness never depends on + uv's local-directory cache. + - *Build caches* (uv cache, Cargo `target/`, Go build cache) are BuildKit cache mounts, never layers of the + shipped image. Their id is the toolchain image digest, platform and recipe hash. They only make builds faster. + This needs candidate images built by Repo2RLEnv and pushed by digest (`registry` mode); an `inline` task built + by the provider rebuilds without the mounts, which is slower but gives the same result. +4. **Pinning.** With a lockfile, uv and Cargo already record a full commit for a Git dependency requested by + branch, and uv records a hash for a URL dependency, so the remaining check is that path dependencies resolve + inside the repository. Without a lockfile, uv's date cutoff does not cover Git dependencies, so a Git + requirement must name a full commit. Otherwise the candidate is dropped as `env_unpinned_dependency`. +5. **Offline contents.** Kept, because the verifier builds offline: the installed environment; the build backends + of every in-repo package, installed into that environment from each member's `build-system.requires` plus what + the backend requests for an editable build (pydantic: `maturin`, `hatchling`, `hatch-fancy-pypi-readme`, + `editables`), so rebuilds use `--no-build-isolation`; Go's module cache for `go.mod`; Cargo's registry index, + crate archives and sources for `Cargo.lock`; `node_modules`. Removed: pip and uv HTTP and wheel caches, npm's `_cacache`, everything under cache + mounts. Then offline settings (`GOPROXY=off`, `GOSUMDB=off`, `GOTOOLCHAIN=local`, `PIP_NO_INDEX=1`, + `UV_OFFLINE=1`, `CARGO_NET_OFFLINE=true`, npm offline), the history scrub and the #278 check. The task ships + `FROM` this image's digest. +6. **Verifier rebuild.** When the agent's diff touches an in-repo native package, the verifier runs `rebuild_cmds` + after rebuilding `/workspace` and before the tests: offline, without build isolation, as the unprivileged test + user through the grader launcher (the build backend runs code from the submission, so never as root). Build output + such as `target/` is not shipped (step 3), so this is a cold build (pydantic-core: 67 s). +7. **Gold patches that need new dependencies.** The gold control runs offline in the candidate image. If it can't + resolve or build because the gold patch needs a dependency version the base doesn't have, the candidate is + dropped as `env_gold_needs_dependency`; nothing from the gold's dependency set enters the shipped image. A gold + patch that only removes dependencies still passes. Of the 54 hugo pilot tasks, 3 edit `go.mod`/`go.sum` and 2 + of them fail offline. +8. **Network.** Validation stages run with `--network none` in fresh containers (#279). If the sandbox backend + cannot apply it, the candidate is `inconclusive` (`network_unenforced`) and not emitted. The shipped task sets + `[verifier.environment] network_mode = "no-network"` with a separate verifier. Harbor creates the separate + verifier environment after the agent phase, so on a backend that can't enforce it (`hf-sandbox` today) the trial + ends with an exception and no reward, after the agent has run. The dataset card states the required capability; + checking it at trial start would be a Harbor change. The agent side keeps #257. +9. **Gate.** Gold passes F2P and P2P, base fails F2P, P2P passes at base. Test counts are diagnostics only. +10. **Environment failures.** `env_install_failed` and `env_gold_unrunnable` escalate to one re-bootstrap at that + base, deduplicated by (dependency fingerprint, failure signature). + +## Verification + +Reward, verifier grading, config guard and mutants are unchanged apart from step 6. The gold patch scores 1.0 in the +shipped image with the verifier's network policy. + +## Anti-contamination + +Locked or date-capped dependencies, commit-pinned Git dependencies, an image built without later source, and step 7 +keep the fix out of the environment. Agent network unchanged (#257). + +## LLM use + +Bootstrap, plus re-bootstraps from step 10. A run-wide cap, `max_run_llm_spend_usd`, uses the campaign +`BudgetLedger`: each bootstrap reserves its `max_llm_spend_usd` against the run before starting and settles with its +actual cost, so retries cannot exceed the cap. Today an unpriced model reports `cost_usd = 0` (`llm.py`), and the +bootstrap loop's dollar check never fires. With a run cap set, the run therefore refuses an unpriced model unless a +price per million tokens is configured for it. + +## Yield & repo suitability + +Expected to stop yield falling with PR age on repositories with lockfiles. Repositories with unpinned Git +dependencies or no installer for their toolchain get typed drops instead of silent zero-test validations. + +## Alternatives considered + +- **Epochs by fingerprint:** about one image per two candidates on active repositories; kept only as the dependency + layer's cache key. +- **Time windows:** hugo reached 19 tasks, not 54. +- **Prefetching the gold's dependency set into the image:** keeps the step 7 candidates but shows the agent which + versions the fix needs. Left as an open question. +- **Install at solve time:** needs network, and validation would differ from the shipped image. + +## Rollout plan + +1. Replay check on six bootstrapped repositories. Stop if recipes don't replay. +2. Compare with `head` on hugo, networkx, pydantic and fiber, on x86: yield by PR age, build time, storage. +3. Oracle and no-op runs on every task. Then make `candidate` the default. + +## Open questions + +- Can the bootstrap agent reliably separate `system_cmds`, `install_cmds` and one-off setup? +- How should differing Python or Node versions be installed? +- Is dropping step 7 candidates acceptable, or is prefetching worth the exposure? + +## Measurements + +Contributor runs, arm64 unless noted. Pilot repository: [rycerzes/swe-rl-pilot](https://github.com/rycerzes/swe-rl-pilot). + +| Claim | Repo2RLEnv | Inputs | Command / run | +|---|---|---|---| +| hugo 2 / 185 | `db619e1` | 4 monthly windows 2026-07-15..11-11, limit 200 | run 42908332459 (pilot `4055ae3`) | +| hugo 19 | `db619e1` | bootstrap re-anchored per two-week window | run 42913575209 (`af808d5`) | +| hugo 54 | `db619e1` | as above + `go mod download` per base | run 42922942604 (`3f5de55`) | +| pydantic 0 / 360 | `db619e1` | 4 monthly windows, limit 200 | run 42908340421 (`4055ae3`) | +| Fingerprints | — | distinct `git reset --hard` SHAs in the stage scripts of 42908332459 and 42908340421 | `git rev-parse :` over `go.mod go.sum` (hugo) and `pyproject.toml uv.lock pydantic-core/{pyproject.toml,Cargo.toml,Cargo.lock} .python-version` (pydantic) | +| Gold changes dependencies | — | merged PRs whose base is one of those SHAs | PR files API; lockfile package names at merge base vs head | +| Gold needs dependency offline | — | hugo pilot tasks 15156, 15432, 15503, `golang:1.27` | `go mod download` at base, then `GOPROXY=off go list -deps -test ./...` at base (all pass) and with `solution/patch.diff` (15156, 15432 fail) | +| uv rebuild miss, build time | — | pydantic `98a08d3e` → `53b39c38` (#13505), uv 0.13.4, `rust:1-bookworm` | `uv sync --frozen --all-packages` at A (27 s cold), checkout B, sync again, then `--reinstall-package pydantic-core` (9 s) | +| Offline verifier rebuild | — | same pair; uv cache and `target/` removed; non-root user, `UV_OFFLINE=1`, `CARGO_NET_OFFLINE=true` | with build isolation: fails (`maturin was not found in the cache`); backends preinstalled + `--no-build-isolation`: rebuilt in 67 s, B's schema validates | +| Two-step candidate layers | — | same pair | dependency files only + `uv sync --frozen --no-install-workspace`: 2 s, identical installed set at A and B; then source + `--reinstall-package pydantic-core`: 35 s / 28 s, B's schema validates | +| Date cap without a lockfile | — | networkx `db84a87d` (2026-08-06), `requirements/{default,test}.txt` | `uv pip install --exclude-newer` into an empty venv: 21 packages, versions differ from uncapped, none first uploaded after the cutoff (PyPI JSON) | +| Lockfile pinning | — | toy projects, uv 0.13.4, cargo | branch Git deps recorded as `?rev=main#` (uv) and `?branch=master#` (Cargo); URL wheel has a hash; a detector flags only the path dependency outside the project | +| Cargo and npm offline | — | hexyl `6ecc29b9`, uuid `766d0d29` | image after `cargo fetch --locked` / `npm ci` (no `target/`, no `_cacache`), run with `--network none` as a non-root user: `cargo test --locked` passes, `npm run build && npm test` 84/84; controls without the registry / with a new package fail | +| Cache mounts | — | same pair, podman build (buildah) | `RUN --mount=type=cache` for uv cache and `target/`: 84 s at A, 17 s at B; `target/` absent from both images | + +## References + +#253, #257, #278, #279, #281. RepoLaunch (2603.05026), SWE-Next (2603.20691), SWE-rebench V2 (2602.23866). + +## Implementation + +*Placeholder while `draft`.* diff --git a/docs/rfcs/index.md b/docs/rfcs/index.md index 6949c870..d2d2fb76 100644 --- a/docs/rfcs/index.md +++ b/docs/rfcs/index.md @@ -81,6 +81,7 @@ Sequential. `0001-.md`, `0002-.md`, …. Never reuse a number. If an | 0032 | `optimization_synth` / `frontiersmith` | implemented in 0.9.3; experimental | [0032-frontiersmith-recipe.md](0032-frontiersmith-recipe.md) | Local campaign; dataset unpublished | | 0033 | Evidence-based quality review | implemented; experimental, opt-in | [0033-evidence-based-quality-review.md](0033-evidence-based-quality-review.md) | Bounded pilot; see RFC measurements | | 0034 | `trajectory_to_env` | experimental implementation | [0034-trajectory-to-env.md](0034-trajectory-to-env.md) | Local smoke run; dataset unpublished | +| 0035 | `pr_runtime` per-candidate environments | draft | [0035-pr-runtime-per-candidate-environments.md](0035-pr-runtime-per-candidate-environments.md) | n/a |