feat: deterministic traversal benchmark & closed-loop optimization harness #1302

Open
github-bot wants to merge 2 commits from github-bot/gh-1302 into main AGit
Owner

@⁠Vladimir-Human on GitHub · 2026-11-26 13:17 UTC · original
Vladimir-Human:feat/deterministic-bench-loop → main · +5571 −19 · 11 files · 2 commits · open

Summary

Adds an opt-in, zero-default-overhead Deterministic Traversal Benchmark & Closed-Loop Optimization Harness (victory-gpu::bench, victory-hle::modules::gameinput_script, cargo xtask bench-loop, and docs/auto-bench.md) with zero new crate dependencies (Cargo.toml, Cargo.lock, and xtask/src/policy.rs untouched).

Components

  1. GPU Benchmark Telemetry (crates/victory-gpu/src/bench.rs, hooks in lib.rs, framelog.rs, queue.rs, 1 line in host.rs::fail):
    • pub fn world_frame() -> u64: monotonic counter staying 0 through menus/loading screens and latching to 1, 2, ... at the first presented frame with >= 500 draws (atomic-only fast path when bench env vars are unset).
    • Opt-in env vars: VICTORY_BENCH_OUT=<abs_path.json> (enforces outside-repo .victory-root check and writes atomically via .tmp.<pid>.<seq> + rename), VICTORY_BENCH_WARMUP=<W> (default 30), VICTORY_BENCH_EXIT_FRAMES=<N> (flush JSON + std::process::exit(0)), and VICTORY_BENCH_CHECK_EVERY=<K>.
    • Emits pure-std JSON covering world_frames, warmup_frames, frame_ms (avg, median, p95, p99, low_5pct_fps, low_1pct_fps), draws (avg, min, max), device_removed, zero_draw_world_frames, black_frames, memory (DXGI VRAM peak/budget + Win32 private commit & working set peaks), framelog per-frame averages (prepare_ms, card_wait_ms, card_idle_ms, copy_ms, copyback_ms, remap_ms, refresh_ms, pipeline_wait_ms, guard_faults, card_sync_ms, card_check_ms, card_lists_ms), and input_script_sha256 (blake3).
  2. Deterministic Input Recording & Replay (crates/victory-hle/src/modules/gameinput_script.rs, tiny hook in gameinput.rs):
    • VICTORY_INPUT_RECORD=<abs_path.jsonl>: validates outside-repo destination, records full PadState + held keys on every state change tagged with wframe and ms, flushed per transition and on Drop.
    • VICTORY_INPUT_REPLAY=<abs_path.jsonl>: replays recorded JSONL traces and/or declarative range lines ({"from":0,"to":120,"ly":1.0,"rt":0.8}) keyed to world_frame(), immune to FPS changes, waiting in neutral state through loading screens (world_frame == 0), latching wframe across pad(0)/keys() in each poll cycle, and registering the script digest into victory_gpu::bench.
  3. Interleaved A/B & Closed-Loop Harness (xtask/src/bench_loop.rs, Cmd::BenchLoop in xtask/src/main.rs):
    • Pure std + existing anyhow/clap (zero new dependencies): TOML/KV playlist parser ([[scenes]]), JSON parser, and 8-bit RGB/RGBA PNG decoder (RFC 1950/1951 inflate + row unfilter) for optional checkpoint PNG luma/black-frame parity.
    • --mode ab (interleaved base -> cand -> base or N-round median) and --mode loop (pluggable --agent-cmd with timeout watchdog, optional --fast-cmd offline pre-filter, clean-tree guard, commit-on-keep / git reset --hard + new-untracked cleanup on revert, and experiments.jsonl dead-end history).
    • Enforces all 6 hard anti-reward-hacking gates: (1) build/test/policy/clippy, (2) exit 0 + timeout watchdog + valid JSON + device_removed == false, (3) draws.avg within ±15% of baseline, (4) zero_draw_world_frames == 0, black_frames == 0, optional checkpoint PNG parity, (5) warmup exclusion + input_script_sha256 parity + interleaved medians, (6) median frame_ms gain >= --min-gain-pct + 1% low, VRAM, and RAM non-regression/caps.
  4. Documentation (docs/auto-bench.md): concise setup and usage guide for recording scripts, playlist configs, --mode ab, --mode loop, JSON schema, and gates.

Verification

  • cargo run --locked -p xtask -- policy: asset policy: 224 files ok
  • cargo test --locked -p xtask: 17 passed; 0 failed (covers keep-on-win, draw-skip rejection, device-removed rejection, black-frame + PNG parity rejection, VRAM breach, noise-below-threshold, input_script_sha256 mismatch, Gate 1 failure JSON safety, real git keep/revert across iterations, agent failure handling, and watchdog timeout)
  • cargo test --locked -p victory-gpu -p victory-hle -- --test-threads=1: victory-gpu 216 passed; 0 failed; 6 ignored, victory-hle 106 passed; 0 failed, no_dll_planting 1 passed
  • cargo test --locked --features diagnostics -p victory-gpu -p victory-hle -- --test-threads=1: victory-gpu 235 passed; 0 failed; 7 ignored, victory-hle 106 passed; 0 failed, no_dll_planting 1 passed
  • cargo clippy --workspace --all-targets --locked -- -D warnings -A deprecated (default & --all-features): 0 warnings
  • git diff --check: clean; Cargo.toml, Cargo.lock, and xtask/src/policy.rs untouched; all files < 512 KiB
**@⁠Vladimir-Human** on GitHub · 2026-11-26 13:17 UTC · [original](https://github.com/fxceless/victory-fork/pull/1302) `Vladimir-Human:feat/deterministic-bench-loop` → `main` · +5571 −19 · 11 files · 2 commits · open ## Summary Adds an opt-in, zero-default-overhead **Deterministic Traversal Benchmark & Closed-Loop Optimization Harness** (`victory-gpu::bench`, `victory-hle::modules::gameinput_script`, `cargo xtask bench-loop`, and `docs/auto-bench.md`) with zero new crate dependencies (`Cargo.toml`, `Cargo.lock`, and `xtask/src/policy.rs` untouched). ### Components 1. **GPU Benchmark Telemetry (`crates/victory-gpu/src/bench.rs`, hooks in `lib.rs`, `framelog.rs`, `queue.rs`, 1 line in `host.rs::fail`):** - `pub fn world_frame() -> u64`: monotonic counter staying `0` through menus/loading screens and latching to `1, 2, ...` at the first presented frame with `>= 500` draws (atomic-only fast path when bench env vars are unset). - Opt-in env vars: `VICTORY_BENCH_OUT=<abs_path.json>` (enforces outside-repo `.victory-root` check and writes atomically via `.tmp.<pid>.<seq>` + rename), `VICTORY_BENCH_WARMUP=<W>` (default `30`), `VICTORY_BENCH_EXIT_FRAMES=<N>` (flush JSON + `std::process::exit(0)`), and `VICTORY_BENCH_CHECK_EVERY=<K>`. - Emits pure-std JSON covering `world_frames`, `warmup_frames`, `frame_ms` (`avg`, `median`, `p95`, `p99`, `low_5pct_fps`, `low_1pct_fps`), `draws` (`avg`, `min`, `max`), `device_removed`, `zero_draw_world_frames`, `black_frames`, `memory` (DXGI VRAM peak/budget + Win32 private commit & working set peaks), `framelog` per-frame averages (`prepare_ms`, `card_wait_ms`, `card_idle_ms`, `copy_ms`, `copyback_ms`, `remap_ms`, `refresh_ms`, `pipeline_wait_ms`, `guard_faults`, `card_sync_ms`, `card_check_ms`, `card_lists_ms`), and `input_script_sha256` (`blake3`). 2. **Deterministic Input Recording & Replay (`crates/victory-hle/src/modules/gameinput_script.rs`, tiny hook in `gameinput.rs`):** - `VICTORY_INPUT_RECORD=<abs_path.jsonl>`: validates outside-repo destination, records full `PadState` + held keys on every state change tagged with `wframe` and `ms`, flushed per transition and on `Drop`. - `VICTORY_INPUT_REPLAY=<abs_path.jsonl>`: replays recorded JSONL traces and/or declarative range lines (`{"from":0,"to":120,"ly":1.0,"rt":0.8}`) keyed to `world_frame()`, immune to FPS changes, waiting in neutral state through loading screens (`world_frame == 0`), latching `wframe` across `pad(0)`/`keys()` in each poll cycle, and registering the script digest into `victory_gpu::bench`. 3. **Interleaved A/B & Closed-Loop Harness (`xtask/src/bench_loop.rs`, `Cmd::BenchLoop` in `xtask/src/main.rs`):** - Pure `std` + existing `anyhow`/`clap` (zero new dependencies): TOML/KV playlist parser (`[[scenes]]`), JSON parser, and 8-bit RGB/RGBA PNG decoder (RFC 1950/1951 inflate + row unfilter) for optional checkpoint PNG luma/black-frame parity. - `--mode ab` (interleaved `base -> cand -> base` or N-round median) and `--mode loop` (pluggable `--agent-cmd` with timeout watchdog, optional `--fast-cmd` offline pre-filter, clean-tree guard, commit-on-keep / `git reset --hard` + new-untracked cleanup on revert, and `experiments.jsonl` dead-end history). - Enforces all 6 hard anti-reward-hacking gates: (1) build/test/policy/clippy, (2) exit 0 + timeout watchdog + valid JSON + `device_removed == false`, (3) `draws.avg` within ±15% of baseline, (4) `zero_draw_world_frames == 0`, `black_frames == 0`, optional checkpoint PNG parity, (5) warmup exclusion + `input_script_sha256` parity + interleaved medians, (6) `median frame_ms` gain `>= --min-gain-pct` + `1% low`, VRAM, and RAM non-regression/caps. 4. **Documentation (`docs/auto-bench.md`):** concise setup and usage guide for recording scripts, playlist configs, `--mode ab`, `--mode loop`, JSON schema, and gates. ## Verification - `cargo run --locked -p xtask -- policy`: `asset policy: 224 files ok` - `cargo test --locked -p xtask`: `17 passed; 0 failed` (covers keep-on-win, draw-skip rejection, device-removed rejection, black-frame + PNG parity rejection, VRAM breach, noise-below-threshold, `input_script_sha256` mismatch, Gate 1 failure JSON safety, real git keep/revert across iterations, agent failure handling, and watchdog timeout) - `cargo test --locked -p victory-gpu -p victory-hle -- --test-threads=1`: `victory-gpu` `216 passed; 0 failed; 6 ignored`, `victory-hle` `106 passed; 0 failed`, `no_dll_planting` `1 passed` - `cargo test --locked --features diagnostics -p victory-gpu -p victory-hle -- --test-threads=1`: `victory-gpu` `235 passed; 0 failed; 7 ignored`, `victory-hle` `106 passed; 0 failed`, `no_dll_planting` `1 passed` - `cargo clippy --workspace --all-targets --locked -- -D warnings -A deprecated` (default & `--all-features`): 0 warnings - `git diff --check`: clean; `Cargo.toml`, `Cargo.lock`, and `xtask/src/policy.rs` untouched; all files `< 512 KiB`
- Add opt-in GPU benchmark telemetry (`crates/victory-gpu/src/bench.rs`) with
  monotonic `world_frame()` latching at >= 500 draws, `VICTORY_BENCH_OUT`,
  `VICTORY_BENCH_WARMUP`, `VICTORY_BENCH_EXIT_FRAMES`, and
  `VICTORY_BENCH_CHECK_EVERY`, outside-repo path validation, atomic
  `.tmp.<pid>.<seq>` JSON output (frame-time percentiles, 5%/1% low FPS,
  draw counts, device-removed/zero-draw/black-frame counters, DXGI VRAM and
  Win32 RAM peaks, `framelog` per-frame averages, and input-script digest).
- Add world-frame-keyed input recording and replay
  (`crates/victory-hle/src/modules/gameinput_script.rs`) via
  `VICTORY_INPUT_RECORD` and `VICTORY_INPUT_REPLAY`, supporting recorded JSONL
  traces and declarative range scripts, neutral wait through loading screens
  (`world_frame == 0`), and FPS-independent playback.
- Add pure-std `cargo xtask bench-loop` (`xtask/src/bench_loop.rs`) with
  interleaved A/B (`--mode ab`), autonomous optimization (`--mode loop` with
  pluggable `--agent-cmd`, optional `--fast-cmd`, git rollback/commit safety,
  and `experiments.jsonl` history), pure-std TOML/JSON/PNG decoders, and
  6 anti-reward-hacking gates.
- Add neutral usage guide in `docs/auto-bench.md`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:19:40 +00:00
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-26 13:49 UTC · original

Updated in a451e37:

  • Gate 5 symmetric short-repeat hardening (mirroring @⁠HandshakeHackin's catch on PastiiJay/klbf-lab#78):
    • ggregate_runs keeps .min() for both world_frames and warmup_frames, and valuate_all_gates Gate 5 now enforces warmup_frames >= scene.warmup, world_frames >= scene.frames.max(1), finite rame_ms.median > 0 (aggregate and per-repeat), and input_script_sha256 repeat parity on both baseline and candidate runs.
    • Added unit test
      eject_when_a_repeat_ends_before_requested_frame_count proving [120, 1, 120] measured world_frames (as well as short warmup, non-positive median frame time, and the rames.max(1) floor) on either baseline or candidate is rejected by Gate 5.
  • Quick-start docs: added a copy-paste "Quick start: record one route and replay it twice" block near the top of docs/auto-bench.md.

Verified with cargo run --locked -p xtask -- policy (224 files ok), cargo test --locked -p xtask (18/18), and cargo clippy --workspace --all-targets --locked -- -D warnings -A deprecated (

**@⁠Vladimir-Human** on GitHub · 2026-11-26 13:49 UTC · [original](https://github.com/fxceless/victory-fork/pull/1302#issuecomment-7193893669) Updated in `a451e37`: - **Gate 5 symmetric short-repeat hardening** (mirroring @⁠HandshakeHackin's catch on PastiiJay/klbf-lab#78): - ggregate_runs keeps .min() for both world_frames and warmup_frames, and valuate_all_gates Gate 5 now enforces warmup_frames >= scene.warmup, world_frames >= scene.frames.max(1), finite rame_ms.median > 0 (aggregate and per-repeat), and input_script_sha256 repeat parity on **both** baseline and candidate runs. - Added unit test eject_when_a_repeat_ends_before_requested_frame_count proving [120, 1, 120] measured world_frames (as well as short warmup, non-positive median frame time, and the rames.max(1) floor) on either baseline or candidate is rejected by Gate 5. - **Quick-start docs**: added a copy-paste **"Quick start: record one route and replay it twice"** block near the top of docs/auto-bench.md. Verified with cargo run --locked -p xtask -- policy (224 files ok), cargo test --locked -p xtask (18/18), and cargo clippy --workspace --all-targets --locked -- -D warnings -A deprecated (
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1302/head:github-bot/gh-1302'
git switch 'github-bot/gh-1302'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1302'
git switch 'github-bot/gh-1302'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1302'
git switch 'github-bot/gh-1302'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1302'
git switch 'main'
git merge --squash 'github-bot/gh-1302'
git switch 'main'
git merge --ff-only 'github-bot/gh-1302'
git switch 'main'
git merge 'github-bot/gh-1302'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.