From fbfcd18b9f2e9c660225dd7f3f3775fa30549f45 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 24 Nov 2026 14:10:07 -0600 Subject: [PATCH] PYTHON-6295 Capture the BSON fuzz corpus weekly instead of nightly --- .evergreen/generated_configs/tasks.yml | 10 ++++++- .evergreen/generated_configs/variants.yml | 7 +++++ .evergreen/scripts/capture-fuzz-corpus.sh | 5 ++-- .evergreen/scripts/generate_config.py | 31 ++++++++++++++++------ .evergreen/scripts/setup_tests.py | 7 ++--- .evergreen/scripts/test_generate_config.py | 29 +++++++++++++------- CONTRIBUTING.md | 11 ++++---- fuzz/README.md | 22 ++++++++------- fuzz/capture_corpus.py | 2 +- 9 files changed, 85 insertions(+), 39 deletions(-) diff --git a/.evergreen/generated_configs/tasks.yml b/.evergreen/generated_configs/tasks.yml index 738609fc0e..00ac5416da 100644 --- a/.evergreen/generated_configs/tasks.yml +++ b/.evergreen/generated_configs/tasks.yml @@ -215,6 +215,14 @@ tasks: UV_PYTHON: "3.13" tags: [fuzz, fuzz-regression, pr] - name: fuzz + commands: + - func: run tests + vars: + TEST_NAME: fuzz + SUB_TEST_NAME: fuzz + UV_PYTHON: "3.13" + tags: [fuzz, fuzz-nightly] + - name: fuzz-capture commands: - func: run tests vars: @@ -234,7 +242,7 @@ tasks: - AWS_SECRET_ACCESS_KEY - AWS_SESSION_TOKEN type: test - tags: [fuzz, fuzz-nightly] + tags: [fuzz, fuzz-weekly] # Getdata tests - name: getdata diff --git a/.evergreen/generated_configs/variants.yml b/.evergreen/generated_configs/variants.yml index 5e1094ac9e..f624b89e6e 100644 --- a/.evergreen/generated_configs/variants.yml +++ b/.evergreen/generated_configs/variants.yml @@ -215,6 +215,13 @@ buildvariants: run_on: - rhel8.10-small batchtime: 1440 + - name: fuzz-capture-rhel8 + tasks: + - name: .fuzz-weekly + display_name: Fuzz Capture RHEL8 + run_on: + - rhel8.10-small + batchtime: 10080 # Green framework tests - name: green-gevent-rhel8 diff --git a/.evergreen/scripts/capture-fuzz-corpus.sh b/.evergreen/scripts/capture-fuzz-corpus.sh index 1b3512e4b0..ad829e0c48 100755 --- a/.evergreen/scripts/capture-fuzz-corpus.sh +++ b/.evergreen/scripts/capture-fuzz-corpus.sh @@ -1,8 +1,9 @@ #!/bin/bash # PYTHON-6178: capture coverage-increasing inputs from a fuzz run and open # an automated PR growing fuzz/corpus/. Runs as the last command of the -# nightly "fuzz" task, while the scratch corpus exists; manual -# `evergreen patch --variant fuzz-rhel8 --task fuzz` runs capture too. +# weekly "fuzz-capture" task, while the scratch corpus exists; manual +# `evergreen patch --variant fuzz-capture-rhel8 --task fuzz-capture` runs +# capture too. set -eu # Same environment as just.sh: venv on PATH for a modern Python. diff --git a/.evergreen/scripts/generate_config.py b/.evergreen/scripts/generate_config.py index afbe9ae55a..061f9bc0a6 100644 --- a/.evergreen/scripts/generate_config.py +++ b/.evergreen/scripts/generate_config.py @@ -389,12 +389,13 @@ def create_doctests_variants(): def create_fuzz_variants(): - # Two variants for the two fuzz flows: the regression reproducers run - # on every PR, the time-boxed fuzzing runs nightly. The nightly variant - # carries no "pr" tag, so PR patch builds never select it, while its - # default patchability keeps it manually runnable - # (`evergreen patch --variant fuzz-rhel8 --task fuzz`). The host needs - # CPython, which the rhel8 toolchain provides. + # Three variants for the three fuzz flows: the regression reproducers run + # on every PR, the time-boxed fuzzing for crash discovery runs nightly, + # and the weekly variant also captures the corpus (opens the automated + # [Fuzz Corpus] PR). The non-pr variants carry no "pr" tag, so PR patch + # builds never select them, while their default patchability keeps them + # manually runnable (`evergreen patch --variant fuzz-rhel8 --task fuzz`). + # The host needs CPython, which the rhel8 toolchain provides. host = HOSTS["rhel8"] return [ create_variant( @@ -403,6 +404,12 @@ def create_fuzz_variants(): create_variant( [".fuzz-nightly"], get_variant_name("Fuzz", host), host=host, batchtime=BATCHTIME_DAY ), + create_variant( + [".fuzz-weekly"], + get_variant_name("Fuzz Capture", host), + host=host, + batchtime=BATCHTIME_WEEK, + ), ] @@ -722,10 +729,18 @@ def create_fuzz_tasks(): test_func = FunctionCall(func="run tests", vars=test_vars) tasks = [EvgTask(name="fuzz-regression", tags=tags, commands=[test_func])] - # Time-boxed fuzzing against the generated seed corpus. + # Time-boxed fuzzing against the generated seed corpus, for crash + # discovery; corpus capture moved to the weekly fuzz-capture task. tags = ["fuzz", "fuzz-nightly"] test_vars = dict(TEST_NAME="fuzz", SUB_TEST_NAME="fuzz", UV_PYTHON="3.13") test_func = FunctionCall(func="run tests", vars=test_vars) + tasks.append(EvgTask(name="fuzz", tags=tags, commands=[test_func])) + + # The weekly capture task fuzzes too (the capture reads the task-local + # fuzz-scratch/ corpus, so it must stay attached to a fuzzing run). + tags = ["fuzz", "fuzz-weekly"] + test_vars = dict(TEST_NAME="fuzz", SUB_TEST_NAME="fuzz", UV_PYTHON="3.13") + test_func = FunctionCall(func="run tests", vars=test_vars) # PYTHON-6178: while the scratch corpus still exists, capture the new # coverage-increasing inputs, replay them through every target so a # unit that fails one is never published, and open an automated PR @@ -743,7 +758,7 @@ def create_fuzz_tasks(): "AWS_SESSION_TOKEN", ], ) - tasks.append(EvgTask(name="fuzz", tags=tags, commands=[test_func, capture_cmd])) + tasks.append(EvgTask(name="fuzz-capture", tags=tags, commands=[test_func, capture_cmd])) return tasks diff --git a/.evergreen/scripts/setup_tests.py b/.evergreen/scripts/setup_tests.py index fecb6c9efc..cb0fb59c1e 100644 --- a/.evergreen/scripts/setup_tests.py +++ b/.evergreen/scripts/setup_tests.py @@ -600,9 +600,10 @@ def handle_test_env() -> None: zip_path.unlink() if sub_test_name == "fuzz": # PYTHON-6178 Also seed from the committed corpus of previously - # captured inputs, so the nightly builds on prior discoveries - # instead of the spec seeds alone. Regression runs (PRs) keep - # running only the reproducers and the spec seed corpus. + # captured inputs, so the nightly and weekly runs build on prior + # discoveries instead of the spec seeds alone. Regression runs + # (PRs) keep running only the reproducers and the spec seed + # corpus. committed_dir = ROOT / "fuzz" / "corpus" if committed_dir.is_dir(): for path in sorted(committed_dir.iterdir()): diff --git a/.evergreen/scripts/test_generate_config.py b/.evergreen/scripts/test_generate_config.py index 8e431f1a3f..602e84e3e5 100644 --- a/.evergreen/scripts/test_generate_config.py +++ b/.evergreen/scripts/test_generate_config.py @@ -443,32 +443,43 @@ def test_non_standard_cov_tasks_have_no_cov_companions(): def test_fuzz_task_wiring(): """Test the fuzz task wiring. - Two fuzz variants: the pr-tagged regression variant runs the reproducers on - every PR; the nightly variant (which also captures the corpus) carries no - "pr" tag, so PR patch builds never select it, while its default patchability - keeps it manually runnable (`evergreen patch --variant fuzz-rhel8 --task fuzz`). + Three fuzz flows: the pr-tagged regression variant runs the reproducers + on every PR; the nightly variant fuzzes for crash discovery; the weekly + variant also captures the corpus. The non-pr variants carry no "pr" tag, + so PR patch builds never select them, while their default patchability + keeps them manually runnable + (`evergreen patch --variant fuzz-rhel8 --task fuzz`). """ tasks = [task for task in all_tasks() if "fuzz" in (task.tags or [])] assert [task.name for task in tasks if "pr" in (task.tags or [])] == ["fuzz-regression"] - assert [task.name for task in tasks if "pr" not in (task.tags or [])] == ["fuzz"] + assert [task.name for task in tasks if "pr" not in (task.tags or [])] == [ + "fuzz", + "fuzz-capture", + ] variants = generate_config.create_fuzz_variants() - assert len(variants) == 2 - regression, nightly = variants + assert len(variants) == 3 + regression, nightly, capture_variant = variants assert variant_selects(regression, tasks[0]) assert "pr" in (regression.tags or []) assert variant_selects(nightly, tasks[1]) assert nightly.batchtime == generate_config_utils.BATCHTIME_DAY + assert variant_selects(capture_variant, tasks[2]) + assert capture_variant.batchtime == generate_config_utils.BATCHTIME_WEEK # Webhook PR patch builds only select pr-tagged variants. assert not nightly.tags + assert not capture_variant.tags + # The nightly fuzz task is crash discovery only: its last command is + # the "run tests" FunctionCall, with no capture command. + assert tasks[1].commands[-1].func == "run tests" # The capture subprocess bootstraps the comment-bot github app, whose # secrets live in AWS Secrets Manager: it needs the assumed-role # credentials (as resync_specs and backport-pr also pass them). - capture = tasks[1].commands[-1] + capture = tasks[2].commands[-1] env_vars = capture.params["include_expansions_in_env"] for var in ("AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"): assert var in env_vars, f"capture subprocess missing {var}" # The capture no longer keys off is_patch: manual patch runs must - # capture too, and the nightly variant never runs in a PR build. + # capture too, and the weekly variant never runs in a PR build. assert "is_patch" not in env_vars diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 43790a3299..d16f95e5db 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -452,13 +452,14 @@ wheels (CPython 3.12-3.14). - Regression test (runs on every PR): `just setup-tests fuzz regression` then `just run-tests`. -- Time-boxed fuzzing (runs daily on Evergreen): `just setup-tests fuzz fuzz` - then `just run-tests`. Set `FUZZ_MAX_TIME` (seconds, default 300) to change - the per-target budget. -- Nightly fuzzing captures coverage-increasing inputs into `fuzz/corpus/` +- Time-boxed fuzzing for crash discovery (runs daily on Evergreen): + `just setup-tests fuzz fuzz` then `just run-tests`. Set `FUZZ_MAX_TIME` + (seconds, default 300) to change the per-target budget. +- Weekly capture (runs weekly on Evergreen): the `fuzz-capture` task also + fuzzes, then captures coverage-increasing inputs into `fuzz/corpus/` via an automated PR (PYTHON-6178); see [fuzz/README.md](fuzz/README.md). To run that flow on demand, patch the task: - `evergreen patch --variant fuzz-rhel8 --task fuzz`. + `evergreen patch --variant fuzz-capture-rhel8 --task fuzz-capture`. ## Testing time-dependent operations diff --git a/fuzz/README.md b/fuzz/README.md index 464601ac06..979f4a7065 100644 --- a/fuzz/README.md +++ b/fuzz/README.md @@ -77,7 +77,9 @@ default mutation cap of 4096 bytes would keep the nightly away from long-string and many-field code paths. Run the targets against the corpus. Time-boxed runs suit CI; this runs on -Evergreen as the `fuzz` sub-test, daily: +Evergreen as the `fuzz` sub-test, daily. The nightly `fuzz` task is crash +discovery only; the weekly `fuzz-capture` task fuzzes and captures the +corpus (below): ```bash just setup-tests fuzz fuzz @@ -95,15 +97,15 @@ after the corpus directory. The `Failed to find function __sanitizer_*` startup warnings are benign libFuzzer symbol probes on uninstrumented runs; native ASan-instrumented fuzzing is tracked separately (PYTHON-6169). -### Captured corpus (nightly) +### Captured corpus (weekly) -The nightly run seeds from the spec seed corpus plus every unit in +The weekly capture run seeds from the spec seed corpus plus every unit in `corpus/`, and libFuzzer writes each coverage-increasing ("interesting") input it discovers back into its corpus directory. After the targets -finish, the `fuzz` task captures those new units, replays them through -every target once so a unit that fails any target is never published (it -stays in `fuzz-scratch/` for triage), and opens an automated -"[Fuzz Corpus]" PR against main (PYTHON-6178). Later nights +finish, the `fuzz-capture` task captures those new units, replays them +through every target once so a unit that fails any target is never +published (it stays in `fuzz-scratch/` for triage), and opens an automated +"[Fuzz Corpus]" PR against main (PYTHON-6178). Later weeks build on prior discoveries instead of restarting from the spec seeds. Growth is bounded by per-unit and per-run caps, overridable on Evergreen: @@ -115,7 +117,7 @@ Growth is bounded by per-unit and per-run caps, overridable on Evergreen: Units over a cap are discarded, not deferred: they are never persisted, so the fuzzer may re-derive them on later nights. A run that finds nothing new opens no PR. The capture deduplicates against `main` only, so while a -`[Fuzz Corpus]` PR is open, later nights can re-capture its still-pending +`[Fuzz Corpus]` PR is open, later weeks can re-capture its still-pending units and the PRs overlap until one merges (digest-named files keep that conflict-free). Crashing inputs are excluded: they land in `fuzz-scratch/` as `crash-*` artifacts and follow the @@ -141,11 +143,11 @@ gives atheris a graceful exit so coverage.py can flush its report. ``` build_corpus.py Seed corpus builder (mirrors the Go driver's build-oss-fuzz-corpus) -capture_corpus.py Nightly capture of new coverage-increasing inputs (PYTHON-6178) +capture_corpus.py Weekly capture of new coverage-increasing inputs (PYTHON-6178) fuzz_decode.py Fuzz target: bson.decode() fuzz_decode_all.py Fuzz target: bson.decode_all() fuzz_is_valid.py Fuzz target: bson.is_valid() fuzz_shared.py Code shared by the fuzz targets -corpus/ Captured coverage-increasing inputs; grown by automated nightly PRs +corpus/ Captured coverage-increasing inputs; grown by automated weekly PRs regression/ Known bug reproducers; run with the seed corpus on PRs ``` diff --git a/fuzz/capture_corpus.py b/fuzz/capture_corpus.py index 94ad5945a4..7268b75e88 100755 --- a/fuzz/capture_corpus.py +++ b/fuzz/capture_corpus.py @@ -8,7 +8,7 @@ units into an output directory named by their SHA-256 digests, and writes a Markdown summary for the automated corpus PR body. -Pure stdlib: this runs on the Evergreen nightly host after the fuzz +Pure stdlib: this runs on the Evergreen weekly capture host after the fuzz targets finish, and its unit tests must run everywhere (no atheris, no bson).